OneTimeSetUpCommand
OneTimeSetUpCommand runs any one-time setup methods for a suite,
constructing the user test object if necessary.
using System;
using System.Collections.Generic;
namespace NUnit.Framework.Internal.Commands
{
public class OneTimeSetUpCommand : TestCommand
{
private readonly TestSuite _suite;
private readonly Type _fixtureType;
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;
_fixtureType = suite.FixtureType;
_arguments = suite.Arguments;
_setUpTearDown = setUpTearDown;
_actions = actions;
}
public override TestResult Execute(TestExecutionContext context)
{
if ((object)_fixtureType != null) {
if (!IsStaticClass(_fixtureType))
context.TestObject = (_suite.Fixture ?? Reflect.Construct(_fixtureType, _arguments));
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;
}
private static bool IsStaticClass(Type type)
{
if (type.IsAbstract)
return type.IsSealed;
return false;
}
}
}