blob: fcd19b951ba49cfd3e6f50d83134e5838e28539a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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")}).";
}
}
}
}
|