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

OneTimeTearDownCommand

OneTimeTearDownCommand performs any teardown actions specified for a suite and calls Dispose on the user test object, if any.
using NUnit.Framework.Interfaces; using System; using System.Collections.Generic; namespace NUnit.Framework.Internal.Commands { public class OneTimeTearDownCommand : TestCommand { private List<SetUpTearDownItem> _setUpTearDownItems; private List<TestActionItem> _actions; public OneTimeTearDownCommand(TestSuite suite, List<SetUpTearDownItem> setUpTearDownItems, List<TestActionItem> actions) : base(suite) { _setUpTearDownItems = setUpTearDownItems; _actions = actions; } public override TestResult Execute(TestExecutionContext context) { TestResult currentResult = context.CurrentResult; try { int num = _actions.Count; while (num > 0) { _actions[--num].AfterTest(base.Test); } if (_setUpTearDownItems != null) { foreach (SetUpTearDownItem setUpTearDownItem in _setUpTearDownItems) { setUpTearDownItem.RunTearDown(context); } } IDisposable disposable = context.TestObject as IDisposable; if (disposable == null) return currentResult; if (!(base.Test is IDisposableFixture)) return currentResult; disposable.Dispose(); return currentResult; } catch (Exception ex) { currentResult.RecordTearDownException(ex); return currentResult; } } } }