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 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs (limited to 'src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs') 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); + } + } + } +} -- cgit v1.2.3-55-g6feb