TestMethodCommand
TestMethodCommand is the lowest level concrete command
used to run actual test cases.
using NUnit.Framework.Interfaces;
namespace NUnit.Framework.Internal.Commands
{
public class TestMethodCommand : TestCommand
{
private readonly TestMethod testMethod;
private readonly object[] arguments;
public TestMethodCommand(TestMethod testMethod)
: base(testMethod)
{
this.testMethod = testMethod;
arguments = testMethod.Arguments;
}
public override TestResult Execute(TestExecutionContext context)
{
object actual = RunTestMethod(context);
if (testMethod.HasExpectedResult)
Assert.AreEqual(testMethod.ExpectedResult, actual);
context.CurrentResult.SetResult(ResultState.Success);
if (context.CurrentResult.AssertionResults.Count > 0)
context.CurrentResult.RecordTestCompletion();
return context.CurrentResult;
}
private object RunTestMethod(TestExecutionContext context)
{
return RunNonAsyncTestMethod(context);
}
private object RunNonAsyncTestMethod(TestExecutionContext context)
{
return testMethod.Method.Invoke(context.TestObject, arguments);
}
}
}