@joebigelow / wix / commits / 7b37f412

Add test for basic functionality.

Force test project to be x64. Fix intermediate path to include the test group name.

Sean Hall committed Dec 31, 2020 at 18:32 UTC 7b37f41230ca1e5e4a81b834d320831de93616a9
9 files changed +160 -7
nuget.config
+1
@@ -4,6 +4,7 @@
4 <clear />
5 <add key="wixtoolset-balutil" value="https://ci.appveyor.com/nuget/wixtoolset-balutil" />
6 <add key="wixtoolset-bal-wixext" value="https://ci.appveyor.com/nuget/wixtoolset-bal-wixext" />
7 + <add key="wixtoolset-data" value="https://ci.appveyor.com/nuget/wixtoolset-data" />
8 <add key="wixtoolset-dtf" value="https://ci.appveyor.com/nuget/wixtoolset-dtf" />
9 <add key="wixtoolset-netfx-wixext" value="https://ci.appveyor.com/nuget/wixtoolset-netfx-wixext" />
10 <add key="wixtoolset-tools" value="https://ci.appveyor.com/nuget/wixtoolset-tools" />
src/TestData/BasicFunctionality/BundleA/BundleA.wixproj new
+12
@@ -0,0 +1,12 @@
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 +<Project Sdk="WixToolset.Sdk">
3 + <PropertyGroup>
4 + <OutputType>Bundle</OutputType>
5 + </PropertyGroup>
6 + <ItemGroup>
7 + <ProjectReference Include="..\PackageA\PackageA.wixproj" />
8 + </ItemGroup>
9 + <ItemGroup>
10 + <PackageReference Include="WixToolset.Bal.wixext" Version="4.0.77" />
11 + </ItemGroup>
12 +</Project>
\ No newline at end of file
src/TestData/BasicFunctionality/BundleA/BundleA.wxi new
+21
@@ -0,0 +1,21 @@
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 +<?ifndef Version?>
4 +<?define Version = 1.0.0.0?>
5 +<?endif?>
6 +
7 +<Include xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
8 + <Bundle Name="~$(var.TestGroupName) - Bundle A" Version="$(var.Version)" UpgradeCode="{8C7E2C47-1EE7-4BBE-99A2-EAB7F3693F48}" Compressed="yes">
9 + <Log Prefix="~$(var.TestGroupName)_BundleA" />
10 +
11 + <Variable Name="TestGroupName" Value="$(var.TestGroupName)" />
12 +
13 + <BootstrapperApplication>
14 + <bal:WixStandardBootstrapperApplication LicenseUrl="" Theme="hyperlinkLicense" />
15 + </BootstrapperApplication>
16 +
17 + <Chain>
18 + <PackageGroupRef Id="BundlePackages" />
19 + </Chain>
20 + </Bundle>
21 +</Include>
src/TestData/BasicFunctionality/BundleA/BundleA.wxs new
+11
@@ -0,0 +1,11 @@
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 +
4 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
5 + <?include BundleA.wxi ?>
6 + <Fragment>
7 + <PackageGroup Id="BundlePackages">
8 + <MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)" />
9 + </PackageGroup>
10 + </Fragment>
11 +</Wix>
src/TestData/BasicFunctionality/PackageA/PackageA.wixproj new
+10
@@ -0,0 +1,10 @@
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 +<Project Sdk="WixToolset.Sdk">
3 + <PropertyGroup>
4 + <CabPrefix>a</CabPrefix>
5 + <UpgradeCode>{7FD50F1B-D134-4365-923C-DFA160F74738}</UpgradeCode>
6 + </PropertyGroup>
7 + <ItemGroup>
8 + <Compile Include="..\..\Templates\Package.wxs" Link="Package.wxs" />
9 + </ItemGroup>
10 +</Project>
\ No newline at end of file
src/Wix.Build.props
+1
@@ -2,6 +2,7 @@
2 <Project>
3 <PropertyGroup>
4 <TestGroupName Condition=" '$(TestGroupName)'=='' ">$([System.IO.Path]::GetFileName($([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))))</TestGroupName>
5 + <BaseIntermediateOutputPath>$(BaseOutputPath)obj\$(TestGroupName)\$(ProjectName)\</BaseIntermediateOutputPath>
6 <OutputPath>$(OutputPath)$(TestGroupName)\</OutputPath>
7 </PropertyGroup>
8 </Project>
src/WixToolsetTest.BurnE2E/BasicFunctionalityTests.cs new
+41
@@ -0,0 +1,41 @@
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 Xunit;
8 + using Xunit.Abstractions;
9 +
10 + public class BasicFunctionalityTests : BurnE2ETests
11 + {
12 + public BasicFunctionalityTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper, "BasicFunctionality") { }
13 +
14 + [Fact]
15 + public void CanInstallAndUninstallSimpleBundle()
16 + {
17 + var packageA = this.CreatePackageInstaller("PackageA");
18 +
19 + var bundleA = this.CreateBundleInstaller("BundleA");
20 +
21 + var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs");
22 +
23 + // Source file should *not* be installed
24 + Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}");
25 +
26 + bundleA.Install();
27 +
28 + var cachedBundlePath = bundleA.VerifyRegisteredAndInPackageCache();
29 +
30 + // Source file should be installed
31 + Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled));
32 +
33 + bundleA.Uninstall(cachedBundlePath);
34 +
35 + // Source file should *not* be installed
36 + Assert.False(File.Exists(packageASourceCodeInstalled), String.Concat("Package A payload should have been removed by uninstall from: ", packageASourceCodeInstalled));
37 +
38 + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(cachedBundlePath);
39 + }
40 + }
41 +}
src/WixToolsetTest.BurnE2E/BundleInstaller.cs
+60 -2
@@ -4,19 +4,30 @@ 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 class BundleInstaller : IDisposable
15 {
16 + public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
17 + public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath";
18 +
19 public BundleInstaller(WixTestContext testContext, string name)
20 {
21 this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe");
22 + this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb");
23 this.TestGroupName = testContext.TestGroupName;
24 this.TestName = testContext.TestName;
25 }
26
27 public string Bundle { get; }
28
29 + public string BundlePdb { get; }
30 +
31 public string TestGroupName { get; }
32
33 public string TestName { get; }
@@ -65,6 +76,18 @@ namespace WixToolsetTest.BurnE2E
76 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments);
77 }
78
79 + /// <summary>
80 + /// Uninstalls the bundle at the given path with optional arguments.
81 + /// </summary>
82 + /// <param name="bundlePath">This should be the bundle in the package cache.</param>
83 + /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
84 + /// <param name="arguments">Optional arguments to pass to the tool.</param>
85 + /// <returns>Path to the generated log file.</returns>
86 + public string Uninstall(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
87 + {
88 + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments, bundlePath: bundlePath);
89 + }
90 +
91 /// <summary>
92 /// Executes the bundle with optional arguments.
93 /// </summary>
@@ -72,9 +95,9 @@ namespace WixToolsetTest.BurnE2E
95 /// <param name="mode">Install mode.</param>
96 /// <param name="arguments">Optional arguments to pass to the tool.</param>
97 /// <returns>Path to the generated log file.</returns>
75 - private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true)
98 + private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null)
99 {
77 - TestTool bundle = new TestTool(this.Bundle);
100 + TestTool bundle = new TestTool(bundlePath ?? this.Bundle);
101 var sb = new StringBuilder();
102
103 // Be sure to run silent.
@@ -119,6 +142,41 @@ namespace WixToolsetTest.BurnE2E
142 return logFile;
143 }
144
145 + public string VerifyRegisteredAndInPackageCache()
146 + {
147 + using var wixOutput = WixOutput.Read(this.BundlePdb);
148 + var intermediate = Intermediate.Load(wixOutput);
149 + var section = intermediate.Sections.Single();
150 + var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
151 + var bundleId = bundleSymbol.BundleId;
152 + var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}";
153 +
154 + using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath);
155 + Assert.NotNull(testKey);
156 +
157 + var cachePathValue = testKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH);
158 + Assert.NotNull(cachePathValue);
159 + var cachePath = Assert.IsType<string>(cachePathValue);
160 + Assert.True(File.Exists(cachePath));
161 +
162 + return cachePath;
163 + }
164 +
165 + public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath)
166 + {
167 + using var wixOutput = WixOutput.Read(this.BundlePdb);
168 + var intermediate = Intermediate.Load(wixOutput);
169 + var section = intermediate.Sections.Single();
170 + var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
171 + var bundleId = bundleSymbol.BundleId;
172 + var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}";
173 +
174 + using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath);
175 + Assert.Null(testKey);
176 +
177 + Assert.False(File.Exists(cachedBundlePath));
178 + }
179 +
180 public void Dispose()
181 {
182 string[] args = { "-burn.ignoredependencies=ALL" };
src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj
+3 -5
@@ -4,16 +4,14 @@
4 <Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netcoreapp3.1</TargetFramework>
7 - </PropertyGroup>
8 -
9 - <PropertyGroup>
10 - <NoWarn>NU1701</NoWarn>
7 + <PlatformTarget>x64</PlatformTarget>
8 </PropertyGroup>
9
10 <ItemGroup>
11 <PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
12 <PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
16 - <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.*" />
13 + <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.48" />
14 + <PackageReference Include="WixToolset.Data" Version="4.0.177" />
15 </ItemGroup>
16
17 <ItemGroup>