aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolsetTest.BurnE2E/BundleInstaller.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolsetTest.BurnE2E/BundleInstaller.cs128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/WixToolsetTest.BurnE2E/BundleInstaller.cs b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs
new file mode 100644
index 00000000..b708db40
--- /dev/null
+++ b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs
@@ -0,0 +1,128 @@
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.BurnE2E
4{
5 using System;
6 using System.IO;
7 using System.Text;
8
9 public class BundleInstaller : IDisposable
10 {
11 public BundleInstaller(WixTestContext testContext, string name)
12 {
13 this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe");
14 this.TestGroupName = testContext.TestGroupName;
15 this.TestName = testContext.TestName;
16 }
17
18 public string Bundle { get; }
19
20 public string TestGroupName { get; }
21
22 public string TestName { get; }
23
24 /// <summary>
25 /// Installs the bundle with optional arguments.
26 /// </summary>
27 /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
28 /// <param name="arguments">Optional arguments to pass to the tool.</param>
29 /// <returns>Path to the generated log file.</returns>
30 public string Install(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
31 {
32 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Install, arguments);
33 }
34
35 /// <summary>
36 /// Modify the bundle with optional arguments.
37 /// </summary>
38 /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
39 /// <param name="arguments">Optional arguments to pass to the tool.</param>
40 /// <returns>Path to the generated log file.</returns>
41 public string Modify(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
42 {
43 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Modify, arguments);
44 }
45
46 /// <summary>
47 /// Repairs the bundle with optional arguments.
48 /// </summary>
49 /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
50 /// <param name="arguments">Optional arguments to pass to the tool.</param>
51 /// <returns>Path to the generated log file.</returns>
52 public string Repair(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
53 {
54 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Repair, arguments);
55 }
56
57 /// <summary>
58 /// Uninstalls the bundle with optional arguments.
59 /// </summary>
60 /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
61 /// <param name="arguments">Optional arguments to pass to the tool.</param>
62 /// <returns>Path to the generated log file.</returns>
63 public string Uninstall(int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
64 {
65 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments);
66 }
67
68 /// <summary>
69 /// Executes the bundle with optional arguments.
70 /// </summary>
71 /// <param name="expectedExitCode">Expected exit code.</param>
72 /// <param name="mode">Install mode.</param>
73 /// <param name="arguments">Optional arguments to pass to the tool.</param>
74 /// <returns>Path to the generated log file.</returns>
75 private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true)
76 {
77 TestTool bundle = new TestTool(this.Bundle);
78 var sb = new StringBuilder();
79
80 // Be sure to run silent.
81 sb.Append(" -quiet");
82
83 // Generate the log file name.
84 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));
85 sb.AppendFormat(" -log \"{0}\"", logFile);
86
87 // Set operation.
88 switch (mode)
89 {
90 case MSIExec.MSIExecMode.Modify:
91 sb.Append(" -modify");
92 break;
93
94 case MSIExec.MSIExecMode.Repair:
95 sb.Append(" -repair");
96 break;
97
98 case MSIExec.MSIExecMode.Cleanup:
99 case MSIExec.MSIExecMode.Uninstall:
100 sb.Append(" -uninstall");
101 break;
102 }
103
104 // Add additional arguments.
105 if (null != arguments)
106 {
107 sb.Append(" ");
108 sb.Append(String.Join(" ", arguments));
109 }
110
111 // Set the arguments.
112 bundle.Arguments = sb.ToString();
113
114 // Run the tool and assert the expected code.
115 bundle.ExpectedExitCode = expectedExitCode;
116 bundle.Run(assertOnError);
117
118 // Return the log file name.
119 return logFile;
120 }
121
122 public void Dispose()
123 {
124 string[] args = { "-burn.ignoredependencies=ALL" };
125 this.RunBundleWithArguments((int)MSIExec.MSIExecReturnCode.SUCCESS, MSIExec.MSIExecMode.Cleanup, args, assertOnError: false);
126 }
127 }
128}