TestActionItem
TestActionItem wraps a single execution of an ITestAction.
Its primary purpose is to track whether the BeforeTest
method has been called and suppress calling the
AfterTest method if it has not. This is necessary when
ITestActions are used before and after a CompositeWorkItem,
since the OneTimeSetUpCommand and OneTimeTearDownCommand
are separate command chains. By sharing a TestActionItem
between the setup and teardown chains, the two calls can
be coordinated.
using NUnit.Framework.Interfaces;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Internal.Commands
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class TestActionItem
{
private readonly ITestAction _action;
public bool BeforeTestWasRun { get; set; }
public TestActionItem(ITestAction action)
{
_action = action;
}
public void BeforeTest(ITest test)
{
BeforeTestWasRun = true;
_action.BeforeTest(test);
}
public void AfterTest(ITest test)
{
if (BeforeTestWasRun)
_action.AfterTest(test);
}
}
}