~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/NUnitCore/tests/SetUpTest.cs

  • Committer: charliepoole
  • Date: 2006-01-06 01:08:17 UTC
  • Revision ID: vcs-imports@canonical.com-20060106010817-z6xazs4kd89zj8j1
Move core from under NUnitFramework to NUnitCore directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region Copyright (c) 2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
 
2
/************************************************************************************
 
3
'
 
4
' Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
 
5
' Copyright  2000-2002 Philip A. Craig
 
6
'
 
7
' This software is provided 'as-is', without any express or implied warranty. In no 
 
8
' event will the authors be held liable for any damages arising from the use of this 
 
9
' software.
 
10
 
11
' Permission is granted to anyone to use this software for any purpose, including 
 
12
' commercial applications, and to alter it and redistribute it freely, subject to the 
 
13
' following restrictions:
 
14
'
 
15
' 1. The origin of this software must not be misrepresented; you must not claim that 
 
16
' you wrote the original software. If you use this software in a product, an 
 
17
' acknowledgment (see the following) in the product documentation is required.
 
18
'
 
19
' Portions Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
 
20
' or Copyright  2000-2002 Philip A. Craig
 
21
'
 
22
' 2. Altered source versions must be plainly marked as such, and must not be 
 
23
' misrepresented as being the original software.
 
24
'
 
25
' 3. This notice may not be removed or altered from any source distribution.
 
26
'
 
27
'***********************************************************************************/
 
28
#endregion
 
29
 
 
30
using NUnit.Framework;
 
31
using NUnit.Core.Builders;
 
32
 
 
33
namespace NUnit.Core.Tests
 
34
{
 
35
        [TestFixture]
 
36
        public class SetUpTest
 
37
        {       
 
38
                private void RunTestOnFixture( object fixture )
 
39
                {
 
40
                        TestSuite suite = TestFixtureBuilder.Make( fixture );
 
41
                        suite.Run( NullListener.NULL );
 
42
                }
 
43
 
 
44
                [TestFixture]
 
45
                internal class SetUpAndTearDownFixture
 
46
                {
 
47
                        internal bool wasSetUpCalled;
 
48
                        internal bool wasTearDownCalled;
 
49
 
 
50
                        [SetUp]
 
51
                        public virtual void Init()
 
52
                        {
 
53
                                wasSetUpCalled = true;
 
54
                        }
 
55
 
 
56
                        [TearDown]
 
57
                        public virtual void Destroy()
 
58
                        {
 
59
                                wasTearDownCalled = true;
 
60
                        }
 
61
 
 
62
                        [Test]
 
63
                        public void Success(){}
 
64
                }
 
65
 
 
66
 
 
67
                [TestFixture]
 
68
                internal class SetUpAndTearDownCounterFixture
 
69
                {
 
70
                        internal int setUpCounter;
 
71
                        internal int tearDownCounter;
 
72
 
 
73
                        [SetUp]
 
74
                        public virtual void Init()
 
75
                        {
 
76
                                setUpCounter++;
 
77
                        }
 
78
 
 
79
                        [TearDown]
 
80
                        public virtual void Destroy()
 
81
                        {
 
82
                                tearDownCounter++;
 
83
                        }
 
84
 
 
85
                        [Test]
 
86
                        public void TestOne(){}
 
87
 
 
88
                        [Test]
 
89
                        public void TestTwo(){}
 
90
 
 
91
                        [Test]
 
92
                        public void TestThree(){}
 
93
                }
 
94
                
 
95
                [TestFixture]
 
96
                internal class InheritSetUpAndTearDown : SetUpAndTearDownFixture
 
97
                {
 
98
                        [Test]
 
99
                        public void AnotherTest(){}
 
100
                }
 
101
 
 
102
                [Test]
 
103
                public void SetUpAndTearDownCounter()
 
104
                {
 
105
                        SetUpAndTearDownCounterFixture fixture = new SetUpAndTearDownCounterFixture();
 
106
                        RunTestOnFixture( fixture );
 
107
 
 
108
                        Assert.AreEqual(3, fixture.setUpCounter);
 
109
                        Assert.AreEqual(3, fixture.tearDownCounter);
 
110
                }
 
111
 
 
112
                
 
113
                [Test]
 
114
                public void MakeSureSetUpAndTearDownAreCalled()
 
115
                {
 
116
                        SetUpAndTearDownFixture fixture = new SetUpAndTearDownFixture();
 
117
                        RunTestOnFixture( fixture );
 
118
 
 
119
                        Assert.IsTrue(fixture.wasSetUpCalled);
 
120
                        Assert.IsTrue(fixture.wasTearDownCalled);
 
121
                }
 
122
 
 
123
                [Test]
 
124
                public void CheckInheritedSetUpAndTearDownAreCalled()
 
125
                {
 
126
                        InheritSetUpAndTearDown fixture = new InheritSetUpAndTearDown();
 
127
                        RunTestOnFixture( fixture );
 
128
 
 
129
                        Assert.IsTrue(fixture.wasSetUpCalled);
 
130
                        Assert.IsTrue(fixture.wasTearDownCalled);
 
131
                }
 
132
 
 
133
                [TestFixture]
 
134
                internal class DefineInheritSetUpAndTearDown : SetUpAndTearDownFixture
 
135
                {
 
136
                        internal bool derivedSetUpCalled;
 
137
                        internal bool derivedTearDownCalled;
 
138
 
 
139
                        [SetUp]
 
140
                        public override void Init()
 
141
                        {
 
142
                                derivedSetUpCalled = true;
 
143
                        }
 
144
 
 
145
                        [TearDown]
 
146
                        public override void Destroy()
 
147
                        {
 
148
                                derivedTearDownCalled = true;
 
149
                        }
 
150
 
 
151
                        [Test]
 
152
                        public void AnotherTest(){}
 
153
                }
 
154
 
 
155
                [Test]
 
156
                public void CheckInheritedSetUpAndTearDownAreNotCalled()
 
157
                {
 
158
                        DefineInheritSetUpAndTearDown fixture = new DefineInheritSetUpAndTearDown();
 
159
                        RunTestOnFixture( fixture );
 
160
 
 
161
                        Assert.IsFalse(fixture.wasSetUpCalled);
 
162
                        Assert.IsFalse(fixture.wasTearDownCalled);
 
163
                        Assert.IsTrue(fixture.derivedSetUpCalled);
 
164
                        Assert.IsTrue(fixture.derivedTearDownCalled);
 
165
                }
 
166
        }
 
167
}