NetPlatformAttribute
Marks an assembly, test fixture or test method as applying to a specific platform.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class NetPlatformAttribute : IncludeExcludeAttribute, IApplyToTest
{
public NetPlatformAttribute()
{
}
[System.Runtime.CompilerServices.NullableContext(2)]
public NetPlatformAttribute(string platforms)
: base(platforms)
{
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void ApplyToTest(Test test)
{
if (test.RunState != 0 && test.RunState != RunState.Ignored && !IsPlatformSupported(base.Include, base.Exclude, out string reason)) {
test.RunState = RunState.Skipped;
test.Properties.Add("_SKIPREASON", reason);
}
}
[System.Runtime.CompilerServices.NullableContext(2)]
private static bool IsPlatformSupported(string include, string exclude, [System.Runtime.CompilerServices.Nullable(1)] out string reason)
{
if (include != null && !NetPlatformHelper.IsPlatformSupported(include)) {
reason = "Only supported on " + include;
return false;
}
if (exclude != null && NetPlatformHelper.IsPlatformSupported(exclude)) {
reason = "Not supported on " + exclude;
return false;
}
reason = string.Empty;
return true;
}
}
}