@joebigelow / wix / commits / 72d694ee

Add layout tests.

Sean Hall committed Mar 30, 2021 at 15:50 UTC 72d694ee9cb6954953e55bf05b09c93ddebdc9d3
7 files changed +200 -2
src/TestData/LayoutTests/BundleA/Bundle.wxs new
+42
@@ -0,0 +1,42 @@
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 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
8 + <Bundle Name="~$(var.TestGroupName) - $(var.BundleName)" Version="$(var.Version)" UpgradeCode="$(var.UpgradeCode)" Compressed="yes">
9 + <!-- PayloadGroupRef should be the only thing different from the template -->
10 + <PayloadGroupRef Id="LayoutOnlyPayloads" />
11 +
12 + <Log Prefix="~$(var.TestGroupName)_$(var.BundleName)" />
13 +
14 + <Variable Name="TestGroupName" Value="$(var.TestGroupName)" />
15 +
16 + <?ifdef SoftwareTag?>
17 + <SoftwareTag Regid="regid.1995-08.com.example" InstallPath="[CommonAppDataFolder]regid.1995-08.com.example" />
18 + <?endif?>
19 +
20 + <?ifndef BA?>
21 + <!-- pulled in through the PackageGroupRef below -->
22 + <?elseif $(var.BA) = "TestBAdnc"?>
23 + <!-- pulled in through the PackageGroupRef below -->
24 + <?elseif $(var.BA) = "hyperlinkLicense"?>
25 + <BootstrapperApplication>
26 + <bal:WixStandardBootstrapperApplication LicenseUrl="" Theme="hyperlinkLicense" />
27 + </BootstrapperApplication>
28 + <?else?>
29 + <BootstrapperApplicationRef Id="$(var.BA)" />
30 + <?endif?>
31 +
32 + <Chain>
33 + <?ifndef BA?>
34 + <PackageGroupRef Id="TestBA" />
35 + <?elseif $(var.BA) = "TestBAdnc"?>
36 + <PackageGroupRef Id="TestBAdnc" />
37 + <?endif?>
38 +
39 + <PackageGroupRef Id="BundlePackages" />
40 + </Chain>
41 + </Bundle>
42 +</Wix>
src/TestData/LayoutTests/BundleA/BundleA.wixproj new
+23
@@ -0,0 +1,23 @@
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 + <UpgradeCode>{D255FA2D-2B4A-4D78-AE90-C09FECD8491E}</UpgradeCode>
6 + </PropertyGroup>
7 + <ItemGroup>
8 + <ProjectReference Include="..\PackageA\PackageA.wixproj" />
9 + <ProjectReference Include="..\..\TestBA\TestBAWixlib\testbawixlib.wixproj" />
10 + </ItemGroup>
11 + <ItemGroup>
12 + <PackageReference Include="WixToolset.Bal.wixext" Version="4.0.90" />
13 + <PackageReference Include="WixToolset.NetFx.wixext" Version="4.0.64" />
14 + </ItemGroup>
15 + <!-- Workaround wix.targets brokenness -->
16 + <Target Name="CopyUncompressedFiles" AfterTargets="AfterBuild">
17 + <ItemGroup>
18 + <UncompressedFiles Include="$(IntermediateOutputPath)\BundleA.wxs" />
19 + <UncompressedFiles Include="$(IntermediateOutputPath)\packages.cab" />
20 + </ItemGroup>
21 + <Copy SourceFiles="@(UncompressedFiles)" DestinationFolder="$(OutputPath)" />
22 + </Target>
23 +</Project>
\ No newline at end of file
src/TestData/LayoutTests/BundleA/BundleA.wxs new
+26
@@ -0,0 +1,26 @@
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 + <Fragment>
6 + <PackageGroup Id="BundlePackages">
7 + <MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)" />
8 + </PackageGroup>
9 +
10 + <!-- Reenable when fixed
11 + <Container Id="PackagesContainer" Name="packages.cab" DownloadUrl="$(var.WebServerBaseUrl)BundleA/{2}">
12 + -->
13 + <Container Id="PackagesContainer" Name="packages.cab" DownloadUrl="$(var.WebServerBaseUrl)BundleA/packages.cab">
14 + <PackageGroupRef Id="BundlePackages" />
15 + </Container>
16 + </Fragment>
17 +
18 + <Fragment>
19 + <PayloadGroup Id="LayoutOnlyPayloads">
20 + <Payload Id="LayoutOnlyPayload" SourceFile="$(sys.SOURCEFILEPATH)" Compressed="no" DownloadUrl="$(var.WebServerBaseUrl)BundleA/LayoutOnlyPayload" />
21 + <!-- Reenable when fixed
22 + <Payload Id="LayoutOnlyPayload" SourceFile="$(sys.SOURCEFILEPATH)" Compressed="no" DownloadUrl="$(var.WebServerBaseUrl)BundleA/{1}" />
23 + -->
24 + </PayloadGroup>
25 + </Fragment>
26 +</Wix>
src/TestData/LayoutTests/PackageA/PackageA.wixproj new
+9
@@ -0,0 +1,9 @@
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 + <UpgradeCode>{CA12F025-6F6F-4E3C-A1D7-FE8CD45A77F5}</UpgradeCode>
5 + </PropertyGroup>
6 + <ItemGroup>
7 + <Compile Include="..\..\Templates\Package.wxs" Link="Package.wxs" />
8 + </ItemGroup>
9 +</Project>
\ No newline at end of file
src/WixTestTools/BundleInstaller.cs
+30 -1
@@ -48,6 +48,31 @@ namespace WixTestTools
48 return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Install, arguments, bundlePath: bundlePath);
49 }
50
51 + /// <summary>
52 + /// Calls Layout for the bundle with optional arguments.
53 + /// </summary>
54 + /// <param name="layoutDirectory">The destination directory.</param>
55 + /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
56 + /// <param name="arguments">Optional arguments to pass to the tool.</param>
57 + /// <returns>Path to the generated log file.</returns>
58 + public string Layout(string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
59 + {
60 + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, layoutDirectory: layoutDirectory);
61 + }
62 +
63 + /// <summary>
64 + /// Calls Layout for the bundle with optional arguments.
65 + /// </summary>
66 + /// <param name="bundlePath">Path to the bundle to run.</param>
67 + /// <param name="layoutDirectory">The destination directory.</param>
68 + /// <param name="expectedExitCode">Expected exit code, defaults to success.</param>
69 + /// <param name="arguments">Optional arguments to pass to the tool.</param>
70 + /// <returns>Path to the generated log file.</returns>
71 + public string Layout(string bundlePath, string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments)
72 + {
73 + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, bundlePath: bundlePath, layoutDirectory: layoutDirectory);
74 + }
75 +
76 /// <summary>
77 /// Modify the bundle with optional arguments.
78 /// </summary>
@@ -100,7 +125,7 @@ namespace WixTestTools
125 /// <param name="mode">Install mode.</param>
126 /// <param name="arguments">Optional arguments to pass to the tool.</param>
127 /// <returns>Path to the generated log file.</returns>
103 - private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null)
128 + private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null, string layoutDirectory = null)
129 {
130 TestTool bundle = new TestTool(bundlePath ?? this.Bundle);
131 var sb = new StringBuilder();
@@ -115,6 +140,10 @@ namespace WixTestTools
140 // Set operation.
141 switch (mode)
142 {
143 + case MSIExec.MSIExecMode.AdministrativeInstall:
144 + sb.Append($" -layout \"{layoutDirectory}\"");
145 + break;
146 +
147 case MSIExec.MSIExecMode.Modify:
148 sb.Append(" -modify");
149 break;
src/WixToolsetTest.BurnE2E/LayoutTests.cs new
+68
@@ -0,0 +1,68 @@
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.Collections.Generic;
6 + using System.IO;
7 + using WixBuildTools.TestSupport;
8 + using Xunit;
9 + using Xunit.Abstractions;
10 +
11 + public class LayoutTests : BurnE2ETests
12 + {
13 + public LayoutTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
14 +
15 + [Fact]
16 + public void CanLayoutBundleInPlaceWithMissingPayloads()
17 + {
18 + var bundleA = this.CreateBundleInstaller("BundleA");
19 + var webServer = this.CreateWebServer();
20 +
21 + webServer.AddFiles(new Dictionary<string, string>
22 + {
23 + { "/BundleA/LayoutOnlyPayload", Path.Combine(this.TestContext.TestDataFolder, "BundleA.wxs") },
24 + { "/BundleA/packages.cab", Path.Combine(this.TestContext.TestDataFolder, "packages.cab") },
25 + });
26 + webServer.Start();
27 +
28 + using var dfs = new DisposableFileSystem();
29 + var layoutDirectory = dfs.GetFolder(true);
30 +
31 + // Manually copy bundle to layout directory and then run from there so the non-compressed payloads have to be resolved.
32 + var bundleAFileInfo = new FileInfo(bundleA.Bundle);
33 + var bundleACopiedPath = Path.Combine(layoutDirectory, bundleAFileInfo.Name);
34 + bundleAFileInfo.CopyTo(bundleACopiedPath);
35 +
36 + bundleA.Layout(bundleACopiedPath, layoutDirectory);
37 + bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
38 +
39 + Assert.True(File.Exists(bundleACopiedPath));
40 + Assert.True(File.Exists(Path.Combine(layoutDirectory, "packages.cab")));
41 + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.wxs")));
42 + }
43 +
44 + [Fact]
45 + public void CanLayoutBundleToNewDirectory()
46 + {
47 + var bundleA = this.CreateBundleInstaller("BundleA");
48 + var webServer = this.CreateWebServer();
49 +
50 + webServer.AddFiles(new Dictionary<string, string>
51 + {
52 + { "/BundleA/LayoutOnlyPayload", Path.Combine(this.TestContext.TestDataFolder, "BundleA.wxs") },
53 + { "/BundleA/packages.cab", Path.Combine(this.TestContext.TestDataFolder, "packages.cab") },
54 + });
55 + webServer.Start();
56 +
57 + using var dfs = new DisposableFileSystem();
58 + var layoutDirectory = dfs.GetFolder();
59 +
60 + bundleA.Layout(layoutDirectory);
61 + bundleA.VerifyUnregisteredAndRemovedFromPackageCache();
62 +
63 + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.exe")));
64 + Assert.True(File.Exists(Path.Combine(layoutDirectory, "packages.cab")));
65 + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.wxs")));
66 + }
67 + }
68 +}
src/WixToolsetTest.BurnE2E/WebServer/CoreOwinWebServer.cs
+2 -1
@@ -49,7 +49,8 @@ namespace WixToolsetTest.BurnE2E
49
50 public void Dispose()
51 {
52 - this.WebHost?.StopAsync(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();
52 + var waitTime = TimeSpan.FromSeconds(5);
53 + this.WebHost?.StopAsync(waitTime).Wait(waitTime);
54 }
55
56 public IDirectoryContents GetDirectoryContents(string subpath) => throw new NotImplementedException();