Skip to content

Commit 5521bb4

Browse files
Make IgnoreAttribute.Reason public (nunit#4781)
* Make `IgnoreAttribute.Reason` public, null check up-front * Simplify null handling around `AddIgnoreUntilReason` * remove up-front null check in `IgnoreAttribute` * allow null on set-reason * whitespace * remove null check test
1 parent c7e915b commit 5521bb4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/NUnitFramework/framework/Attributes/IgnoreAttribute.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ namespace NUnit.Framework
1515
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
1616
public class IgnoreAttribute : NUnitAttribute, IApplyToTest
1717
{
18-
private readonly string _reason;
1918
private DateTime? _untilDate;
2019
private string? _until;
2120

2221
/// <summary>
23-
/// Constructs the attribute giving a reason for ignoring the test
22+
/// Constructs the attribute giving a reason for ignoring the test.
2423
/// </summary>
25-
/// <param name="reason">The reason for ignoring the test</param>
24+
/// <param name="reason">The reason for ignoring the test.</param>
25+
/// <exception cref="ArgumentNullException">If <paramref name="reason"/> is null.</exception>
2626
public IgnoreAttribute(string reason)
2727
{
28-
_reason = reason;
28+
Reason = reason;
2929
}
3030

31+
/// <summary>
32+
/// Gets the reason for ignoring the test.
33+
/// </summary>
34+
public string Reason { get; }
35+
3136
/// <summary>
3237
/// The date in the future to stop ignoring the test as a string in UTC time.
3338
/// For example for a date and time, "2014-12-25 08:10:00Z" or for just a date,
@@ -66,14 +71,14 @@ public void ApplyToTest(Test test)
6671
if (_untilDate.Value > DateTime.Now)
6772
{
6873
test.RunState = RunState.Ignored;
69-
test.Properties.AddIgnoreUntilReason(_untilDate.Value, _reason);
74+
test.Properties.AddIgnoreUntilReason(_untilDate.Value, Reason);
7075
}
7176
test.Properties.Set(PropertyNames.IgnoreUntilDate, _untilDate.Value.ToString("u"));
7277

7378
return;
7479
}
7580
test.RunState = RunState.Ignored;
76-
test.Properties.Set(PropertyNames.SkipReason, _reason);
81+
test.Properties.Set(PropertyNames.SkipReason, Reason);
7782
}
7883
}
7984

src/NUnitFramework/tests/Attributes/ApplyToTestTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public void DescriptionAttributeSetsDescriptionOnNonRunnableTest()
7979

8080
#region IgnoreAttribute
8181

82+
[Test]
83+
public void IgnoreAttributeReason()
84+
{
85+
var ignore = new IgnoreAttribute("BECAUSE");
86+
Assert.That(ignore.Reason, Is.EqualTo("BECAUSE"));
87+
}
88+
8289
[Test]
8390
public void IgnoreAttributeIgnoresTest()
8491
{

0 commit comments

Comments
 (0)