Created
October 4, 2021 19:46
-
-
Save jnm2/99289cffa9ec74c1973559fe3ac19790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using NUnit.Framework; | |
using NUnit.Framework.Interfaces; | |
using NUnit.Framework.Internal; | |
using NUnit.Framework.Internal.Commands; | |
public sealed class EffectiveAttribute : NUnitAttribute, IWrapSetUpTearDown | |
{ | |
private readonly DateTime starting; | |
public EffectiveAttribute(string starting) | |
{ | |
this.starting = DateTime.Parse(starting, CultureInfo.InvariantCulture); | |
} | |
public TestCommand Wrap(TestCommand command) | |
{ | |
return new Command(starting, command); | |
} | |
private sealed class Command : DelegatingTestCommand | |
{ | |
private readonly DateTime starting; | |
public Command(DateTime starting, TestCommand innerCommand) | |
: base(innerCommand) | |
{ | |
this.starting = starting; | |
} | |
public override TestResult Execute(TestExecutionContext context) | |
{ | |
if (DateTime.Now < starting) | |
{ | |
context.CurrentResult.RecordAssertion( | |
AssertionStatus.Inconclusive, | |
$"This test is not effective until {starting}."); | |
context.CurrentResult.RecordTestCompletion(); | |
return context.CurrentResult; | |
} | |
context.CurrentResult.RecordAssertion( | |
AssertionStatus.Error, | |
$"Now that this test is effective, remove {nameof(EffectiveAttribute)} from the test method."); | |
return innerCommand.Execute(context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment