diff options
Diffstat (limited to 'src/test/burn/WixTestTools')
-rw-r--r-- | src/test/burn/WixTestTools/LongRuntimeFactAttribute.cs | 27 | ||||
-rw-r--r-- | src/test/burn/WixTestTools/RuntimeFactAttribute.cs | 34 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/test/burn/WixTestTools/LongRuntimeFactAttribute.cs b/src/test/burn/WixTestTools/LongRuntimeFactAttribute.cs new file mode 100644 index 00000000..1da10df8 --- /dev/null +++ b/src/test/burn/WixTestTools/LongRuntimeFactAttribute.cs | |||
@@ -0,0 +1,27 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixTestTools | ||
4 | { | ||
5 | using System; | ||
6 | |||
7 | public class LongRuntimeFactAttribute : RuntimeFactAttribute | ||
8 | { | ||
9 | const string RequiredEnvironmentVariableName = "LongRuntimeTestsEnabled"; | ||
10 | |||
11 | public static bool LongRuntimeTestsEnabled { get; } | ||
12 | |||
13 | static LongRuntimeFactAttribute() | ||
14 | { | ||
15 | var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName); | ||
16 | LongRuntimeTestsEnabled = Boolean.TryParse(testsEnabledString, out var testsEnabled) && testsEnabled; | ||
17 | } | ||
18 | |||
19 | public LongRuntimeFactAttribute() | ||
20 | { | ||
21 | if (!LongRuntimeTestsEnabled) | ||
22 | { | ||
23 | this.Skip = $"These tests take a long time to run, so the {RequiredEnvironmentVariableName} environment variable must be set to true."; | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | } | ||
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 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixTestTools | ||
4 | { | ||
5 | using System; | ||
6 | using System.Security.Principal; | ||
7 | using WixBuildTools.TestSupport.XunitExtensions; | ||
8 | |||
9 | public class RuntimeFactAttribute : SkippableFactAttribute | ||
10 | { | ||
11 | const string RequiredEnvironmentVariableName = "RuntimeTestsEnabled"; | ||
12 | |||
13 | public static bool RuntimeTestsEnabled { get; } | ||
14 | public static bool RunningAsAdministrator { get; } | ||
15 | |||
16 | static RuntimeFactAttribute() | ||
17 | { | ||
18 | using var identity = WindowsIdentity.GetCurrent(); | ||
19 | var principal = new WindowsPrincipal(identity); | ||
20 | RunningAsAdministrator = principal.IsInRole(WindowsBuiltInRole.Administrator); | ||
21 | |||
22 | var testsEnabledString = Environment.GetEnvironmentVariable(RequiredEnvironmentVariableName); | ||
23 | RuntimeTestsEnabled = Boolean.TryParse(testsEnabledString, out var testsEnabled) && testsEnabled; | ||
24 | } | ||
25 | |||
26 | public RuntimeFactAttribute() | ||
27 | { | ||
28 | if (!RuntimeTestsEnabled || !RunningAsAdministrator) | ||
29 | { | ||
30 | 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")})."; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | } | ||