aboutsummaryrefslogtreecommitdiff
path: root/src/test/WixToolsetTest.WixCop/WixCopRunner.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/WixToolsetTest.WixCop/WixCopRunner.cs')
-rw-r--r--src/test/WixToolsetTest.WixCop/WixCopRunner.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.WixCop/WixCopRunner.cs b/src/test/WixToolsetTest.WixCop/WixCopRunner.cs
new file mode 100644
index 00000000..b831baa7
--- /dev/null
+++ b/src/test/WixToolsetTest.WixCop/WixCopRunner.cs
@@ -0,0 +1,67 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolsetTest.WixCop
4{
5 using System;
6 using System.Collections.Generic;
7 using WixToolset.Core;
8 using WixToolset.Core.TestPackage;
9 using WixToolset.Extensibility;
10 using WixToolset.Tools.WixCop;
11 using WixToolset.Tools.WixCop.CommandLine;
12 using WixToolset.Tools.WixCop.Interfaces;
13
14 public class WixCopRunner
15 {
16 public bool FixErrors { get; set; }
17
18 public List<string> SearchPatterns { get; } = new List<string>();
19
20 public string SettingFile1 { get; set; }
21
22 public WixCopRunnerResult Execute()
23 {
24 var argList = new List<string>();
25
26 if (this.FixErrors)
27 {
28 argList.Add("-f");
29 }
30
31 if (!String.IsNullOrEmpty(this.SettingFile1))
32 {
33 argList.Add($"-set1{this.SettingFile1}");
34 }
35
36 foreach (var searchPattern in this.SearchPatterns)
37 {
38 argList.Add(searchPattern);
39 }
40
41 return WixCopRunner.Execute(argList.ToArray());
42 }
43
44 public static WixCopRunnerResult Execute(string[] args)
45 {
46 var listener = new TestMessageListener();
47
48 var serviceProvider = new WixToolsetServiceProvider();
49 serviceProvider.AddService<IMessageListener>((x, y) => listener);
50 serviceProvider.AddService<IWixCopCommandLineParser>((x, y) => new WixCopCommandLineParser(x));
51
52 var exitCode = Execute(serviceProvider, args);
53
54 return new WixCopRunnerResult
55 {
56 ExitCode = exitCode,
57 Messages = listener.Messages.ToArray()
58 };
59 }
60
61 public static int Execute(IServiceProvider serviceProvider, string[] args)
62 {
63 var wixcop = new Program();
64 return wixcop.Run(serviceProvider, args);
65 }
66 }
67}