OneTimeSetUpCommand
OneTimeSetUpCommand runs any one-time setup methods for a suite,
constructing the user test object if necessary.
using NUnit.Framework.Interfaces;
using System.Collections.Generic;
namespace NUnit.Framework.Internal.Commands
{
public class OneTimeSetUpCommand : TestCommand
{
private readonly TestSuite _suite;
private readonly ITypeInfo _typeInfo;
private readonly object[] _arguments;
private readonly List<SetUpTearDownItem> _setUpTearDown;
private readonly List<TestActionItem> _actions;
public OneTimeSetUpCommand(TestSuite suite, List<SetUpTearDownItem> setUpTearDown, List<TestActionItem> actions)
: base(suite)
{
_suite = suite;
_typeInfo = suite.TypeInfo;
_arguments = suite.Arguments;
_setUpTearDown = setUpTearDown;
_actions = actions;
}
public override TestResult Execute(TestExecutionContext context)
{
if (_typeInfo != null) {
if (!_typeInfo.IsStaticClass) {
context.TestObject = (_suite.Fixture ?? _typeInfo.Construct(_arguments));
if (_suite.Fixture == null)
_suite.Fixture = context.TestObject;
base.Test.Fixture = _suite.Fixture;
}
int num = _setUpTearDown.Count;
while (num > 0) {
_setUpTearDown[--num].RunSetUp(context);
}
}
for (int i = 0; i < _actions.Count; i++) {
_actions[i].BeforeTest(base.Test);
}
return context.CurrentResult;
}
}
}