aboutsummaryrefslogtreecommitdiff
path: root/src/WixTestTools
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-03-08 16:06:01 -0600
committerSean Hall <r.sean.hall@gmail.com>2021-03-08 16:11:57 -0600
commit99d7440134d0f33683d1150a770a2bc594be41de (patch)
tree9a38c1df21c0022516bdfeca0d30f235acd3b46a /src/WixTestTools
parent23e3978430ec3ae4f1ea808af0b590b71b2fec9a (diff)
downloadwix-99d7440134d0f33683d1150a770a2bc594be41de.tar.gz
wix-99d7440134d0f33683d1150a770a2bc594be41de.tar.bz2
wix-99d7440134d0f33683d1150a770a2bc594be41de.zip
Port dependency tests from old repo.
Diffstat (limited to 'src/WixTestTools')
-rw-r--r--src/WixTestTools/BundleInstaller.cs3
-rw-r--r--src/WixTestTools/BundleRegistration.cs14
-rw-r--r--src/WixTestTools/BundleVerifier.cs65
-rw-r--r--src/WixTestTools/MsiUtilities.cs20
-rw-r--r--src/WixTestTools/PackageVerifier.cs7
-rw-r--r--src/WixTestTools/WixTestTools.csproj2
6 files changed, 98 insertions, 13 deletions
diff --git a/src/WixTestTools/BundleInstaller.cs b/src/WixTestTools/BundleInstaller.cs
index 044486fe..854c12f0 100644
--- a/src/WixTestTools/BundleInstaller.cs
+++ b/src/WixTestTools/BundleInstaller.cs
@@ -12,12 +12,15 @@ namespace WixTestTools
12 { 12 {
13 this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe"); 13 this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe");
14 this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb"); 14 this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb");
15 this.TestContext = testContext;
15 this.TestGroupName = testContext.TestGroupName; 16 this.TestGroupName = testContext.TestGroupName;
16 this.TestName = testContext.TestName; 17 this.TestName = testContext.TestName;
17 } 18 }
18 19
19 public string Bundle { get; } 20 public string Bundle { get; }
20 21
22 private WixTestContext TestContext { get; }
23
21 public string TestGroupName { get; } 24 public string TestGroupName { get; }
22 25
23 public string TestName { get; } 26 public string TestName { get; }
diff --git a/src/WixTestTools/BundleRegistration.cs b/src/WixTestTools/BundleRegistration.cs
index d473dcdd..1a066232 100644
--- a/src/WixTestTools/BundleRegistration.cs
+++ b/src/WixTestTools/BundleRegistration.cs
@@ -7,7 +7,8 @@ namespace WixTestTools
7 7
8 public class BundleRegistration 8 public class BundleRegistration
9 { 9 {
10 public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; 10 public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
11 public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
11 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; 12 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath";
12 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode"; 13 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode";
13 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode"; 14 public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode";
@@ -89,13 +90,22 @@ namespace WixTestTools
89 90
90 public static bool TryGetPerMachineBundleRegistrationById(string bundleId, out BundleRegistration registration) 91 public static bool TryGetPerMachineBundleRegistrationById(string bundleId, out BundleRegistration registration)
91 { 92 {
92 var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; 93 var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE}\\{bundleId}";
93 using var registrationKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); 94 using var registrationKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath);
94 var success = registrationKey != null; 95 var success = registrationKey != null;
95 registration = success ? GetBundleRegistration(registrationKey) : null; 96 registration = success ? GetBundleRegistration(registrationKey) : null;
96 return success; 97 return success;
97 } 98 }
98 99
100 public static bool TryGetPerUserBundleRegistrationById(string bundleId, out BundleRegistration registration)
101 {
102 var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}";
103 using var registrationKey = Registry.CurrentUser.OpenSubKey(registrationKeyPath);
104 var success = registrationKey != null;
105 registration = success ? GetBundleRegistration(registrationKey) : null;
106 return success;
107 }
108
99 private static BundleRegistration GetBundleRegistration(RegistryKey idKey) 109 private static BundleRegistration GetBundleRegistration(RegistryKey idKey)
100 { 110 {
101 var registration = new BundleRegistration(); 111 var registration = new BundleRegistration();
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}
diff --git a/src/WixTestTools/MsiUtilities.cs b/src/WixTestTools/MsiUtilities.cs
index 2a848938..4c7d1601 100644
--- a/src/WixTestTools/MsiUtilities.cs
+++ b/src/WixTestTools/MsiUtilities.cs
@@ -2,6 +2,7 @@
2 2
3namespace WixTestTools 3namespace WixTestTools
4{ 4{
5 using System;
5 using WixToolset.Dtf.WindowsInstaller; 6 using WixToolset.Dtf.WindowsInstaller;
6 7
7 public class MsiUtilities 8 public class MsiUtilities
@@ -23,5 +24,24 @@ namespace WixTestTools
23 } 24 }
24 return false; 25 return false;
25 } 26 }
27
28 /// <summary>
29 /// Return true if it finds the given productcode in system with the specified version otherwise it returns false
30 /// </summary>
31 /// <param name="prodCode"></param>
32 /// <param name="prodVersion"></param>
33 /// <returns></returns>
34 public static bool IsProductInstalledWithVersion(string prodCode, Version prodVersion)
35 {
36 //look in all user's products (both per-machine and per-user)
37 foreach (ProductInstallation product in ProductInstallation.GetProducts(null, "s-1-1-0", UserContexts.All))
38 {
39 if (product.ProductCode == prodCode && product.ProductVersion == prodVersion)
40 {
41 return true;
42 }
43 }
44 return false;
45 }
26 } 46 }
27} 47}
diff --git a/src/WixTestTools/PackageVerifier.cs b/src/WixTestTools/PackageVerifier.cs
index b4289032..073e83b0 100644
--- a/src/WixTestTools/PackageVerifier.cs
+++ b/src/WixTestTools/PackageVerifier.cs
@@ -58,6 +58,13 @@ namespace WixTestTools
58 Assert.Equal(installed, MsiUtilities.IsProductInstalled(productCode)); 58 Assert.Equal(installed, MsiUtilities.IsProductInstalled(productCode));
59 } 59 }
60 60
61 public void VerifyInstalledWithVersion(bool installed)
62 {
63 var productCode = this.GetProperty("ProductCode");
64 Version prodVersion = new Version(this.GetProperty("ProductVersion"));
65 Assert.Equal(installed, MsiUtilities.IsProductInstalledWithVersion(productCode, prodVersion));
66 }
67
61 public void DeleteTestRegistryValue(string name) 68 public void DeleteTestRegistryValue(string name)
62 { 69 {
63 using (var root = this.TestContext.GetTestRegistryRoot()) 70 using (var root = this.TestContext.GetTestRegistryRoot())
diff --git a/src/WixTestTools/WixTestTools.csproj b/src/WixTestTools/WixTestTools.csproj
index f81c82d1..0c3c4c76 100644
--- a/src/WixTestTools/WixTestTools.csproj
+++ b/src/WixTestTools/WixTestTools.csproj
@@ -11,7 +11,7 @@
11 <PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" /> 11 <PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
12 <PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" /> 12 <PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
13 <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.48" /> 13 <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.48" />
14 <PackageReference Include="WixToolset.Data" Version="4.0.196" /> 14 <PackageReference Include="WixToolset.Data" Version="4.0.198" />
15 <PackageReference Include="WixToolset.Mba.Core" Version="4.0.51" /> 15 <PackageReference Include="WixToolset.Mba.Core" Version="4.0.51" />
16 </ItemGroup> 16 </ItemGroup>
17 17