diff options
Diffstat (limited to 'src/WixTestTools/PackageVerifier.cs')
-rw-r--r-- | src/WixTestTools/PackageVerifier.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/WixTestTools/PackageVerifier.cs b/src/WixTestTools/PackageVerifier.cs new file mode 100644 index 00000000..77946c91 --- /dev/null +++ b/src/WixTestTools/PackageVerifier.cs | |||
@@ -0,0 +1,77 @@ | |||
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 WixTestTools | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Linq; | ||
8 | using WixToolset.Data; | ||
9 | using WixToolset.Data.WindowsInstaller; | ||
10 | using WixToolset.Data.WindowsInstaller.Rows; | ||
11 | using Xunit; | ||
12 | |||
13 | public partial class PackageInstaller | ||
14 | { | ||
15 | public string PackagePdb { get; } | ||
16 | |||
17 | private WindowsInstallerData WiData { get; set; } | ||
18 | |||
19 | public string GetInstalledFilePath(string filename) | ||
20 | { | ||
21 | return this.TestContext.GetTestInstallFolder(Path.Combine(this.GetInstallFolderName(), filename)); | ||
22 | } | ||
23 | |||
24 | private WindowsInstallerData GetWindowsInstallerData() | ||
25 | { | ||
26 | if (this.WiData == null) | ||
27 | { | ||
28 | using var wixOutput = WixOutput.Read(this.PackagePdb); | ||
29 | this.WiData = WindowsInstallerData.Load(wixOutput); | ||
30 | } | ||
31 | |||
32 | return this.WiData; | ||
33 | } | ||
34 | |||
35 | public string GetInstallFolderName() | ||
36 | { | ||
37 | var wiData = this.GetWindowsInstallerData(); | ||
38 | var row = wiData.Tables["Directory"].Rows.Single(r => r.FieldAsString(0) == "INSTALLFOLDER"); | ||
39 | var value = row.FieldAsString(2); | ||
40 | var longNameIndex = value.IndexOf('|') + 1; | ||
41 | if (longNameIndex > 0) | ||
42 | { | ||
43 | return value.Substring(longNameIndex); | ||
44 | } | ||
45 | return value; | ||
46 | } | ||
47 | |||
48 | public string GetProperty(string name) | ||
49 | { | ||
50 | var wiData = this.GetWindowsInstallerData(); | ||
51 | var row = wiData.Tables["Property"].Rows.Cast<PropertyRow>().Single(r => r.Property == name); | ||
52 | return row.Value; | ||
53 | } | ||
54 | |||
55 | public void VerifyInstalled(bool installed) | ||
56 | { | ||
57 | var productCode = this.GetProperty("ProductCode"); | ||
58 | Assert.Equal(installed, MsiUtilities.IsProductInstalled(productCode)); | ||
59 | } | ||
60 | |||
61 | public void VerifyTestRegistryRootDeleted() | ||
62 | { | ||
63 | using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(); | ||
64 | Assert.Null(testRegistryRoot); | ||
65 | } | ||
66 | |||
67 | public void VerifyTestRegistryValue(string name, string expectedValue) | ||
68 | { | ||
69 | using (var root = this.TestContext.GetTestRegistryRoot()) | ||
70 | { | ||
71 | Assert.NotNull(root); | ||
72 | var actualValue = root.GetValue(name) as string; | ||
73 | Assert.Equal(expectedValue, actualValue); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | } | ||