diff options
Diffstat (limited to '')
-rw-r--r-- | src/WixToolsetTest.BurnE2E/PackageInstaller.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/WixToolsetTest.BurnE2E/PackageInstaller.cs b/src/WixToolsetTest.BurnE2E/PackageInstaller.cs new file mode 100644 index 00000000..e49d010d --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/PackageInstaller.cs | |||
@@ -0,0 +1,97 @@ | |||
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 WixToolsetTest.BurnE2E | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using static WixToolsetTest.BurnE2E.MSIExec; | ||
8 | |||
9 | public class PackageInstaller : IDisposable | ||
10 | { | ||
11 | public PackageInstaller(WixTestContext testContext, string name) | ||
12 | { | ||
13 | this.Package = Path.Combine(testContext.TestDataFolder, $"{name}.msi"); | ||
14 | this.PackageName = name; | ||
15 | this.TestContext = testContext; | ||
16 | } | ||
17 | |||
18 | public string Package { get; } | ||
19 | |||
20 | private string PackageName { get; } | ||
21 | |||
22 | private WixTestContext TestContext { get; } | ||
23 | |||
24 | public string TestGroupName => this.TestContext.TestGroupName; | ||
25 | |||
26 | public string TestName => this.TestContext.TestName; | ||
27 | |||
28 | public string GetInstalledFilePath(string filename) | ||
29 | { | ||
30 | return this.TestContext.GetTestInstallFolder(Path.Combine(this.PackageName, filename)); | ||
31 | } | ||
32 | |||
33 | /// <summary> | ||
34 | /// Installs a .msi file | ||
35 | /// </summary> | ||
36 | /// <param name="expectedExitCode">Expected exit code</param> | ||
37 | /// <param name="otherArguments">Other arguments to pass to MSIExec.</param> | ||
38 | /// <returns>MSIExec log File</returns> | ||
39 | public string InstallProduct(MSIExecReturnCode expectedExitCode = MSIExecReturnCode.SUCCESS, params string[] otherArguments) | ||
40 | { | ||
41 | return this.RunMSIExec(MSIExecMode.Install, otherArguments, expectedExitCode); | ||
42 | } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Uninstalls a .msi file | ||
46 | /// </summary> | ||
47 | /// <param name="expectedExitCode">Expected exit code</param> | ||
48 | /// <param name="otherArguments">Other arguments to pass to MSIExec.</param> | ||
49 | /// <returns>MSIExec log File</returns> | ||
50 | public string UninstallProduct(MSIExecReturnCode expectedExitCode, params string[] otherArguments) | ||
51 | { | ||
52 | return this.RunMSIExec(MSIExecMode.Uninstall, otherArguments, expectedExitCode); | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Repairs a .msi file | ||
57 | /// </summary> | ||
58 | /// <param name="expectedExitCode">Expected exit code</param> | ||
59 | /// <param name="otherArguments">Other arguments to pass to msiexe.exe.</param> | ||
60 | /// <returns>MSIExec log File</returns> | ||
61 | public string RepairProduct(MSIExecReturnCode expectedExitCode, params string[] otherArguments) | ||
62 | { | ||
63 | return this.RunMSIExec(MSIExecMode.Repair, otherArguments, expectedExitCode); | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Executes MSIExec on a .msi file | ||
68 | /// </summary> | ||
69 | /// <param name="mode">Mode of execution for MSIExec</param> | ||
70 | /// <param name="otherArguments">Other arguments to pass to MSIExec.</param> | ||
71 | /// <param name="expectedExitCode">Expected exit code</param> | ||
72 | /// <returns>MSIExec exit code</returns> | ||
73 | private string RunMSIExec(MSIExecMode mode, string[] otherArguments, MSIExecReturnCode expectedExitCode, bool assertOnError = true) | ||
74 | { | ||
75 | // Generate the log file name. | ||
76 | var logFile = Path.Combine(Path.GetTempPath(), String.Format("{0}_{1}_{2:yyyyMMddhhmmss}_{4}_{3}.log", this.TestGroupName, this.TestName, DateTime.UtcNow, Path.GetFileNameWithoutExtension(this.Package), mode)); | ||
77 | |||
78 | var msiexec = new MSIExec | ||
79 | { | ||
80 | Product = this.Package, | ||
81 | ExecutionMode = mode, | ||
82 | OtherArguments = null != otherArguments ? String.Join(" ", otherArguments) : null, | ||
83 | ExpectedExitCode = expectedExitCode, | ||
84 | LogFile = logFile, | ||
85 | }; | ||
86 | |||
87 | msiexec.Run(assertOnError); | ||
88 | return msiexec.LogFile; | ||
89 | } | ||
90 | |||
91 | public void Dispose() | ||
92 | { | ||
93 | string[] args = { "IGNOREDEPENDENCIES=ALL", "WIXFAILWHENDEFERRED=0" }; | ||
94 | this.RunMSIExec(MSIExecMode.Cleanup, args, MSIExecReturnCode.SUCCESS, assertOnError: false); | ||
95 | } | ||
96 | } | ||
97 | } | ||