From 7b37f41230ca1e5e4a81b834d320831de93616a9 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Thu, 31 Dec 2020 18:32:34 -0600 Subject: Add test for basic functionality. Force test project to be x64. Fix intermediate path to include the test group name. --- nuget.config | 1 + .../BasicFunctionality/BundleA/BundleA.wixproj | 12 +++++ .../BasicFunctionality/BundleA/BundleA.wxi | 21 ++++++++ .../BasicFunctionality/BundleA/BundleA.wxs | 11 ++++ .../BasicFunctionality/PackageA/PackageA.wixproj | 10 ++++ src/Wix.Build.props | 1 + .../BasicFunctionalityTests.cs | 41 ++++++++++++++ src/WixToolsetTest.BurnE2E/BundleInstaller.cs | 62 +++++++++++++++++++++- .../WixToolsetTest.BurnE2E.csproj | 8 ++- 9 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 src/TestData/BasicFunctionality/BundleA/BundleA.wixproj create mode 100644 src/TestData/BasicFunctionality/BundleA/BundleA.wxi create mode 100644 src/TestData/BasicFunctionality/BundleA/BundleA.wxs create mode 100644 src/TestData/BasicFunctionality/PackageA/PackageA.wixproj create mode 100644 src/WixToolsetTest.BurnE2E/BasicFunctionalityTests.cs diff --git a/nuget.config b/nuget.config index dd67462a..0d7536b8 100644 --- a/nuget.config +++ b/nuget.config @@ -4,6 +4,7 @@ + diff --git a/src/TestData/BasicFunctionality/BundleA/BundleA.wixproj b/src/TestData/BasicFunctionality/BundleA/BundleA.wixproj new file mode 100644 index 00000000..45127b23 --- /dev/null +++ b/src/TestData/BasicFunctionality/BundleA/BundleA.wixproj @@ -0,0 +1,12 @@ + + + + Bundle + + + + + + + + \ No newline at end of file diff --git a/src/TestData/BasicFunctionality/BundleA/BundleA.wxi b/src/TestData/BasicFunctionality/BundleA/BundleA.wxi new file mode 100644 index 00000000..0bad694e --- /dev/null +++ b/src/TestData/BasicFunctionality/BundleA/BundleA.wxi @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/TestData/BasicFunctionality/BundleA/BundleA.wxs b/src/TestData/BasicFunctionality/BundleA/BundleA.wxs new file mode 100644 index 00000000..0506f05a --- /dev/null +++ b/src/TestData/BasicFunctionality/BundleA/BundleA.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/TestData/BasicFunctionality/PackageA/PackageA.wixproj b/src/TestData/BasicFunctionality/PackageA/PackageA.wixproj new file mode 100644 index 00000000..9943717c --- /dev/null +++ b/src/TestData/BasicFunctionality/PackageA/PackageA.wixproj @@ -0,0 +1,10 @@ + + + + a + {7FD50F1B-D134-4365-923C-DFA160F74738} + + + + + \ No newline at end of file diff --git a/src/Wix.Build.props b/src/Wix.Build.props index 050ec6d5..3f3aaf8f 100644 --- a/src/Wix.Build.props +++ b/src/Wix.Build.props @@ -2,6 +2,7 @@ $([System.IO.Path]::GetFileName($([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory))))) + $(BaseOutputPath)obj\$(TestGroupName)\$(ProjectName)\ $(OutputPath)$(TestGroupName)\ diff --git a/src/WixToolsetTest.BurnE2E/BasicFunctionalityTests.cs b/src/WixToolsetTest.BurnE2E/BasicFunctionalityTests.cs new file mode 100644 index 00000000..4982d733 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/BasicFunctionalityTests.cs @@ -0,0 +1,41 @@ +// 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; + using System.IO; + using Xunit; + using Xunit.Abstractions; + + public class BasicFunctionalityTests : BurnE2ETests + { + public BasicFunctionalityTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper, "BasicFunctionality") { } + + [Fact] + public void CanInstallAndUninstallSimpleBundle() + { + var packageA = this.CreatePackageInstaller("PackageA"); + + var bundleA = this.CreateBundleInstaller("BundleA"); + + var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs"); + + // Source file should *not* be installed + Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}"); + + bundleA.Install(); + + var cachedBundlePath = bundleA.VerifyRegisteredAndInPackageCache(); + + // Source file should be installed + Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled)); + + bundleA.Uninstall(cachedBundlePath); + + // Source file should *not* be installed + Assert.False(File.Exists(packageASourceCodeInstalled), String.Concat("Package A payload should have been removed by uninstall from: ", packageASourceCodeInstalled)); + + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(cachedBundlePath); + } + } +} diff --git a/src/WixToolsetTest.BurnE2E/BundleInstaller.cs b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs index b708db40..c85646bb 100644 --- a/src/WixToolsetTest.BurnE2E/BundleInstaller.cs +++ b/src/WixToolsetTest.BurnE2E/BundleInstaller.cs @@ -4,19 +4,30 @@ namespace WixToolsetTest.BurnE2E { using System; using System.IO; + using System.Linq; using System.Text; + using Microsoft.Win32; + using WixToolset.Data; + using WixToolset.Data.Symbols; + using Xunit; public class BundleInstaller : IDisposable { + public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; + public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; + public BundleInstaller(WixTestContext testContext, string name) { this.Bundle = Path.Combine(testContext.TestDataFolder, $"{name}.exe"); + this.BundlePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb"); this.TestGroupName = testContext.TestGroupName; this.TestName = testContext.TestName; } public string Bundle { get; } + public string BundlePdb { get; } + public string TestGroupName { get; } public string TestName { get; } @@ -65,6 +76,18 @@ namespace WixToolsetTest.BurnE2E return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments); } + /// + /// Uninstalls the bundle at the given path with optional arguments. + /// + /// This should be the bundle in the package cache. + /// Expected exit code, defaults to success. + /// Optional arguments to pass to the tool. + /// Path to the generated log file. + public string Uninstall(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) + { + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Uninstall, arguments, bundlePath: bundlePath); + } + /// /// Executes the bundle with optional arguments. /// @@ -72,9 +95,9 @@ namespace WixToolsetTest.BurnE2E /// 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) + private string RunBundleWithArguments(int expectedExitCode, MSIExec.MSIExecMode mode, string[] arguments, bool assertOnError = true, string bundlePath = null) { - TestTool bundle = new TestTool(this.Bundle); + TestTool bundle = new TestTool(bundlePath ?? this.Bundle); var sb = new StringBuilder(); // Be sure to run silent. @@ -119,6 +142,41 @@ namespace WixToolsetTest.BurnE2E return logFile; } + public string VerifyRegisteredAndInPackageCache() + { + using var wixOutput = WixOutput.Read(this.BundlePdb); + var intermediate = Intermediate.Load(wixOutput); + var section = intermediate.Sections.Single(); + var bundleSymbol = section.Symbols.OfType().Single(); + var bundleId = bundleSymbol.BundleId; + var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; + + using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); + Assert.NotNull(testKey); + + var cachePathValue = testKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH); + Assert.NotNull(cachePathValue); + var cachePath = Assert.IsType(cachePathValue); + Assert.True(File.Exists(cachePath)); + + return cachePath; + } + + public void VerifyUnregisteredAndRemovedFromPackageCache(string cachedBundlePath) + { + using var wixOutput = WixOutput.Read(this.BundlePdb); + var intermediate = Intermediate.Load(wixOutput); + var section = intermediate.Sections.Single(); + var bundleSymbol = section.Symbols.OfType().Single(); + var bundleId = bundleSymbol.BundleId; + var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; + + using var testKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); + Assert.Null(testKey); + + Assert.False(File.Exists(cachedBundlePath)); + } + public void Dispose() { string[] args = { "-burn.ignoredependencies=ALL" }; diff --git a/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj b/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj index 78dbaf74..988834b2 100644 --- a/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj +++ b/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj @@ -4,16 +4,14 @@ netcoreapp3.1 - - - - NU1701 + x64 - + + -- cgit v1.2.3-55-g6feb