1
#region Copyright (c) 2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2
/************************************************************************************
4
' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5
' Copyright 2000-2002 Philip A. Craig
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
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:
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.
19
' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20
' or Copyright 2000-2002 Philip A. Craig
22
' 2. Altered source versions must be plainly marked as such, and must not be
23
' misrepresented as being the original software.
25
' 3. This notice may not be removed or altered from any source distribution.
27
'***********************************************************************************/
30
using NUnit.Framework;
31
using NUnit.Core.Builders;
33
namespace NUnit.Core.Tests
36
public class SetUpTest
38
private void RunTestOnFixture( object fixture )
40
TestSuite suite = TestFixtureBuilder.Make( fixture );
41
suite.Run( NullListener.NULL );
45
internal class SetUpAndTearDownFixture
47
internal bool wasSetUpCalled;
48
internal bool wasTearDownCalled;
51
public virtual void Init()
53
wasSetUpCalled = true;
57
public virtual void Destroy()
59
wasTearDownCalled = true;
63
public void Success(){}
68
internal class SetUpAndTearDownCounterFixture
70
internal int setUpCounter;
71
internal int tearDownCounter;
74
public virtual void Init()
80
public virtual void Destroy()
86
public void TestOne(){}
89
public void TestTwo(){}
92
public void TestThree(){}
96
internal class InheritSetUpAndTearDown : SetUpAndTearDownFixture
99
public void AnotherTest(){}
103
public void SetUpAndTearDownCounter()
105
SetUpAndTearDownCounterFixture fixture = new SetUpAndTearDownCounterFixture();
106
RunTestOnFixture( fixture );
108
Assert.AreEqual(3, fixture.setUpCounter);
109
Assert.AreEqual(3, fixture.tearDownCounter);
114
public void MakeSureSetUpAndTearDownAreCalled()
116
SetUpAndTearDownFixture fixture = new SetUpAndTearDownFixture();
117
RunTestOnFixture( fixture );
119
Assert.IsTrue(fixture.wasSetUpCalled);
120
Assert.IsTrue(fixture.wasTearDownCalled);
124
public void CheckInheritedSetUpAndTearDownAreCalled()
126
InheritSetUpAndTearDown fixture = new InheritSetUpAndTearDown();
127
RunTestOnFixture( fixture );
129
Assert.IsTrue(fixture.wasSetUpCalled);
130
Assert.IsTrue(fixture.wasTearDownCalled);
134
internal class DefineInheritSetUpAndTearDown : SetUpAndTearDownFixture
136
internal bool derivedSetUpCalled;
137
internal bool derivedTearDownCalled;
140
public override void Init()
142
derivedSetUpCalled = true;
146
public override void Destroy()
148
derivedTearDownCalled = true;
152
public void AnotherTest(){}
156
public void CheckInheritedSetUpAndTearDownAreNotCalled()
158
DefineInheritSetUpAndTearDown fixture = new DefineInheritSetUpAndTearDown();
159
RunTestOnFixture( fixture );
161
Assert.IsFalse(fixture.wasSetUpCalled);
162
Assert.IsFalse(fixture.wasTearDownCalled);
163
Assert.IsTrue(fixture.derivedSetUpCalled);
164
Assert.IsTrue(fixture.derivedTearDownCalled);