<PackageReference Include="NUnit" Version="4.5.0" />

TestActionCommand

TestActionCommand handles a single ITestAction applied to a test. It runs the BeforeTest method, then runs the test and finally runs the AfterTest method.
using System; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal.Commands { public class TestActionCommand : BeforeAndAfterTestCommand { [NullableContext(1)] public TestActionCommand(TestCommand innerCommand, ITestAction action) : base(innerCommand) { Guard.ArgumentValid(innerCommand.Test is TestMethod, "TestActionCommand may only apply to a TestMethod", "innerCommand"); ArgumentNullException.ThrowIfNull(action, "action"); BeforeTest = delegate(TestExecutionContext context) { <>c__DisplayClass0_0 <>c__DisplayClass0_2; Action action3 = context.ExecutionHooksEnabled ? ((Action)delegate { MethodWrapper hookedMethod2 = new MethodWrapper(action.GetType(), "BeforeTest"); try { context.ExecutionHooks.OnBeforeTestActionBeforeTest(context, hookedMethod2); <>c__DisplayClass0_2.<.ctor>g__RunBeforeTest|3(); } catch (Exception exceptionContext2) { context.ExecutionHooks.OnAfterTestActionBeforeTest(context, hookedMethod2, exceptionContext2); throw; } context.ExecutionHooks.OnAfterTestActionBeforeTest(context, hookedMethod2, null); }) : ((Action)delegate { action.BeforeTest(base.Test); }); action3(); }; AfterTest = delegate(TestExecutionContext context) { <>c__DisplayClass0_0 <>c__DisplayClass0_; Action action2 = context.ExecutionHooksEnabled ? ((Action)delegate { MethodWrapper hookedMethod = new MethodWrapper(action.GetType(), "AfterTest"); try { context.ExecutionHooks.OnBeforeTestActionAfterTest(context, hookedMethod); <>c__DisplayClass0_.<.ctor>g__RunAfterTest|5(); } catch (Exception exceptionContext) { context.ExecutionHooks.OnAfterTestActionAfterTest(context, hookedMethod, exceptionContext); throw; } context.ExecutionHooks.OnAfterTestActionAfterTest(context, hookedMethod, null); }) : ((Action)delegate { action.AfterTest(base.Test); }); action2(); }; } } }