~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to addins/RowTest/NUnitExtension.RowTest.AddIn.UnitTests/RowTestCaseTest.cs

  • Committer: charliepoole
  • Date: 2008-05-05 22:17:22 UTC
  • Revision ID: vcs-imports@canonical.com-20080505221722-7bdjujqed8pk6al3
Add back RowTestExtension as a separately compiled assembly, bundled
with NUnit, and modify build script to handle addins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// *********************************************************************
 
2
// Copyright 2007, Andreas Schlapsi
 
3
// This is free software licensed under the MIT license. 
 
4
// *********************************************************************
 
5
using System;
 
6
using System.Reflection;
 
7
using NUnit.Core;
 
8
using NUnit.Framework;
 
9
using NUnit.Framework.SyntaxHelpers;
 
10
 
 
11
namespace NUnitExtension.RowTest.AddIn.UnitTests
 
12
{
 
13
        [TestFixture]
 
14
        public class RowTestCaseTest : BaseTestFixture
 
15
        {
 
16
                public RowTestCaseTest()
 
17
                {
 
18
                }
 
19
        
 
20
                [Test]
 
21
                public void Initialize()
 
22
                {
 
23
                        MethodInfo method = GetRowTestMethodWith2Rows();
 
24
                        object[] arguments = new object[] { 4, 5 };
 
25
                        
 
26
                        RowTestCase testCase = new RowTestCase(method, null, arguments);
 
27
                        
 
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)));
 
31
                }
 
32
        
 
33
                [Test]
 
34
                public void Initialize_TestNameIsMethodName()
 
35
                {
 
36
                        MethodInfo method = GetRowTestMethodWith2Rows();
 
37
                        object[] arguments = new object[] { 4, 5 };
 
38
                        
 
39
                        RowTestCase testCase = new RowTestCase(method, null, arguments);
 
40
 
 
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));
 
45
                }
 
46
                
 
47
                [Test]
 
48
                public void Initialize_TestNameIsProvided()
 
49
                {
 
50
                        MethodInfo method = GetRowTestMethodWith2Rows();
 
51
                        object[] arguments = new object[] { 4, 5 };
 
52
                        string testName = "UnitTest";
 
53
                        
 
54
                        RowTestCase testCase = new RowTestCase(method, testName, arguments);
 
55
 
 
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));
 
60
                }
 
61
                
 
62
                [Test]
 
63
                public void RunTestMethod_WithArguments()
 
64
                {
 
65
                        object[] arguments = new object[] { 42, 53 };
 
66
                        TestClass testFixture = new TestClass();
 
67
                        RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWith2Rows, arguments);
 
68
 
 
69
#if NUNIT_2_5
 
70
            TestResult result = new TestResult(testCase);
 
71
#else
 
72
            TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
 
73
#endif
 
74
                        
 
75
                        testCase.RunTestMethod(result);
 
76
                        
 
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]));
 
80
                }
 
81
 
 
82
#if NET_2_0
 
83
                [Test]
 
84
                public void RunTestMethod_WithNormalAndNullArguments()
 
85
                {
 
86
                        object[] arguments = new object[] { 42, null };
 
87
                        TestClass testFixture = new TestClass();
 
88
                        RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWithNormalAndNullArgument, arguments);
 
89
 
 
90
#if NUNIT_2_5
 
91
            TestResult result = new TestResult(testCase);
 
92
#else
 
93
            TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
 
94
#endif
 
95
                        
 
96
                        testCase.RunTestMethod(result);
 
97
                        
 
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);
 
101
                }
 
102
#endif
 
103
                
 
104
                [Test]
 
105
                public void RunTestMethod_WithNullArgument()
 
106
                {
 
107
                        object[] arguments = new object[] { null };
 
108
                        TestClass testFixture = new TestClass();
 
109
                        RowTestCase testCase = CreateRowTestCase(testFixture, Method_RowTestMethodWithNullArgument, arguments);
 
110
 
 
111
#if NUNIT_2_5
 
112
            TestResult result = new TestResult(testCase);
 
113
#else
 
114
            TestCaseResult result = new TestCaseResult(testCase.TestName.Name);
 
115
#endif
 
116
                        
 
117
                        testCase.RunTestMethod(result);
 
118
                        
 
119
                        Assert.That(testFixture.Arguments, Is.Not.Null);
 
120
                        Assert.That(testFixture.Arguments[0], Is.Null);
 
121
                }
 
122
                
 
123
                private RowTestCase CreateRowTestCase(TestClass fixture, string methodName, params object[] arguments)
 
124
                {
 
125
                        MethodInfo method = GetTestClassMethod(methodName);
 
126
                        
 
127
                        NUnitTestFixture nunitTestFixture = new NUnitTestFixture(fixture.GetType());
 
128
                        nunitTestFixture.Fixture = fixture;
 
129
                        
 
130
                        TestSuite suite = new TestSuite(nunitTestFixture.TestName.Name, method.Name);
 
131
                        suite.Parent = nunitTestFixture;
 
132
                        suite.Fixture = fixture;
 
133
 
 
134
                        RowTestCase testCase = new RowTestCase(method, method.Name, arguments);
 
135
                        testCase.Fixture = fixture;
 
136
                        suite.Add(testCase);
 
137
                        
 
138
                        return testCase;
 
139
                }
 
140
        }
 
141
}