diff options
Diffstat (limited to 'src/WixToolsetTest.BurnE2E/BundleVerifier.cs')
-rw-r--r-- | src/WixToolsetTest.BurnE2E/BundleVerifier.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/WixToolsetTest.BurnE2E/BundleVerifier.cs b/src/WixToolsetTest.BurnE2E/BundleVerifier.cs new file mode 100644 index 00000000..94d51890 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/BundleVerifier.cs | |||
@@ -0,0 +1,78 @@ | |||
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 System.Linq; | ||
8 | using System.Text; | ||
9 | using Microsoft.Win32; | ||
10 | using WixToolset.Data; | ||
11 | using WixToolset.Data.Symbols; | ||
12 | using Xunit; | ||
13 | |||
14 | public partial class BundleInstaller | ||
15 | { | ||
16 | public const string FULL_BURN_POLICY_REGISTRY_PATH = "SOFTWARE\\WOW6432Node\\Policies\\WiX\\Burn"; | ||
17 | public const string PACKAGE_CACHE_FOLDER_NAME = "Package Cache"; | ||
18 | |||
19 | public string BundlePdb { get; } | ||
20 | |||
21 | private WixBundleSymbol BundleSymbol { get; set; } | ||
22 | |||
23 | private WixBundleSymbol GetBundleSymbol() | ||
24 | { | ||
25 | if (this.BundleSymbol == null) | ||
26 | { | ||
27 | using var wixOutput = WixOutput.Read(this.BundlePdb); | ||
28 | var intermediate = Intermediate.Load(wixOutput); | ||
29 | var section = intermediate.Sections.Single(); | ||
30 | this.BundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single(); | ||
31 | } | ||
32 | |||
33 | return this.BundleSymbol; | ||
34 | } | ||
35 | |||
36 | public string GetExpectedCachedBundlePath() | ||
37 | { | ||
38 | var bundleSymbol = this.GetBundleSymbol(); | ||
39 | |||
40 | using var policyKey = Registry.LocalMachine.OpenSubKey(FULL_BURN_POLICY_REGISTRY_PATH); | ||
41 | var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; | ||
42 | var cachePath = redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); | ||
43 | return Path.Combine(cachePath, bundleSymbol.BundleId, Path.GetFileName(this.Bundle)); | ||
44 | } | ||
45 | |||
46 | public bool TryGetPerMachineRegistration(out BundleRegistration registration) | ||
47 | { | ||
48 | var bundleSymbol = this.GetBundleSymbol(); | ||
49 | var bundleId = bundleSymbol.BundleId; | ||
50 | return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleId, out registration); | ||
51 | } | ||
52 | |||
53 | public string VerifyRegisteredAndInPackageCache() | ||
54 | { | ||
55 | Assert.True(this.TryGetPerMachineRegistration(out var registration)); | ||
56 | |||
57 | Assert.NotNull(registration.CachePath); | ||
58 | Assert.True(File.Exists(registration.CachePath)); | ||
59 | |||
60 | var expectedCachePath = this.GetExpectedCachedBundlePath(); | ||
61 | Assert.Equal(expectedCachePath, registration.CachePath, StringComparer.OrdinalIgnoreCase); | ||
62 | |||
63 | return registration.CachePath; | ||
64 | } | ||
65 | |||
66 | public void VerifyUnregisteredAndRemovedFromPackageCache() | ||
67 | { | ||
68 | var cachedBundlePath = this.GetExpectedCachedBundlePath(); | ||
69 | this.VerifyUnregisteredAndRemovedFromPackageCache(cachedBundlePath); | ||
70 | } | ||
71 | |||
72 | public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) | ||
73 | { | ||
74 | Assert.False(this.TryGetPerMachineRegistration(out _)); | ||
75 | Assert.False(File.Exists(cachedBundlePath)); | ||
76 | } | ||
77 | } | ||
78 | } | ||