diff options
Diffstat (limited to 'src/WixTestTools/BundleVerifier.cs')
-rw-r--r-- | src/WixTestTools/BundleVerifier.cs | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/src/WixTestTools/BundleVerifier.cs b/src/WixTestTools/BundleVerifier.cs index 96c86fdf..433b6a0a 100644 --- a/src/WixTestTools/BundleVerifier.cs +++ b/src/WixTestTools/BundleVerifier.cs | |||
@@ -33,31 +33,46 @@ namespace WixTestTools | |||
33 | return this.BundleSymbol; | 33 | return this.BundleSymbol; |
34 | } | 34 | } |
35 | 35 | ||
36 | public string GetPackageCachePathForCacheId(string cacheId) | 36 | public string GetPackageCachePathForCacheId(string cacheId, bool perMachine) |
37 | { | 37 | { |
38 | using var policyKey = Registry.LocalMachine.OpenSubKey(FULL_BURN_POLICY_REGISTRY_PATH); | 38 | string cachePath; |
39 | var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; | 39 | if (perMachine) |
40 | var cachePath = redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); | 40 | { |
41 | using var policyKey = Registry.LocalMachine.OpenSubKey(FULL_BURN_POLICY_REGISTRY_PATH); | ||
42 | var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; | ||
43 | cachePath = redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | cachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PACKAGE_CACHE_FOLDER_NAME); | ||
48 | } | ||
41 | return Path.Combine(cachePath, cacheId); | 49 | return Path.Combine(cachePath, cacheId); |
42 | } | 50 | } |
43 | 51 | ||
44 | public string GetExpectedCachedBundlePath() | 52 | public string GetExpectedCachedBundlePath() |
45 | { | 53 | { |
46 | var bundleSymbol = this.GetBundleSymbol(); | 54 | var bundleSymbol = this.GetBundleSymbol(); |
47 | var cachePath = this.GetPackageCachePathForCacheId(bundleSymbol.BundleId); | 55 | var cachePath = this.GetPackageCachePathForCacheId(bundleSymbol.BundleId, bundleSymbol.PerMachine); |
48 | return Path.Combine(cachePath, Path.GetFileName(this.Bundle)); | 56 | return Path.Combine(cachePath, Path.GetFileName(this.Bundle)); |
49 | } | 57 | } |
50 | 58 | ||
51 | public bool TryGetPerMachineRegistration(out BundleRegistration registration) | 59 | public bool TryGetRegistration(out BundleRegistration registration) |
52 | { | 60 | { |
53 | var bundleSymbol = this.GetBundleSymbol(); | 61 | var bundleSymbol = this.GetBundleSymbol(); |
54 | var bundleId = bundleSymbol.BundleId; | 62 | var bundleId = bundleSymbol.BundleId; |
55 | return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleId, out registration); | 63 | if (bundleSymbol.PerMachine) |
64 | { | ||
65 | return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleId, out registration); | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | return BundleRegistration.TryGetPerUserBundleRegistrationById(bundleId, out registration); | ||
70 | } | ||
56 | } | 71 | } |
57 | 72 | ||
58 | public string VerifyRegisteredAndInPackageCache() | 73 | public string VerifyRegisteredAndInPackageCache() |
59 | { | 74 | { |
60 | Assert.True(this.TryGetPerMachineRegistration(out var registration)); | 75 | Assert.True(this.TryGetRegistration(out var registration)); |
61 | 76 | ||
62 | Assert.NotNull(registration.CachePath); | 77 | Assert.NotNull(registration.CachePath); |
63 | Assert.True(File.Exists(registration.CachePath)); | 78 | Assert.True(File.Exists(registration.CachePath)); |
@@ -76,7 +91,7 @@ namespace WixTestTools | |||
76 | 91 | ||
77 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) | 92 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) |
78 | { | 93 | { |
79 | Assert.False(this.TryGetPerMachineRegistration(out _)); | 94 | Assert.False(this.TryGetRegistration(out _)); |
80 | Assert.False(File.Exists(cachedBundlePath)); | 95 | Assert.False(File.Exists(cachedBundlePath)); |
81 | } | 96 | } |
82 | 97 | ||
@@ -86,11 +101,41 @@ namespace WixTestTools | |||
86 | var intermediate = Intermediate.Load(wixOutput); | 101 | var intermediate = Intermediate.Load(wixOutput); |
87 | var section = intermediate.Sections.Single(); | 102 | var section = intermediate.Sections.Single(); |
88 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); | 103 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); |
89 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId); | 104 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.PerMachine == YesNoDefaultType.Yes); |
90 | if (Directory.Exists(cachePath)) | 105 | if (Directory.Exists(cachePath)) |
91 | { | 106 | { |
92 | Directory.Delete(cachePath, true); | 107 | Directory.Delete(cachePath, true); |
93 | } | 108 | } |
94 | } | 109 | } |
110 | |||
111 | public void VerifyPackageIsCached(string packageId) | ||
112 | { | ||
113 | using var wixOutput = WixOutput.Read(this.BundlePdb); | ||
114 | var intermediate = Intermediate.Load(wixOutput); | ||
115 | var section = intermediate.Sections.Single(); | ||
116 | var packageSymbol = section.Symbols.OfType<WixBundlePackageSymbol>().Single(p => p.Id.Id == packageId); | ||
117 | var cachePath = this.GetPackageCachePathForCacheId(packageSymbol.CacheId, packageSymbol.PerMachine == YesNoDefaultType.Yes); | ||
118 | Assert.True(Directory.Exists(cachePath)); | ||
119 | } | ||
120 | |||
121 | public void VerifyExeTestRegistryRootDeleted(string name) | ||
122 | { | ||
123 | using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(name); | ||
124 | if (testRegistryRoot != null) | ||
125 | { | ||
126 | var actualValue = testRegistryRoot.GetValue("Version") as string; | ||
127 | Assert.Null(actualValue); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | public void VerifyExeTestRegistryValue(string name, string expectedValue) | ||
132 | { | ||
133 | using (var root = this.TestContext.GetTestRegistryRoot(name)) | ||
134 | { | ||
135 | Assert.NotNull(root); | ||
136 | var actualValue = root.GetValue("Version") as string; | ||
137 | Assert.Equal(expectedValue, actualValue); | ||
138 | } | ||
139 | } | ||
95 | } | 140 | } |
96 | } | 141 | } |