diff options
Diffstat (limited to 'src/test/burn/WixTestTools/BundleInstaller.cs')
-rw-r--r-- | src/test/burn/WixTestTools/BundleInstaller.cs | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/src/test/burn/WixTestTools/BundleInstaller.cs b/src/test/burn/WixTestTools/BundleInstaller.cs new file mode 100644 index 00000000..a49c4024 --- /dev/null +++ b/src/test/burn/WixTestTools/BundleInstaller.cs | |||
@@ -0,0 +1,197 @@ | |||
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 | |||
3 | namespace WixTestTools | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Text; | ||
8 | |||
9 | public partial class BundleInstaller : IDisposable | ||
10 | { | ||
11 | public BundleInstaller(WixTestContext testContext, string name) | ||
12 | { | ||
13 | this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe"); | ||
14 | this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb"); | ||
15 | this.TestContext = testContext; | ||
16 | this.TestGroupName = testContext.TestGroupName; | ||
17 | this.TestName = testContext.TestName; | ||
18 | } | ||
19 | |||
20 | public string Bundle { get; } | ||
21 | |||
22 | private WixTestContext TestContext { get; } | ||
23 | |||
24 | public string TestGroupName { get; } | ||
25 | |||
26 | public string TestName { get; } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Installs the bundle with optional arguments. | ||
30 | /// </summary> | ||
31 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
32 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
33 | /// <returns>Path to the generated log file.</returns> | ||
34 | public string Install(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
35 | { | ||
36 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Install, arguments); | ||
37 | } | ||
38 | |||
39 | /// <summary> | ||
40 | /// Installs the bundle with optional arguments. | ||
41 | /// </summary> | ||
42 | /// <param name="bundlePath">This should be the bundle in the package cache.</param> | ||
43 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
44 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
45 | /// <returns>Path to the generated log file.</returns> | ||
46 | public string Install(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
47 | { | ||
48 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Install, arguments, bundlePath: bundlePath); | ||
49 | } | ||
50 | |||
51 | /// <summary> | ||
52 | /// Calls Layout for the bundle with optional arguments. | ||
53 | /// </summary> | ||
54 | /// <param name="layoutDirectory">The destination directory.</param> | ||
55 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
56 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
57 | /// <returns>Path to the generated log file.</returns> | ||
58 | public string Layout(string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
59 | { | ||
60 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, layoutDirectory: layoutDirectory); | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Calls Layout for the bundle with optional arguments. | ||
65 | /// </summary> | ||
66 | /// <param name="bundlePath">Path to the bundle to run.</param> | ||
67 | /// <param name="layoutDirectory">The destination directory.</param> | ||
68 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
69 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
70 | /// <returns>Path to the generated log file.</returns> | ||
71 | public string Layout(string bundlePath, string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
72 | { | ||
73 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, bundlePath: bundlePath, layoutDirectory: layoutDirectory); | ||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// Modify the bundle with optional arguments. | ||
78 | /// </summary> | ||
79 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
80 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
81 | /// <returns>Path to the generated log file.</returns> | ||
82 | public string Modify(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
83 | { | ||
84 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Modify, arguments); | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// Modify the bundle with optional arguments. | ||
89 | /// </summary> | ||
90 | /// <param name="bundlePath">This should be the bundle in the package cache.</param> | ||
91 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
92 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
93 | /// <returns>Path to the generated log file.</returns> | ||
94 | public string Modify(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
95 | { | ||
96 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Modify, arguments, bundlePath: bundlePath); | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Repairs the bundle with optional arguments. | ||
101 | /// </summary> | ||
102 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
103 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
104 | /// <returns>Path to the generated log file.</returns> | ||
105 | public string Repair(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
106 | { | ||
107 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Repair, arguments); | ||
108 | } | ||
109 | |||
110 | /// <summary> | ||
111 | /// Uninstalls the bundle with optional arguments. | ||
112 | /// </summary> | ||
113 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
114 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
115 | /// <returns>Path to the generated log file.</returns> | ||
116 | public string Uninstall(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
117 | { | ||
118 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments); | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// Uninstalls the bundle at the given path with optional arguments. | ||
123 | /// </summary> | ||
124 | /// <param name="bundlePath">This should be the bundle in the package cache.</param> | ||
125 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
126 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
127 | /// <returns>Path to the generated log file.</returns> | ||
128 | public string Uninstall(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
129 | { | ||
130 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments, bundlePath: bundlePath); | ||
131 | } | ||
132 | |||
133 | /// <summary> | ||
134 | /// Executes the bundle with optional arguments. | ||
135 | /// </summary> | ||
136 | /// <param name="expectedExitCode">Expected exit code.</param> | ||
137 | /// <param name="mode">Install mode.</param> | ||
138 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
139 | /// <returns>Path to the generated log file.</returns> | ||
140 | private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null, string layoutDirectory = null) | ||
141 | { | ||
142 | TestTool bundle = new TestTool(bundlePath ?? this.Bundle); | ||
143 | var sb = new StringBuilder(); | ||
144 | |||
145 | // Be sure to run silent. | ||
146 | sb.Append(" -quiet"); | ||
147 | |||
148 | // Generate the log file name. | ||
149 | string logFile = Path.Combine(Path.GetTempPath(), String.Format("{0}_{1}_{2:yyyyMMddhhmmss}_{4}_{3}.log", this.TestGroupName, this.TestName, DateTime.UtcNow, Path.GetFileNameWithoutExtension(this.Bundle), mode)); | ||
150 | sb.AppendFormat(" -log \"{0}\"", logFile); | ||
151 | |||
152 | // Set operation. | ||
153 | switch (mode) | ||
154 | { | ||
155 | case MSIExec.MSIExecMode.AdministrativeInstall: | ||
156 | sb.Append($" -layout \"{layoutDirectory}\""); | ||
157 | break; | ||
158 | |||
159 | case MSIExec.MSIExecMode.Modify: | ||
160 | sb.Append(" -modify"); | ||
161 | break; | ||
162 | |||
163 | case MSIExec.MSIExecMode.Repair: | ||
164 | sb.Append(" -repair"); | ||
165 | break; | ||
166 | |||
167 | case MSIExec.MSIExecMode.Cleanup: | ||
168 | case MSIExec.MSIExecMode.Uninstall: | ||
169 | sb.Append(" -uninstall"); | ||
170 | break; | ||
171 | } | ||
172 | |||
173 | // Add additional arguments. | ||
174 | if (null != arguments) | ||
175 | { | ||
176 | sb.Append(" "); | ||
177 | sb.Append(String.Join(" ", arguments)); | ||
178 | } | ||
179 | |||
180 | // Set the arguments. | ||
181 | bundle.Arguments = sb.ToString(); | ||
182 | |||
183 | // Run the tool and assert the expected code. | ||
184 | bundle.ExpectedExitCode = expectedExitCode; | ||
185 | bundle.Run(assertOnError); | ||
186 | |||
187 | // Return the log file name. | ||
188 | return logFile; | ||
189 | } | ||
190 | |||
191 | public void Dispose() | ||
192 | { | ||
193 | string[] args = { "-burn.ignoredependencies=ALL" }; | ||
194 | this.RunBundleWithArguments((int)MSIExec.MSIExecReturnCode.SUCCESS, MSIExec.MSIExecMode.Cleanup, args, assertOnError: false); | ||
195 | } | ||
196 | } | ||
197 | } | ||