IgnoreAttribute
Marks an assembly, test fixture or test method as being ignored. Ignored tests result in a warning message when the tests are run.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Extensions;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace NUnit.Framework
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class IgnoreAttribute : NUnitAttribute, IApplyToTest
{
private DateTime? _untilDate;
[System.Runtime.CompilerServices.Nullable(2)]
private string _until;
public string Reason { get; }
[System.Runtime.CompilerServices.Nullable(2)]
[StringSyntax("DateTimeFormat")]
public string Until {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
return _until;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[param: DisallowNull]
set {
_until = value;
_untilDate = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
}
}
public IgnoreAttribute(string reason)
{
Reason = reason;
}
public void ApplyToTest(Test test)
{
if (test.RunState != 0) {
if (_untilDate.HasValue) {
if (_untilDate.Value > DateTime.Now) {
test.RunState = RunState.Ignored;
test.Properties.AddIgnoreUntilReason(_untilDate.Value, Reason);
}
test.Properties.Set("IgnoreUntilDate", _untilDate.Value.ToString("u"));
} else {
test.RunState = RunState.Ignored;
test.Properties.Set("_SKIPREASON", Reason);
}
}
}
}
}