retag
[mcs.git] / nunit24 / ClientUtilities / util / TestEventArgs.cs
blobe2926f0a2d6d6e0867846d4a7ac71d5ee92aac4c
1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
7 using System;
8 using System.Diagnostics;
9 using NUnit.Core;
11 namespace NUnit.Util
13 #region TestEventHandler delegate
15 /// <summary>
16 /// The delegates for all events related to running tests
17 /// </summary>
18 public delegate void TestEventHandler ( object sender, TestEventArgs args );
20 #endregion
22 #region TestAction enumeration
24 /// <summary>
25 /// Enumeration used to distiguish test events
26 /// </summary>
27 public enum TestAction
29 // Project Load Events
30 ProjectLoading,
31 ProjectLoaded,
32 ProjectLoadFailed,
33 ProjectUnloading,
34 ProjectUnloaded,
35 ProjectUnloadFailed,
36 // Test Load Events
37 TestLoading,
38 TestLoaded,
39 TestLoadFailed,
40 TestReloading,
41 TestReloaded,
42 TestReloadFailed,
43 TestUnloading,
44 TestUnloaded,
45 TestUnloadFailed,
46 // Test Run Events
47 RunStarting,
48 RunFinished,
49 SuiteStarting,
50 SuiteFinished,
51 TestStarting,
52 TestFinished,
53 TestException,
54 TestOutput
57 #endregion
59 /// <summary>
60 /// Argument used for all test events
61 /// </summary>
62 public class TestEventArgs : EventArgs
64 #region Instance Variables
66 // The action represented by the event
67 private TestAction action;
69 // The name of the test or other item
70 private string name;
72 // The name of the test we are running
73 private ITest test;
75 private TestName testName;
77 // The results from our tests
78 private TestResult testResult;
80 // The exception causing a failure
81 private Exception exception;
83 // The test output
84 private TestOutput testOutput;
86 // The number of tests we are running
87 private int testCount;
89 #endregion
91 #region Constructors
93 // TestLoaded, TestReloaded
94 public TestEventArgs( TestAction action,
95 string name, ITest test )
97 Debug.Assert(
98 action == TestAction.TestLoaded || action == TestAction.TestReloaded,
99 "Invalid TestAction argument to TestEventArgs constructor" );
101 this.action = action;
102 this.name = name;
103 this.test = test;
104 if ( test != null )
105 this.testCount = test.TestCount;
108 // ProjectLoading, ProjectLoaded, ProjectUnloading, ProjectUnloaded,
109 // TestLoading, TestUnloading, TestUnloaded, TestReloading
110 public TestEventArgs( TestAction action, string name )
112 Debug.Assert(
113 action == TestAction.ProjectLoading || action == TestAction.ProjectLoaded ||
114 action == TestAction.ProjectUnloading || action == TestAction.ProjectUnloaded ||
115 action == TestAction.TestLoading || action == TestAction.TestUnloading ||
116 action == TestAction.TestUnloaded || action == TestAction.TestReloading,
117 "Invalid TestAction argument to TestEventArgs constructor" );
119 this.action = action;
120 this.name = name;
123 public TestEventArgs( TestAction action, string name, int testCount )
125 Debug.Assert( action == TestAction.RunStarting,
126 "Invalid TestAction argument to TestEventArgs constructor" );
128 this.action = action;
129 this.name = name;
130 this.testCount = testCount;
133 // ProjectLoadFailed, ProjectUnloadFailed, TestLoadFailed, TestUnloadFailed, TestReloadFailed, TestException
134 public TestEventArgs( TestAction action,
135 string name, Exception exception )
137 Debug.Assert(
138 action == TestAction.ProjectLoadFailed || action == TestAction.ProjectUnloadFailed ||
139 action == TestAction.TestLoadFailed || action == TestAction.TestUnloadFailed ||
140 action == TestAction.TestReloadFailed || action == TestAction.TestException,
141 "Invalid TestAction argument to TestEventArgs constructor" );
143 this.action = action;
144 this.name = name;
145 this.exception = exception;
148 // TestStarting, SuiteStarting
149 public TestEventArgs( TestAction action, TestName testName )
151 Debug.Assert( action == TestAction.TestStarting || action == TestAction.SuiteStarting,
152 "Invalid TestAction argument to TestEventArgs constructor" );
154 this.action = action;
155 this.testName = testName;
158 // TestFinished, SuiteFinished, RunFinished
159 public TestEventArgs( TestAction action, TestResult testResult )
161 Debug.Assert( action == TestAction.TestFinished || action == TestAction.SuiteFinished ||
162 action == TestAction.RunFinished,
163 "Invalid TestAction argument to TestEventArgs constructor" );
165 this.action = action;
166 this.testResult = testResult;
169 // RunFinished
170 public TestEventArgs( TestAction action, Exception exception )
172 Debug.Assert( action == TestAction.RunFinished,
173 "Invalid TestAction argument to TestEventArgs constructor" );
175 this.action = action;
176 this.exception = exception;
179 // TestOutput
180 public TestEventArgs( TestAction action, TestOutput testOutput )
182 Debug.Assert( action == TestAction.TestOutput,
183 "Invalid TestAction argument to TestEventArgs constructor" );
185 this.action = action;
186 this.testOutput = testOutput;
188 #endregion
190 #region Properties
192 public TestAction Action
194 get { return action; }
197 public string Name
199 get { return name; }
202 public ITest Test
204 get { return test; }
207 public TestName TestName
209 get { return testName; }
212 public int TestCount
214 get { return testCount; }
217 public TestResult Result
219 get { return testResult; }
222 public Exception Exception
224 get { return exception; }
227 public TestOutput TestOutput
229 get { return testOutput; }
232 #endregion