diff options
Diffstat (limited to 'src/WixToolsetTest.BurnE2E/BundleInstaller.cs')
-rw-r--r-- | src/WixToolsetTest.BurnE2E/BundleInstaller.cs | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/WixToolsetTest.BurnE2E/BundleInstaller.cs b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs index b708db40..c85646bb 100644 --- a/src/WixToolsetTest.BurnE2E/BundleInstaller.cs +++ b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs | |||
@@ -4,19 +4,30 @@ namespace WixToolsetTest.BurnE2E | |||
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.IO; | 6 | using System.IO; |
7 | using System.Linq; | ||
7 | using System.Text; | 8 | using System.Text; |
9 | using Microsoft.Win32; | ||
10 | using WixToolset.Data; | ||
11 | using WixToolset.Data.Symbols; | ||
12 | using Xunit; | ||
8 | 13 | ||
9 | public class BundleInstaller : IDisposable | 14 | public class BundleInstaller : IDisposable |
10 | { | 15 | { |
16 | public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
17 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; | ||
18 | |||
11 | public BundleInstaller(WixTestContext testContext, string name) | 19 | public BundleInstaller(WixTestContext testContext, string name) |
12 | { | 20 | { |
13 | this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe"); | 21 | this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe"); |
22 | this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb"); | ||
14 | this.TestGroupName = testContext.TestGroupName; | 23 | this.TestGroupName = testContext.TestGroupName; |
15 | this.TestName = testContext.TestName; | 24 | this.TestName = testContext.TestName; |
16 | } | 25 | } |
17 | 26 | ||
18 | public string Bundle { get; } | 27 | public string Bundle { get; } |
19 | 28 | ||
29 | public string BundlePdb { get; } | ||
30 | |||
20 | public string TestGroupName { get; } | 31 | public string TestGroupName { get; } |
21 | 32 | ||
22 | public string TestName { get; } | 33 | public string TestName { get; } |
@@ -66,15 +77,27 @@ namespace WixToolsetTest.BurnE2E | |||
66 | } | 77 | } |
67 | 78 | ||
68 | /// <summary> | 79 | /// <summary> |
80 | /// Uninstalls the bundle at the given path with optional arguments. | ||
81 | /// </summary> | ||
82 | /// <param name="bundlePath">This should be the bundle in the package cache.</param> | ||
83 | /// <param name="expectedExitCode">Expected exit code, defaults to success.</param> | ||
84 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | ||
85 | /// <returns>Path to the generated log file.</returns> | ||
86 | public string Uninstall(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) | ||
87 | { | ||
88 | return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments, bundlePath: bundlePath); | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
69 | /// Executes the bundle with optional arguments. | 92 | /// Executes the bundle with optional arguments. |
70 | /// </summary> | 93 | /// </summary> |
71 | /// <param name="expectedExitCode">Expected exit code.</param> | 94 | /// <param name="expectedExitCode">Expected exit code.</param> |
72 | /// <param name="mode">Install mode.</param> | 95 | /// <param name="mode">Install mode.</param> |
73 | /// <param name="arguments">Optional arguments to pass to the tool.</param> | 96 | /// <param name="arguments">Optional arguments to pass to the tool.</param> |
74 | /// <returns>Path to the generated log file.</returns> | 97 | /// <returns>Path to the generated log file.</returns> |
75 | private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true) | 98 | private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null) |
76 | { | 99 | { |
77 | TestTool bundle = new TestTool(this.Bundle); | 100 | TestTool bundle = new TestTool(bundlePath ?? this.Bundle); |
78 | var sb = new StringBuilder(); | 101 | var sb = new StringBuilder(); |
79 | 102 | ||
80 | // Be sure to run silent. | 103 | // Be sure to run silent. |
@@ -119,6 +142,41 @@ namespace WixToolsetTest.BurnE2E | |||
119 | return logFile; | 142 | return logFile; |
120 | } | 143 | } |
121 | 144 | ||
145 | public string VerifyRegisteredAndInPackageCache() | ||
146 | { | ||
147 | using var wixOutput = WixOutput.Read(this.BundlePdb); | ||
148 | var intermediate = Intermediate.Load(wixOutput); | ||
149 | var section = intermediate.Sections.Single(); | ||
150 | var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single(); | ||
151 | var bundleId = bundleSymbol.BundleId; | ||
152 | var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; | ||
153 | |||
154 | using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); | ||
155 | Assert.NotNull(testKey); | ||
156 | |||
157 | var cachePathValue = testKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH); | ||
158 | Assert.NotNull(cachePathValue); | ||
159 | var cachePath = Assert.IsType<string>(cachePathValue); | ||
160 | Assert.True(File.Exists(cachePath)); | ||
161 | |||
162 | return cachePath; | ||
163 | } | ||
164 | |||
165 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) | ||
166 | { | ||
167 | using var wixOutput = WixOutput.Read(this.BundlePdb); | ||
168 | var intermediate = Intermediate.Load(wixOutput); | ||
169 | var section = intermediate.Sections.Single(); | ||
170 | var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single(); | ||
171 | var bundleId = bundleSymbol.BundleId; | ||
172 | var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; | ||
173 | |||
174 | using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); | ||
175 | Assert.Null(testKey); | ||
176 | |||
177 | Assert.False(File.Exists(cachedBundlePath)); | ||
178 | } | ||
179 | |||
122 | public void Dispose() | 180 | public void Dispose() |
123 | { | 181 | { |
124 | string[] args = { "-burn.ignoredependencies=ALL" }; | 182 | string[] args = { "-burn.ignoredependencies=ALL" }; |