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(2)]
[System.Runtime.CompilerServices.Nullable(0)]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class IgnoreAttribute : NUnitAttribute, IApplyToTest
{
[System.Runtime.CompilerServices.Nullable(1)]
private readonly string _reason;
private DateTime? _untilDate;
private string _until;
[StringSyntax("DateTimeFormat")]
public string Until {
get {
return _until;
}
[param: DisallowNull]
set {
_until = value;
_untilDate = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
}
}
[System.Runtime.CompilerServices.NullableContext(1)]
public IgnoreAttribute(string reason)
{
_reason = reason;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public void ApplyToTest(Test test)
{
if (test.RunState != 0) {
if (_untilDate.HasValue) {
if (_untilDate.Value > DateTime.Now) {
test.RunState = RunState.Ignored;
IPropertyBagDataExtensions.AddIgnoreUntilReason(test.Properties, _untilDate.Value, _reason);
}
test.Properties.Set("IgnoreUntilDate", _untilDate.Value.ToString("u"));
} else {
test.RunState = RunState.Ignored;
test.Properties.Set("_SKIPREASON", _reason);
}
}
}
}
}