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 // ****************************************************************
8 using System
.Diagnostics
;
13 #region TestEventHandler delegate
16 /// The delegates for all events related to running tests
18 public delegate void TestEventHandler ( object sender
, TestEventArgs args
);
22 #region TestAction enumeration
25 /// Enumeration used to distiguish test events
27 public enum TestAction
29 // Project Load Events
60 /// Argument used for all test events
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
72 // The name of the test we are running
75 private TestName testName
;
77 // The results from our tests
78 private TestResult testResult
;
80 // The exception causing a failure
81 private Exception exception
;
84 private TestOutput testOutput
;
86 // The number of tests we are running
87 private int testCount
;
93 // TestLoaded, TestReloaded
94 public TestEventArgs( TestAction action
,
95 string name
, ITest test
)
98 action
== TestAction
.TestLoaded
|| action
== TestAction
.TestReloaded
,
99 "Invalid TestAction argument to TestEventArgs constructor" );
101 this.action
= action
;
105 this.testCount
= test
.TestCount
;
108 // ProjectLoading, ProjectLoaded, ProjectUnloading, ProjectUnloaded,
109 // TestLoading, TestUnloading, TestUnloaded, TestReloading
110 public TestEventArgs( TestAction action
, string name
)
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
;
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
;
130 this.testCount
= testCount
;
133 // ProjectLoadFailed, ProjectUnloadFailed, TestLoadFailed, TestUnloadFailed, TestReloadFailed, TestException
134 public TestEventArgs( TestAction action
,
135 string name
, Exception exception
)
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
;
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
;
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
;
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
;
192 public TestAction Action
194 get { return action; }
207 public TestName TestName
209 get { return testName; }
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; }