Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestSetup.cs « NUnitCore « src « nunit « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9582350401572ee467bc99a117e0f1d57559fe0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace NUnit.Extensions 
{
	using System;
	using NUnit.Framework;
  
	/// <summary>A Decorator to set up and tear down additional fixture state.
	/// </summary><remarks>
	/// Subclass TestSetup and insert it into your tests when you want
	/// to set up additional state once before the tests are run.</remarks>
	public class TestSetup: TestDecorator 
	{
		#region Constructors
		/// <summary>
		/// 
		/// </summary>
		/// <param name="test"></param>
		public TestSetup(ITest test) : base(test) {}
		#endregion

		#region Nested Classes
		/// <summary>
		/// 
		/// </summary>
		protected class ProtectedProtect: IProtectable 
		{
			private readonly TestSetup fTestSetup;
			private readonly TestResult fTestResult;
			/// <summary>
			/// 
			/// </summary>
			/// <param name="testSetup"></param>
			/// <param name="testResult"></param>
			public ProtectedProtect(TestSetup testSetup, TestResult testResult)
			{
				if(testSetup == null)
					throw new ArgumentNullException("testSetup");
				if(testResult == null)
					throw new ArgumentNullException("testResult");
				this.fTestSetup = testSetup;
				this.fTestResult = testResult;
			}
			/// <summary>
			/// 
			/// </summary>
			void IProtectable.Protect() 
			{
				this.fTestSetup.SetUp();
				this.fTestSetup.BasicRun(fTestResult);
				this.fTestSetup.TearDown();
			}
		}
		#endregion

		/// <summary>
		/// 
		/// </summary>
		/// <param name="result"></param>
		public override void Run(TestResult result) 
		{
			IProtectable p = new ProtectedProtect(this, result);
			result.RunProtected(this, p);
		}
		/// <summary>Sets up the fixture. Override to set up additional fixture
		/// state.</summary>
		protected virtual void SetUp() {}
		/// <summary>Tears down the fixture. Override to tear down the additional
		/// fixture state.</summary>
		protected virtual void TearDown() {}
	}
}