main
cs 122 lines 4.76 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 WixTestTools;
7 using WixToolset.BootstrapperApplicationApi;
8 using Xunit;
9 using Xunit.Abstractions;
10
11 public class RegistrationTests : BurnE2ETests
12 {
13 public RegistrationTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
14
15 [RuntimeFact]
16 public void AllowsBAToKeepRegistration()
17 {
18 const string fakeInstallDay = "20230101";
19 this.CreatePackageInstaller("PackageA");
20 var bundleA = this.CreateBundleInstaller("BundleA");
21 var testBAController = this.CreateTestBAController();
22
23 testBAController.SetPackageRequestedState("PackageA", RequestState.Absent);
24 testBAController.SetForceKeepRegistration();
25
26 bundleA.Install();
27 var initialRegistration = bundleA.VerifyRegisteredAndInPackageCache();
28
29 var now = DateTime.Now;
30 var today = now.ToString("yyyyMMdd");
31 var yesterday = now.AddDays(-1).ToString("yyyyMMdd"); // check yesterday in case the bundle install crossed the midnight hour.
32
33 Assert.NotNull(initialRegistration.EstimatedSize);
34 Assert.True(initialRegistration.InstallDate == today || initialRegistration.InstallDate == yesterday, $"Installed date should have been {today} or {yesterday}");
35
36 testBAController.SetForceKeepRegistration(null);
37 testBAController.ResetPackageStates("PackageA");
38
39 // Pretend the bundle was installed on this day to be able to verify that it is only written on the initial install.
40 using (var registrationKey = initialRegistration.BaseKey.OpenSubKey(initialRegistration.KeyPath, writable: true))
41 {
42 registrationKey.SetValue(GenericArpRegistration.REGISTRY_ARP_INSTALL_DATE, fakeInstallDay);
43 }
44
45 bundleA.Install();
46 var finalRegistration = bundleA.VerifyRegisteredAndInPackageCache();
47
48 // Verifies https://github.com/wixtoolset/issues/issues/4039
49 Assert.NotNull(finalRegistration.EstimatedSize);
50 Assert.InRange(finalRegistration.EstimatedSize.Value, initialRegistration.EstimatedSize.Value + 1, Int32.MaxValue);
51
52 Assert.Equal(fakeInstallDay, finalRegistration.InstallDate);
53 }
54
55 [RuntimeFact]
56 public void AutomaticallyUncachesBundleWhenNotInstalled()
57 {
58 this.CreatePackageInstaller("PackageA");
59 var bundleA = this.CreateBundleInstaller("BundleA");
60 var testBAController = this.CreateTestBAController();
61
62 var cachedBundlePath = bundleA.ManuallyCache();
63
64 testBAController.SetQuitAfterDetect();
65
66 bundleA.Install(cachedBundlePath);
67
68 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
69 }
70
71 [RuntimeFact]
72 public void AutomaticallyUninstallsBundleWithoutBADoingApply()
73 {
74 this.InstallBundleThenManuallyUninstallPackageAndRemovePackageFromCacheThenRunAndQuitWithoutApply(true);
75 }
76
77 [RuntimeFact]
78 public void AutomaticallyUninstallsBundleWithoutBADoingDetect()
79 {
80 this.InstallBundleThenManuallyUninstallPackageAndRemovePackageFromCacheThenRunAndQuitWithoutApply(false);
81 }
82
83 [RuntimeFact]
84 public void RegistersInARPIfPrecached()
85 {
86 this.CreatePackageInstaller("PackageA");
87 var bundleA = this.CreateBundleInstaller("BundleA");
88
89 bundleA.ManuallyCache();
90
91 // Verifies https://github.com/wixtoolset/issues/issues/5702
92 bundleA.Install();
93 bundleA.VerifyRegisteredAndInPackageCache();
94 }
95
96 private void InstallBundleThenManuallyUninstallPackageAndRemovePackageFromCacheThenRunAndQuitWithoutApply(bool detect)
97 {
98 var packageA = this.CreatePackageInstaller("PackageA");
99 var bundleA = this.CreateBundleInstaller("BundleA");
100 var testBAController = this.CreateTestBAController();
101
102 bundleA.Install();
103 bundleA.VerifyRegisteredAndInPackageCache();
104 packageA.VerifyInstalled(true);
105
106 packageA.UninstallProduct();
107 bundleA.RemovePackageFromCache("PackageA");
108
109 if (detect)
110 {
111 testBAController.SetQuitAfterDetect();
112 }
113 else
114 {
115 testBAController.SetImmediatelyQuit();
116 }
117 bundleA.Install();
118 packageA.VerifyInstalled(false);
119 bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
120 }
121 }
122 }