1 // ***********************************************************************
2 // Copyright (c) 2007 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 
24 using System;
25 using NUnit.Framework;
26 #if !NETCF
27 using System.Security.Principal;
28 #endif
29 
30 namespace NUnit.TestData.TestFixtureData
31 {
32 	/// <summary>
33 	/// Classes used for testing NUnit
34 	/// </summary>
35 
36     [TestFixture]
37     public class NoDefaultCtorFixture
38     {
NoDefaultCtorFixture(int index)39         public NoDefaultCtorFixture(int index) { }
40 
41         [Test]
OneTest()42         public void OneTest() { }
43     }
44 
45     [TestFixture(7,3)]
46     public class FixtureWithArgsSupplied
47     {
FixtureWithArgsSupplied(int x, int y)48         public FixtureWithArgsSupplied(int x, int y) { }
49 
50         [Test]
OneTest()51         public void OneTest() { }
52     }
53 
54     [TestFixture]
55 	public class BadCtorFixture
56 	{
BadCtorFixture()57 		BadCtorFixture()
58 		{
59 			throw new Exception();
60 		}
61 
OneTest()62 		[Test] public void OneTest()
63 		{}
64 	}
65 
66     [TestFixture]
67     public class FixtureWithTestFixtureAttribute
68     {
69         [Test]
SomeTest()70         public void SomeTest() { }
71     }
72 
73     public class FixtureWithoutTestFixtureAttributeContainingTest
74     {
75         [Test]
SomeTest()76         public void SomeTest() { }
77     }
78 
79     public class FixtureWithoutTestFixtureAttributeContainingTestCase
80     {
81         [TestCase(42)]
SomeTest(int x)82         public void SomeTest(int x) { }
83     }
84 
85     public class FixtureWithoutTestFixtureAttributeContainingTestCaseSource
86     {
87         [TestCaseSource("data")]
SomeTest(int x)88         public void SomeTest(int x) { }
89     }
90 
91 #if !NUNITLITE
92     public class FixtureWithoutTestFixtureAttributeContainingTheory
93     {
94         [Theory]
SomeTest(int x)95         public void SomeTest(int x) { }
96     }
97 #endif
98 
99 #if CLR_2_0 || CLR_4_0
100     public static class StaticFixtureWithoutTestFixtureAttribute
101     {
102         [Test]
StaticTest()103         public static void StaticTest() { }
104     }
105 #endif
106 
107     [TestFixture]
108 	public class MultipleSetUpAttributes
109 	{
110 		[SetUp]
Init1()111 		public void Init1()
112 		{}
113 
114 		[SetUp]
Init2()115 		public void Init2()
116 		{}
117 
OneTest()118 		[Test] public void OneTest()
119 		{}
120 	}
121 
122 	[TestFixture]
123 	public class MultipleTearDownAttributes
124 	{
125 		[TearDown]
Destroy1()126 		public void Destroy1()
127 		{}
128 
129 		[TearDown]
Destroy2()130 		public void Destroy2()
131 		{}
132 
OneTest()133 		[Test] public void OneTest()
134 		{}
135 	}
136 
137 	[TestFixture]
138 	[Ignore("testing ignore a fixture")]
139 	public class IgnoredFixture
140 	{
141 		[Test]
Success()142 		public void Success()
143 		{}
144 	}
145 
146 	[TestFixture]
147 	public class OuterClass
148 	{
149 		[TestFixture]
150 		public class NestedTestFixture
151 		{
152 			[TestFixture]
153 				public class DoublyNestedTestFixture
154 			{
155 				[Test]
Test()156 				public void Test()
157 				{
158 				}
159 			}
160 		}
161 	}
162 
163 	[TestFixture]
164 	public abstract class AbstractTestFixture
165 	{
166 		[TearDown]
Destroy1()167 		public void Destroy1()
168 		{}
169 
170         [Test]
SomeTest()171         public void SomeTest()
172         {
173         }
174 	}
175 
176     public class DerivedFromAbstractTestFixture : AbstractTestFixture
177     {
178     }
179 
180 	[TestFixture]
181 	public class BaseClassTestFixture
182 	{
183 		[Test]
Success()184 		public void Success() { }
185 	}
186 
187 	public abstract class AbstractDerivedTestFixture : BaseClassTestFixture
188 	{
189         [Test]
Test()190         public void Test()
191         {
192         }
193 	}
194 
195     public class DerivedFromAbstractDerivedTestFixture : AbstractDerivedTestFixture
196     {
197     }
198 
199     [TestFixture]
200     public abstract class AbstractBaseFixtureWithAttribute
201     {
202     }
203 
204     [TestFixture]
205     public abstract class AbstractDerivedFixtureWithSecondAttribute
206         : AbstractBaseFixtureWithAttribute
207     {
208     }
209 
210     public class DoubleDerivedClassWithTwoInheritedAttributes
211         : AbstractDerivedFixtureWithSecondAttribute
212     {
213     }
214 
215     [TestFixture]
216 	public class MultipleFixtureSetUpAttributes
217 	{
218 		[TestFixtureSetUp]
Init1()219 		public void Init1()
220 		{}
221 
222 		[TestFixtureSetUp]
Init2()223 		public void Init2()
224 		{}
225 
OneTest()226 		[Test] public void OneTest()
227 		{}
228 	}
229 
230 	[TestFixture]
231 	public class MultipleFixtureTearDownAttributes
232 	{
233 		[TestFixtureTearDown]
Destroy1()234 		public void Destroy1()
235 		{}
236 
237 		[TestFixtureTearDown]
Destroy2()238 		public void Destroy2()
239 		{}
240 
OneTest()241 		[Test] public void OneTest()
242 		{}
243 	}
244 
245 	// Base class used to ensure following classes
246 	// all have at least one test
247 	public class OneTestBase
248 	{
OneTest()249 		[Test] public void OneTest() { }
250 	}
251 
252 	[TestFixture]
253 	public class PrivateSetUp : OneTestBase
254 	{
255 		[SetUp]
Setup()256 		private void Setup()	{}
257 	}
258 
259 	[TestFixture]
260 	public class ProtectedSetUp : OneTestBase
261 	{
262 		[SetUp]
Setup()263 		protected void Setup()	{}
264 	}
265 
266 	[TestFixture]
267 	public class StaticSetUp : OneTestBase
268 	{
269 		[SetUp]
Setup()270 		public static void Setup() {}
271 	}
272 
273 	[TestFixture]
274 	public class SetUpWithReturnValue : OneTestBase
275 	{
276 		[SetUp]
Setup()277 		public int Setup() { return 0; }
278 	}
279 
280 	[TestFixture]
281 	public class SetUpWithParameters : OneTestBase
282 	{
283 		[SetUp]
Setup(int j)284 		public void Setup(int j) { }
285 	}
286 
287 	[TestFixture]
288 	public class PrivateTearDown : OneTestBase
289 	{
290 		[TearDown]
Teardown()291 		private void Teardown()	{}
292 	}
293 
294 	[TestFixture]
295 	public class ProtectedTearDown : OneTestBase
296 	{
297 		[TearDown]
Teardown()298 		protected void Teardown()	{}
299 	}
300 
301 	[TestFixture]
302 	public class StaticTearDown : OneTestBase
303 	{
304 		[SetUp]
TearDown()305 		public static void TearDown() {}
306 	}
307 
308 	[TestFixture]
309 	public class TearDownWithReturnValue : OneTestBase
310 	{
311 		[TearDown]
Teardown()312 		public int Teardown() { return 0; }
313 	}
314 
315 	[TestFixture]
316 	public class TearDownWithParameters : OneTestBase
317 	{
318 		[TearDown]
Teardown(int j)319 		public void Teardown(int j) { }
320 	}
321 
322 	[TestFixture]
323 	public class PrivateFixtureSetUp : OneTestBase
324 	{
325 		[TestFixtureSetUp]
Setup()326 		private void Setup()	{}
327 	}
328 
329 	[TestFixture]
330 	public class ProtectedFixtureSetUp : OneTestBase
331 	{
332 		[TestFixtureSetUp]
Setup()333 		protected void Setup()	{}
334 	}
335 
336 	[TestFixture]
337 	public class StaticFixtureSetUp : OneTestBase
338 	{
339 		[TestFixtureSetUp]
Setup()340 		public static void Setup() {}
341 	}
342 
343 	[TestFixture]
344 	public class FixtureSetUpWithReturnValue : OneTestBase
345 	{
346 		[TestFixtureSetUp]
Setup()347 		public int Setup() { return 0; }
348 	}
349 
350 	[TestFixture]
351 	public class FixtureSetUpWithParameters : OneTestBase
352 	{
353 		[SetUp]
Setup(int j)354 		public void Setup(int j) { }
355 	}
356 
357 	[TestFixture]
358 	public class PrivateFixtureTearDown : OneTestBase
359 	{
360 		[TestFixtureTearDown]
Teardown()361 		private void Teardown()	{}
362 	}
363 
364 	[TestFixture]
365 	public class ProtectedFixtureTearDown : OneTestBase
366 	{
367 		[TestFixtureTearDown]
Teardown()368 		protected void Teardown()	{}
369 	}
370 
371 	[TestFixture]
372 	public class StaticFixtureTearDown : OneTestBase
373 	{
374 		[TestFixtureTearDown]
Teardown()375 		public static void Teardown() {}
376 	}
377 
378 	[TestFixture]
379 	public class FixtureTearDownWithReturnValue : OneTestBase
380 	{
381 		[TestFixtureTearDown]
Teardown()382 		public int Teardown() { return 0; }
383 	}
384 
385 	[TestFixture]
386 	public class FixtureTearDownWithParameters : OneTestBase
387 	{
388 		[TestFixtureTearDown]
Teardown(int j)389 		public void Teardown(int j) { }
390 	}
391 
392 #if !NETCF && !SILVERLIGHT
393     [TestFixture]
394     public class FixtureThatChangesTheCurrentPrincipal
395     {
396         [Test]
ChangeCurrentPrincipal()397         public void ChangeCurrentPrincipal()
398         {
399             WindowsIdentity identity = WindowsIdentity.GetCurrent();
400             GenericPrincipal principal = new GenericPrincipal( identity, new string[] { } );
401             System.Threading.Thread.CurrentPrincipal = principal;
402         }
403     }
404 #endif
405 
406 #if CLR_2_0 || CLR_4_0
407 #if !NETCF
408     [TestFixture(typeof(int))]
409     [TestFixture(typeof(string))]
410     public class GenericFixtureWithProperArgsProvided<T>
411     {
412         [Test]
SomeTest()413         public void SomeTest() { }
414     }
415 
416     public class GenericFixtureWithNoTestFixtureAttribute<T>
417     {
418         [Test]
SomeTest()419         public void SomeTest() { }
420     }
421 
422     [TestFixture]
423     public class GenericFixtureWithNoArgsProvided<T>
424     {
425         [Test]
SomeTest()426         public void SomeTest() { }
427     }
428 
429     [TestFixture]
430     public abstract class AbstractFixtureBase
431     {
432         [Test]
SomeTest()433         public void SomeTest() { }
434     }
435 
436     public class GenericFixtureDerivedFromAbstractFixtureWithNoArgsProvided<T> : AbstractFixtureBase
437     {
438     }
439 
440     [TestFixture(typeof(int))]
441     [TestFixture(typeof(string))]
442     public class GenericFixtureDerivedFromAbstractFixtureWithArgsProvided<T> : AbstractFixtureBase
443     {
444     }
445 #endif
446 #endif
447 }
448