From 72d694ee9cb6954953e55bf05b09c93ddebdc9d3 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 30 Mar 2021 15:50:32 -0500 Subject: Add layout tests. --- src/TestData/LayoutTests/BundleA/Bundle.wxs | 42 +++++++++++++ src/TestData/LayoutTests/BundleA/BundleA.wixproj | 23 ++++++++ src/TestData/LayoutTests/BundleA/BundleA.wxs | 26 +++++++++ src/TestData/LayoutTests/PackageA/PackageA.wixproj | 9 +++ src/WixTestTools/BundleInstaller.cs | 31 +++++++++- src/WixToolsetTest.BurnE2E/LayoutTests.cs | 68 ++++++++++++++++++++++ .../WebServer/CoreOwinWebServer.cs | 3 +- 7 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 src/TestData/LayoutTests/BundleA/Bundle.wxs create mode 100644 src/TestData/LayoutTests/BundleA/BundleA.wixproj create mode 100644 src/TestData/LayoutTests/BundleA/BundleA.wxs create mode 100644 src/TestData/LayoutTests/PackageA/PackageA.wixproj create mode 100644 src/WixToolsetTest.BurnE2E/LayoutTests.cs diff --git a/src/TestData/LayoutTests/BundleA/Bundle.wxs b/src/TestData/LayoutTests/BundleA/Bundle.wxs new file mode 100644 index 00000000..e74b8394 --- /dev/null +++ b/src/TestData/LayoutTests/BundleA/Bundle.wxs @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/TestData/LayoutTests/BundleA/BundleA.wixproj b/src/TestData/LayoutTests/BundleA/BundleA.wixproj new file mode 100644 index 00000000..fa7f227c --- /dev/null +++ b/src/TestData/LayoutTests/BundleA/BundleA.wixproj @@ -0,0 +1,23 @@ + + + + Bundle + {D255FA2D-2B4A-4D78-AE90-C09FECD8491E} + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/LayoutTests/BundleA/BundleA.wxs b/src/TestData/LayoutTests/BundleA/BundleA.wxs new file mode 100644 index 00000000..ea46c5b2 --- /dev/null +++ b/src/TestData/LayoutTests/BundleA/BundleA.wxs @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/TestData/LayoutTests/PackageA/PackageA.wixproj b/src/TestData/LayoutTests/PackageA/PackageA.wixproj new file mode 100644 index 00000000..be425985 --- /dev/null +++ b/src/TestData/LayoutTests/PackageA/PackageA.wixproj @@ -0,0 +1,9 @@ + + + + {CA12F025-6F6F-4E3C-A1D7-FE8CD45A77F5} + + + + + \ No newline at end of file diff --git a/src/WixTestTools/BundleInstaller.cs b/src/WixTestTools/BundleInstaller.cs index 859656ad..34661651 100644 --- a/src/WixTestTools/BundleInstaller.cs +++ b/src/WixTestTools/BundleInstaller.cs @@ -48,6 +48,31 @@ namespace WixTestTools return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Install, arguments, bundlePath: bundlePath); } + /// + /// Calls Layout for the bundle with optional arguments. + /// + /// The destination directory. + /// Expected exit code, defaults to success. + /// Optional arguments to pass to the tool. + /// Path to the generated log file. + public string Layout(string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) + { + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, layoutDirectory: layoutDirectory); + } + + /// + /// Calls Layout for the bundle with optional arguments. + /// + /// Path to the bundle to run. + /// The destination directory. + /// Expected exit code, defaults to success. + /// Optional arguments to pass to the tool. + /// Path to the generated log file. + public string Layout(string bundlePath, string layoutDirectory, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) + { + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.AdministrativeInstall, arguments, bundlePath: bundlePath, layoutDirectory: layoutDirectory); + } + /// /// Modify the bundle with optional arguments. /// @@ -100,7 +125,7 @@ namespace WixTestTools /// Install mode. /// Optional arguments to pass to the tool. /// Path to the generated log file. - private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null) + private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null, string layoutDirectory = null) { TestTool bundle = new TestTool(bundlePath ?? this.Bundle); var sb = new StringBuilder(); @@ -115,6 +140,10 @@ namespace WixTestTools // Set operation. switch (mode) { + case MSIExec.MSIExecMode.AdministrativeInstall: + sb.Append($" -layout \"{layoutDirectory}\""); + break; + case MSIExec.MSIExecMode.Modify: sb.Append(" -modify"); break; diff --git a/src/WixToolsetTest.BurnE2E/LayoutTests.cs b/src/WixToolsetTest.BurnE2E/LayoutTests.cs new file mode 100644 index 00000000..1e36e2a5 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/LayoutTests.cs @@ -0,0 +1,68 @@ +// 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. + +namespace WixToolsetTest.BurnE2E +{ + using System.Collections.Generic; + using System.IO; + using WixBuildTools.TestSupport; + using Xunit; + using Xunit.Abstractions; + + public class LayoutTests : BurnE2ETests + { + public LayoutTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + + [Fact] + public void CanLayoutBundleInPlaceWithMissingPayloads() + { + var bundleA = this.CreateBundleInstaller("BundleA"); + var webServer = this.CreateWebServer(); + + webServer.AddFiles(new Dictionary + { + { "/BundleA/LayoutOnlyPayload", Path.Combine(this.TestContext.TestDataFolder, "BundleA.wxs") }, + { "/BundleA/packages.cab", Path.Combine(this.TestContext.TestDataFolder, "packages.cab") }, + }); + webServer.Start(); + + using var dfs = new DisposableFileSystem(); + var layoutDirectory = dfs.GetFolder(true); + + // Manually copy bundle to layout directory and then run from there so the non-compressed payloads have to be resolved. + var bundleAFileInfo = new FileInfo(bundleA.Bundle); + var bundleACopiedPath = Path.Combine(layoutDirectory, bundleAFileInfo.Name); + bundleAFileInfo.CopyTo(bundleACopiedPath); + + bundleA.Layout(bundleACopiedPath, layoutDirectory); + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); + + Assert.True(File.Exists(bundleACopiedPath)); + Assert.True(File.Exists(Path.Combine(layoutDirectory, "packages.cab"))); + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.wxs"))); + } + + [Fact] + public void CanLayoutBundleToNewDirectory() + { + var bundleA = this.CreateBundleInstaller("BundleA"); + var webServer = this.CreateWebServer(); + + webServer.AddFiles(new Dictionary + { + { "/BundleA/LayoutOnlyPayload", Path.Combine(this.TestContext.TestDataFolder, "BundleA.wxs") }, + { "/BundleA/packages.cab", Path.Combine(this.TestContext.TestDataFolder, "packages.cab") }, + }); + webServer.Start(); + + using var dfs = new DisposableFileSystem(); + var layoutDirectory = dfs.GetFolder(); + + bundleA.Layout(layoutDirectory); + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); + + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.exe"))); + Assert.True(File.Exists(Path.Combine(layoutDirectory, "packages.cab"))); + Assert.True(File.Exists(Path.Combine(layoutDirectory, "BundleA.wxs"))); + } + } +} diff --git a/src/WixToolsetTest.BurnE2E/WebServer/CoreOwinWebServer.cs b/src/WixToolsetTest.BurnE2E/WebServer/CoreOwinWebServer.cs index 66db226c..89825813 100644 --- a/src/WixToolsetTest.BurnE2E/WebServer/CoreOwinWebServer.cs +++ b/src/WixToolsetTest.BurnE2E/WebServer/CoreOwinWebServer.cs @@ -49,7 +49,8 @@ namespace WixToolsetTest.BurnE2E public void Dispose() { - this.WebHost?.StopAsync(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult(); + var waitTime = TimeSpan.FromSeconds(5); + this.WebHost?.StopAsync(waitTime).Wait(waitTime); } public IDirectoryContents GetDirectoryContents(string subpath) => throw new NotImplementedException(); -- cgit v1.2.3-55-g6feb