From 031991f32f059b64374e6d257cbe573304dd577f Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 13 May 2022 11:40:45 -0500 Subject: Add ability to skip tests at runtime, and skip long running cache tests 6665 --- src/test/burn/WixTestTools/RuntimeFactAttribute.cs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/burn/WixTestTools/RuntimeFactAttribute.cs (limited to 'src/test/burn/WixTestTools/RuntimeFactAttribute.cs') diff --git a/src/test/burn/WixTestTools/RuntimeFactAttribute.cs b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs new file mode 100644 index 00000000..fcd19b95 --- /dev/null +++ b/src/test/burn/WixTestTools/RuntimeFactAttribute.cs @@ -0,0 +1,34 @@ +// 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.Security.Principal; + using WixBuildTools.TestSupport.XunitExtensions; + + public class RuntimeFactAttribute : SkippableFactAttribute + { + const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled"; + + public static bool RuntimeTestsEnabled { get; } + public static bool RunningAsAdministrator { get; } + + static RuntimeFactAttribute() + { + using var identity = WindowsIdentity.GetCurrent(); + var principal = new WindowsPrincipal(identity); + RunningAsAdministrator = principal.IsInRole(WindowsBuiltInRole.Administrator); + + var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName); + RuntimeTestsEnabled = Boolean.TryParse(testsEnabledString, out var testsEnabled) && testsEnabled; + } + + public RuntimeFactAttribute() + { + if (!RuntimeTestsEnabled || !RunningAsAdministrator) + { + this.Skip = $"These tests must run elevated ({(RunningAsAdministrator ? "passed" : "failed")}). These tests affect machine state. To accept the consequences, set the {RequiredEnvironmentVariableName} environment variable to true ({(RuntimeTestsEnabled ? "passed" : "failed")})."; + } + } + } +} -- cgit v1.2.3-55-g6feb