Last active
July 15, 2024 15:57
-
-
Save sodablue/6941abcd6855e71b4393118c3e01bf2f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 NUnit.Framework.Interfaces; | |
| using NUnit.Framework.Internal; | |
| using System.Diagnostics; | |
| namespace NUnit.Framework | |
| { | |
| public class DebugExplicitAttribute : NUnitAttribute, IApplyToTest | |
| { | |
| private readonly string _reason; | |
| /// <summary> | |
| /// Default constructor | |
| /// </summary> | |
| public DebugExplicitAttribute() | |
| { | |
| } | |
| /// <summary> | |
| /// Constructor with a reason | |
| /// </summary> | |
| /// <param name="reason">The reason test is marked explicit</param> | |
| public DebugExplicitAttribute(string reason) | |
| { | |
| _reason = reason; | |
| } | |
| #region IApplyToTest members | |
| /// <summary> | |
| /// Modifies a test by marking it as explicit. | |
| /// </summary> | |
| /// <param name="test">The test to modify</param> | |
| public void ApplyToTest(Test test) | |
| { | |
| if (!Debugger.IsAttached) | |
| { | |
| //Skip = "Only running in interactive mode."; | |
| test.RunState = RunState.Ignored; | |
| test.Properties.Set(PropertyNames.SkipReason, $"Explicit"); | |
| if (_reason != null) | |
| test.Properties.Set(PropertyNames.SkipReason, $"Explicit: {_reason}"); | |
| } | |
| if (test.RunState != RunState.NotRunnable && test.RunState != RunState.Ignored) | |
| { | |
| test.RunState = RunState.Explicit; | |
| if (_reason != null) | |
| test.Properties.Set(PropertyNames.SkipReason, _reason); | |
| } | |
| } | |
| #endregion | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment