From ce73352b1fa1d4f9cded10a0ee410f2e786bd326 Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Mon, 15 Jul 2024 20:06:54 +1000 Subject: Add basic test for Msmq install/uninstall. Fix up lack of WIX CUSTOM_ACTION_DECORATION wrappers Add new RuntimeTest skipper for Server Features / Optional Features. Signed-off-by: Bevan Weiss --- .../RuntimePrereqFeatureFactAttribute.cs | 56 ++++++++++++++++++++++ src/test/burn/WixTestTools/WixTestTools.csproj | 1 + .../MsmqInstall/MsmqInstall.wixproj | 13 +++++ .../MsmqExtensionTests/MsmqInstall/product.wxs | 17 +++++++ .../WixToolsetTest.MsiE2E/MsmqExtensionTests.cs | 27 +++++++++++ 5 files changed, 114 insertions(+) create mode 100644 src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs create mode 100644 src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/MsmqInstall.wixproj create mode 100644 src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/product.wxs create mode 100644 src/test/msi/WixToolsetTest.MsiE2E/MsmqExtensionTests.cs (limited to 'src/test') diff --git a/src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs b/src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs new file mode 100644 index 00000000..aa02d5f3 --- /dev/null +++ b/src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs @@ -0,0 +1,56 @@ +// 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 WixTestTools +{ + using System; + using System.Globalization; + using System.Linq; + using System.Management; + using System.Collections.Generic; + using System.Security.Principal; + using WixInternal.TestSupport.XunitExtensions; + + public class RuntimePrereqFeatureFactAttribute : RuntimeFactAttribute + { + public static HashSet OptionalFeatures = new(StringComparer.OrdinalIgnoreCase); + public static HashSet ServerFeatures = new(StringComparer.OrdinalIgnoreCase); + static RuntimePrereqFeatureFactAttribute() + { + AddFeaturesToSet(ServerFeatures, "Win32_ServerFeature"); + AddFeaturesToSet(OptionalFeatures, "Win32_OptionalFeature"); + } + + private static void AddFeaturesToSet(HashSet featureSet, string featureSetName) + { + try + { + var objMC = new ManagementClass(featureSetName); + var objMOC = objMC?.GetInstances(); + if (objMOC is not null) + { + foreach (var objMO in objMOC) + { + string featureName = (string)objMO.Properties["Name"].Value; + if ((uint)objMO.Properties["InstallState"].Value == 1) + { + featureSet.Add(featureName); + } + } + } + } + catch + { + } + } + + public RuntimePrereqFeatureFactAttribute(params string[] prerequisiteFeatures) : base() + { + var missingRequirements = prerequisiteFeatures.Select(x => x).Where(x => !ServerFeatures.Contains(x) && !OptionalFeatures.Contains(x)); + + if (missingRequirements.Any()) + { + this.Skip = "This test is missing the following Feature pre-requisites: " + String.Join(", ", missingRequirements); + } + } + } +} diff --git a/src/test/burn/WixTestTools/WixTestTools.csproj b/src/test/burn/WixTestTools/WixTestTools.csproj index 19c09294..7a702949 100644 --- a/src/test/burn/WixTestTools/WixTestTools.csproj +++ b/src/test/burn/WixTestTools/WixTestTools.csproj @@ -23,6 +23,7 @@ + diff --git a/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/MsmqInstall.wixproj b/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/MsmqInstall.wixproj new file mode 100644 index 00000000..41e39944 --- /dev/null +++ b/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/MsmqInstall.wixproj @@ -0,0 +1,13 @@ + + + + {A75B81F4-3335-4B4D-B766-303E136ED374} + true + + + + + + + + diff --git a/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/product.wxs b/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/product.wxs new file mode 100644 index 00000000..241b6aed --- /dev/null +++ b/src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/product.wxs @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/msi/WixToolsetTest.MsiE2E/MsmqExtensionTests.cs b/src/test/msi/WixToolsetTest.MsiE2E/MsmqExtensionTests.cs new file mode 100644 index 00000000..41eb8201 --- /dev/null +++ b/src/test/msi/WixToolsetTest.MsiE2E/MsmqExtensionTests.cs @@ -0,0 +1,27 @@ +// 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.MsiE2E +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using WixTestTools; + using Xunit.Abstractions; + + public class MsmqExtensionTests : MsiE2ETests + { + public MsmqExtensionTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + { + } + + [RuntimePrereqFeatureFact("MSMQ-Container", "MSMQ-Server")] + public void CanInstallAndUninstallMsmq() + { + var product = this.CreatePackageInstaller("MsmqInstall"); + product.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + product.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS); + } + } +} -- cgit v1.2.3-55-g6feb