File: TestEventArgs.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (234 lines) | stat: -rw-r--r-- 5,614 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
// ****************************************************************

using System;
using System.Diagnostics;
using NUnit.Core;

namespace NUnit.Util
{
	#region TestEventHandler delegate

	/// <summary>
	/// The delegates for all events related to running tests
	/// </summary>
	public delegate void TestEventHandler ( object sender, TestEventArgs args );

	#endregion

	#region TestAction enumeration

	/// <summary>
	/// Enumeration used to distiguish test events
	/// </summary>
	public enum TestAction
	{
		// Project Load Events
		ProjectLoading,
		ProjectLoaded,
		ProjectLoadFailed,
		ProjectUnloading,
		ProjectUnloaded,
		ProjectUnloadFailed,
		// Test Load Events
		TestLoading,
		TestLoaded,
		TestLoadFailed,
		TestReloading,
		TestReloaded,
		TestReloadFailed,
		TestUnloading,
		TestUnloaded,
		TestUnloadFailed,
		// Test Run Events
		RunStarting,
		RunFinished,
		SuiteStarting,
		SuiteFinished,
		TestStarting,
		TestFinished,
		TestException,
		TestOutput
}

	#endregion

	/// <summary>
	/// Argument used for all test events
	/// </summary>
	public class TestEventArgs : EventArgs
	{
		#region Instance Variables

		// The action represented by the event
		private TestAction action;

		// The name of the test or other item
		private string name;
		
		// The name of the test we are running
		private ITest test;

		private TestName testName;

		// The results from our tests
		private TestResult testResult;
		
		// The exception causing a failure
		private Exception exception;

		// The test output
		private TestOutput testOutput;

		// The number of tests we are running
		private int testCount;

		#endregion

		#region Constructors

		// TestLoaded, TestReloaded
		public TestEventArgs( TestAction action, 
			string name, ITest test )
		{
			Debug.Assert( 
				action == TestAction.TestLoaded || action == TestAction.TestReloaded,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.name = name;
			this.test = test;
			if ( test != null )
				this.testCount = test.TestCount;
		}

		// ProjectLoading, ProjectLoaded, ProjectUnloading, ProjectUnloaded,
		// TestLoading, TestUnloading, TestUnloaded, TestReloading
		public TestEventArgs( TestAction action, string name )
		{
			Debug.Assert( 
				action == TestAction.ProjectLoading || action == TestAction.ProjectLoaded ||
				action == TestAction.ProjectUnloading || action == TestAction.ProjectUnloaded ||
				action == TestAction.TestLoading || action == TestAction.TestUnloading ||
				action == TestAction.TestUnloaded || action == TestAction.TestReloading,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.name = name;
		}

		public TestEventArgs( TestAction action, string name, int testCount )
		{
			Debug.Assert( action == TestAction.RunStarting,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.name = name;
			this.testCount = testCount;
		}

		// ProjectLoadFailed, ProjectUnloadFailed, TestLoadFailed, TestUnloadFailed, TestReloadFailed, TestException
		public TestEventArgs( TestAction action,
			string name, Exception exception )
		{
			Debug.Assert(
				action == TestAction.ProjectLoadFailed || action == TestAction.ProjectUnloadFailed ||
				action == TestAction.TestLoadFailed || action == TestAction.TestUnloadFailed ||
				action == TestAction.TestReloadFailed || action == TestAction.TestException, 
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.name = name;
			this.exception = exception;
		}

		// TestStarting, SuiteStarting
		public TestEventArgs( TestAction action, TestName testName )
		{
			Debug.Assert( action == TestAction.TestStarting || action == TestAction.SuiteStarting,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.testName = testName;
		}

		// TestFinished, SuiteFinished, RunFinished
		public TestEventArgs( TestAction action, TestResult testResult )
		{
			Debug.Assert( action == TestAction.TestFinished || action == TestAction.SuiteFinished ||
				action == TestAction.RunFinished,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.testResult = testResult;
		}

		// RunFinished
		public TestEventArgs( TestAction action, Exception exception )
		{
			Debug.Assert( action == TestAction.RunFinished,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.exception = exception;
		}

		// TestOutput
		public TestEventArgs( TestAction action, TestOutput testOutput )
		{
			Debug.Assert( action == TestAction.TestOutput,
				"Invalid TestAction argument to TestEventArgs constructor" );

			this.action = action;
			this.testOutput = testOutput;
		}
		#endregion

		#region Properties

		public TestAction Action
		{
			get { return action; }
		}

		public string Name
		{
			get { return name; }
		}

		public ITest Test
		{
			get { return test; }
		}

		public TestName TestName
		{
			get { return testName; }
		}

		public int TestCount 
		{
			get	{ return testCount;	}
		}

		public TestResult Result
		{
			get { return testResult; }
		}

		public Exception Exception
		{
			get { return exception; }
		}

		public TestOutput TestOutput
		{
			get { return testOutput; }
		}

		#endregion
	}
}