main
cs 263 lines 16.3 KB
Raw
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 WixTestTools;
8 using WixToolset.BootstrapperApplicationApi;
9 using Xunit;
10 using Xunit.Abstractions;
11
12 public class BundlePackageTests : BurnE2ETests
13 {
14 public BundlePackageTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
15
16 [RuntimeFact]
17 public void CanBuildBundlePackagesWithRemoteBundles()
18 {
19 var multipleBundlePackagesWithRemoteBundle = this.CreateBundleInstaller("MultipleBundlePackagesWithRemoteBundle");
20
21 multipleBundlePackagesWithRemoteBundle.Install();
22 // Bundle only contains permanent packages, so it isn't registered
23 multipleBundlePackagesWithRemoteBundle.VerifyUnregisteredAndRemovedFromPackageCache();
24 }
25
26 [RuntimeFact]
27 public void CanInstallAndUninstallBundlePackages()
28 {
29 var packageA = this.CreatePackageInstaller(@"..\BasicFunctionalityTests\PackageA");
30 var packageA_x64 = this.CreatePackageInstaller(@"..\BasicFunctionalityTests\PackageA_x64");
31 var bundleA = this.CreateBundleInstaller(@"..\BasicFunctionalityTests\BundleA");
32 var bundleB_x64 = this.CreateBundleInstaller(@"..\BasicFunctionalityTests\BundleB_x64");
33 var multipleBundlePackagesBundle = this.CreateBundleInstaller(@"MultipleBundlePackagesBundle");
34
35 var packageA32SourceCodeFilePath = packageA.GetInstalledFilePath("Package.wxs");
36 var packageA64SourceCodeFilePath = packageA_x64.GetInstalledFilePath("Package.wxs");
37
38 // Source file should *not* be installed
39 Assert.False(File.Exists(packageA32SourceCodeFilePath), $"PackageA payload should not be there on test start: {packageA32SourceCodeFilePath}");
40 Assert.False(File.Exists(packageA64SourceCodeFilePath), $"PackageA_x64 payload should not be there on test start: {packageA64SourceCodeFilePath}");
41
42 multipleBundlePackagesBundle.Install();
43 multipleBundlePackagesBundle.VerifyRegisteredAndInPackageCache();
44
45 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
46 bundleB_x64.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
47
48 // Source file should be installed
49 Assert.True(File.Exists(packageA32SourceCodeFilePath), $"Should have found PackageA payload installed at: {packageA32SourceCodeFilePath}");
50 Assert.True(File.Exists(packageA64SourceCodeFilePath), $"Should have found PackageA_x64 payload installed at: {packageA64SourceCodeFilePath}");
51
52 multipleBundlePackagesBundle.Uninstall();
53 multipleBundlePackagesBundle.VerifyUnregisteredAndRemovedFromPackageCache();
54
55 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
56 bundleB_x64.VerifyUnregisteredAndRemovedFromPackageCache();
57
58 // Source file should *not* be installed
59 Assert.False(File.Exists(packageA32SourceCodeFilePath), $"PackageA payload should have been removed by uninstall from: {packageA32SourceCodeFilePath}");
60 Assert.False(File.Exists(packageA64SourceCodeFilePath), $"PackageA_x64 payload should have been removed by uninstall from: {packageA64SourceCodeFilePath}");
61 }
62
63 [RuntimeFact]
64 public void CanInstallUpgradeBundlePackage()
65 {
66 var bundleAv1 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv1");
67 var bundleAv2 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv2");
68 var upgradeBundlePackageBundlev2 = this.CreateBundleInstaller("UpgradeBundlePackageBundlev2");
69
70 bundleAv1.Install();
71 bundleAv1.VerifyRegisteredAndInPackageCache();
72
73 upgradeBundlePackageBundlev2.Install();
74 upgradeBundlePackageBundlev2.VerifyRegisteredAndInPackageCache();
75 bundleAv2.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
76 bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache();
77 }
78
79 [RuntimeFact]
80 public void CanInstallV3BundlePackage()
81 {
82 var v3BundleId = "{215a70db-ab35-48c7-be51-d66eaac87177}";
83 var v3BundleName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Package Cache", v3BundleId, "CustomV3Theme");
84 var v3Bundle = new BundleInstaller(this.TestContext, v3BundleName);
85 this.AddBundleInstaller(v3Bundle);
86 var v3BundlePackageBundle = this.CreateBundleInstaller("V3BundlePackageBundle");
87
88 Assert.False(File.Exists(v3Bundle.Bundle), "v3bundle.exe was already installed");
89
90 var logPath = v3BundlePackageBundle.Install();
91 v3BundlePackageBundle.VerifyRegisteredAndInPackageCache();
92
93 Assert.True(LogVerifier.MessageInLogFile(logPath, "Applied execute package: v3bundle.exe, result: 0x0, restart: None"));
94
95 Assert.True(BundleRegistration.TryGetPerMachineBundleRegistrationById(v3BundleId, false, out var v3Registration));
96 Assert.Null(v3Registration.SystemComponent);
97 }
98
99 [RuntimeFact]
100 public void CanLeaveBundlePackageVisible()
101 {
102 var bundleAv1 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv1");
103 var upgradeBundlePackageBundlev1 = this.CreateBundleInstaller("UpgradeBundlePackageBundlev1");
104
105 bundleAv1.Install();
106 bundleAv1.VerifyRegisteredAndInPackageCache();
107
108 upgradeBundlePackageBundlev1.Install();
109 upgradeBundlePackageBundlev1.VerifyRegisteredAndInPackageCache();
110 bundleAv1.VerifyRegisteredAndInPackageCache();
111
112 upgradeBundlePackageBundlev1.Uninstall();
113 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache();
114 bundleAv1.VerifyRegisteredAndInPackageCache();
115 }
116
117 [RuntimeFact]
118 public void CanReferenceCountBundlePackage()
119 {
120 var bundleAv1 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv1");
121 var upgradeBundlePackageBundlev1 = this.CreateBundleInstaller("UpgradeBundlePackageBundlev1");
122
123 upgradeBundlePackageBundlev1.Install();
124 upgradeBundlePackageBundlev1.VerifyRegisteredAndInPackageCache();
125 bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
126
127 // Repair bundle so it adds itself as a reference to itself.
128 bundleAv1.Repair();
129 bundleAv1.VerifyRegisteredAndInPackageCache();
130
131 upgradeBundlePackageBundlev1.Uninstall();
132 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache();
133
134 bundleAv1.VerifyRegisteredAndInPackageCache();
135 }
136
137 [RuntimeFact]
138 public void CanSkipObsoleteBundlePackage()
139 {
140 var bundleAv1 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv1");
141 var bundleAv2 = this.CreateBundleInstaller(@"..\UpgradeRelatedBundleTests\BundleAv2");
142 var upgradeBundlePackageBundlev1 = this.CreateBundleInstaller("UpgradeBundlePackageBundlev1");
143
144 bundleAv2.Install();
145 bundleAv2.VerifyRegisteredAndInPackageCache();
146
147 upgradeBundlePackageBundlev1.Install();
148 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache();
149 bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache();
150 }
151
152 [RuntimeFact]
153 public void CanRecacheAndReinstallBundlePackageOnUninstallRollback()
154 {
155 var packageFail = this.CreatePackageInstaller("PackageFail");
156 var packageA = this.CreatePackageInstaller(@"..\BasicFunctionalityTests\PackageA");
157 var bundleA = this.CreateBundleInstaller(@"..\BasicFunctionalityTests\BundleA");
158 var bundlePackageUninstallFailureBundle = this.CreateBundleInstaller("BundlePackageUninstallFailureBundle");
159 var testBAController = this.CreateTestBAController();
160 var bundleASelfCachedPath = bundleA.GetExpectedCachedBundlePath();
161 var bundleAEmbeddedCachedPath = bundlePackageUninstallFailureBundle.GetPackageEntryPointCachePath("PackageA");
162
163 packageA.VerifyInstalled(false);
164 packageFail.VerifyInstalled(false);
165 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
166
167 testBAController.SetPackageRequestedCacheType("PackageA", BOOTSTRAPPER_CACHE_TYPE.Remove);
168
169 var installLogPath = bundlePackageUninstallFailureBundle.Install();
170 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
171 packageFail.VerifyInstalled(true);
172 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
173
174 Assert.False(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
175 Assert.True(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
176
177 testBAController.ResetPackageStates("PackageA");
178 testBAController.SetAllowAcquireAfterValidationFailure();
179
180 var uninstallLogPath = bundlePackageUninstallFailureBundle.Uninstall((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "FAILWHENDEFERRED=1");
181 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
182 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
183 packageFail.VerifyInstalled(true);
184
185 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, "TESTBA: OnCachePackageNonVitalValidationFailure() - id: PackageA, default: None, requested: Acquire"));
186 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
187 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
188 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
189 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
190 }
191
192 [RuntimeFact]
193 public void CanReinstallBundlePackageOnUninstallRollback()
194 {
195 var packageFail = this.CreatePackageInstaller("PackageFail");
196 var packageA = this.CreatePackageInstaller(@"..\BasicFunctionalityTests\PackageA");
197 var bundleA = this.CreateBundleInstaller(@"..\BasicFunctionalityTests\BundleA");
198 var bundlePackageUninstallFailureBundle = this.CreateBundleInstaller("BundlePackageUninstallFailureBundle");
199 var bundleASelfCachedPath = bundleA.GetExpectedCachedBundlePath();
200 var bundleAEmbeddedCachedPath = bundlePackageUninstallFailureBundle.GetPackageEntryPointCachePath("PackageA");
201
202 packageA.VerifyInstalled(false);
203 packageFail.VerifyInstalled(false);
204 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
205
206 var installLogPath = bundlePackageUninstallFailureBundle.Install();
207 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
208 packageFail.VerifyInstalled(true);
209 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
210
211 Assert.False(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
212 Assert.True(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
213
214 var uninstallLogPath = bundlePackageUninstallFailureBundle.Uninstall((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "FAILWHENDEFERRED=1");
215 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
216 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
217 packageFail.VerifyInstalled(true);
218
219 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, "TESTBA: OnCachePackageNonVitalValidationFailure() - id: PackageA"));
220 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
221 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
222 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
223 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
224 }
225
226 [RuntimeFact]
227 public void CanSkipReinstallBundlePackageOnUninstallRollback()
228 {
229 var packageFail = this.CreatePackageInstaller("PackageFail");
230 var packageA = this.CreatePackageInstaller(@"..\BasicFunctionalityTests\PackageA");
231 var bundleA = this.CreateBundleInstaller(@"..\BasicFunctionalityTests\BundleA");
232 var bundlePackageUninstallFailureBundle = this.CreateBundleInstaller("BundlePackageUninstallFailureBundle");
233 var testBAController = this.CreateTestBAController();
234 var bundleASelfCachedPath = bundleA.GetExpectedCachedBundlePath();
235 var bundleAEmbeddedCachedPath = bundlePackageUninstallFailureBundle.GetPackageEntryPointCachePath("PackageA");
236
237 packageA.VerifyInstalled(false);
238 packageFail.VerifyInstalled(false);
239 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
240
241 testBAController.SetPackageRequestedCacheType("PackageA", BOOTSTRAPPER_CACHE_TYPE.Remove);
242
243 var installLogPath = bundlePackageUninstallFailureBundle.Install();
244 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
245 packageFail.VerifyInstalled(true);
246 bundleA.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
247
248 Assert.False(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
249 Assert.True(LogVerifier.MessageInLogFile(installLogPath, $"Applying execute package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
250
251 var uninstallLogPath = bundlePackageUninstallFailureBundle.Uninstall((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "FAILWHENDEFERRED=1");
252 bundlePackageUninstallFailureBundle.VerifyRegisteredAndInPackageCache();
253 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
254 packageFail.VerifyInstalled(true);
255
256 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, "TESTBA: OnCachePackageNonVitalValidationFailure() - id: PackageA, default: None, requested: None"));
257 Assert.True(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
258 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying execute package: PackageA, action: Uninstall, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
259 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleASelfCachedPath}"), bundleASelfCachedPath);
260 Assert.False(LogVerifier.MessageInLogFile(uninstallLogPath, $"Applying rollback package: PackageA, action: Install, path: {bundleAEmbeddedCachedPath}"), bundleAEmbeddedCachedPath);
261 }
262 }
263 }