1
// *********************************************************************
2
// Copyright 2007, Andreas Schlapsi
3
// This is free software licensed under the MIT license.
4
// *********************************************************************
6
using System.Reflection;
9
using NUnit.Framework.SyntaxHelpers;
11
namespace NUnitExtension.RowTest.AddIn.UnitTests
14
public class RowTestCaseTest : BaseTestFixture
16
public RowTestCaseTest()
21
public void Initialize()
23
MethodInfo method = GetRowTestMethodWith2Rows();
24
object[] arguments = new object[] { 4, 5 };
26
RowTestCase testCase = new RowTestCase(method, null, arguments);
28
Assert.That(testCase.Arguments, Is.SameAs(arguments));
29
Assert.That(testCase.Method, Is.SameAs(method));
30
Assert.That(testCase.FixtureType, Is.SameAs(typeof (TestClass)));
34
public void Initialize_TestNameIsMethodName()
36
MethodInfo method = GetRowTestMethodWith2Rows();
37
object[] arguments = new object[] { 4, 5 };
39
RowTestCase testCase = new RowTestCase(method, null, arguments);
41
string expectedTestName = Method_RowTestMethodWith2Rows + "(4, 5)";
42
string expectedFullTestName = typeof(TestClass).FullName + "." + expectedTestName;
43
Assert.That(testCase.TestName.Name, Is.EqualTo(expectedTestName));
44
Assert.That(testCase.TestName.FullName, Is.EqualTo(expectedFullTestName));
48
public void Initialize_TestNameIsProvided()
50
MethodInfo method = GetRowTestMethodWith2Rows();
51
object[] arguments = new object[] { 4, 5 };
52
string testName = "UnitTest";
54
RowTestCase testCase = new RowTestCase(method, testName, arguments);
56
string expectedTestName = testName + "(4, 5)";
57
string expectedFullTestName = typeof(TestClass).FullName + "." + expectedTestName;
58
Assert.That(testCase.TestName.Name, Is.EqualTo(expectedTestName));
59
Assert.That(testCase.TestName.FullName, Is.EqualTo(expectedFullTestName));
63
public void RunTestMethod_WithArguments()
65
object[] arguments = new object[] { 42, 53 };
66
TestClass testFixture = new TestClass();
67
RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWith2Rows, arguments);
70
TestResult result = new TestResult(testCase);
72
TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
75
testCase.RunTestMethod(result);
77
Assert.That(testFixture.Arguments, Is.Not.Null);
78
Assert.That(testFixture.Arguments[0], Is.EqualTo(arguments[0]));
79
Assert.That(testFixture.Arguments[1], Is.EqualTo(arguments[1]));
84
public void RunTestMethod_WithNormalAndNullArguments()
86
object[] arguments = new object[] { 42, null };
87
TestClass testFixture = new TestClass();
88
RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWithNormalAndNullArgument, arguments);
91
TestResult result = new TestResult(testCase);
93
TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
96
testCase.RunTestMethod(result);
98
Assert.That(testFixture.Arguments, Is.Not.Null);
99
Assert.That(testFixture.Arguments[0], Is.EqualTo(arguments[0]));
100
Assert.That(testFixture.Arguments[1], Is.Null);
105
public void RunTestMethod_WithNullArgument()
107
object[] arguments = new object[] { null };
108
TestClass testFixture = new TestClass();
109
RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWithNullArgument, arguments);
112
TestResult result = new TestResult(testCase);
114
TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
117
testCase.RunTestMethod(result);
119
Assert.That(testFixture.Arguments, Is.Not.Null);
120
Assert.That(testFixture.Arguments[0], Is.Null);
123
private RowTestCase CreateRowTestCase(TestClass fixture, string methodName, params object[] arguments)
125
MethodInfo method = GetTestClassMethod(methodName);
127
NUnitTestFixture nunitTestFixture = new NUnitTestFixture(fixture.GetType());
128
nunitTestFixture.Fixture = fixture;
130
TestSuite suite = new TestSuite(nunitTestFixture.TestName.Name, method.Name);
131
suite.Parent = nunitTestFixture;
132
suite.Fixture = fixture;
134
RowTestCase testCase = new RowTestCase(method, method.Name, arguments);
135
testCase.Fixture = fixture;