36
44
#region Constructors
39
/// Construct a TestController using default runner and builder
47
/// Construct a TestController using the default builder and runner.
41
49
public TestController()
43
if (!NUnit.Core.CoreExtensions.Host.Initialized)
44
NUnit.Core.CoreExtensions.Host.Initialize();
51
if (!CoreExtensions.Host.Initialized)
52
CoreExtensions.Host.Initialize();
54
// TODO: This should be taken from constructor options
55
InternalTrace.Level = InternalTrace.TraceLevel.Debug;
56
InternalTrace.Open("InternalTrace.txt");
46
58
this.builder = new DefaultTestAssemblyBuilder();
47
59
this.runner = new DefaultTestAssemblyRunner(this.builder);
51
63
/// Construct a TestController, specifying the types to be used
114
133
protected TestControllerAction(TestController controller, AsyncCallback callback)
116
135
this.controller = controller;
117
this.runner = controller.Runner;
118
136
this.callback = callback;
124
/// <value>The runner.</value>
125
protected ITestAssemblyRunner Runner
127
get { return this.runner; }
131
/// Reports the progress.
133
/// <param name="progress">The progress.</param>
134
public void ReportProgress(object progress)
136
callback(new ProgressReport(progress));
140
140
/// Reports the result.
142
142
/// <param name="result">The result.</param>
143
143
/// <param name="synchronous">if set to <c>true</c> [synchronous].</param>
144
public void ReportResult(object result, bool synchronous)
144
protected void ReportResult(object result, bool synchronous)
146
146
callback(new FinalResult(result, synchronous));
170
170
/// <param name="controller">The controller.</param>
171
171
/// <param name="assemblyFilename">The assembly filename.</param>
172
/// <param name="loadOptions">Options controlling how the tests are loaded</param>
172
173
/// <param name="callback">The callback.</param>
173
public LoadTestsAction(TestController controller, string assemblyFilename, AsyncCallback callback)
174
public LoadTestsAction(TestController controller, string assemblyFilename, IDictionary loadOptions, AsyncCallback callback)
174
175
: base(controller, callback)
176
ReportResult(Runner.Load(assemblyFilename), true);
177
ReportResult(controller.Runner.Load(assemblyFilename, loadOptions), true);
185
186
/// CountTestsAction counts the number of test cases in the loaded TestSuite
186
187
/// held by the TestController.
188
public class CountTestsAction : TestControllerAction
191
/// Construct a CountsTestAction and perform the count of test cases.
193
/// <param name="controller">A TestController holding the TestSuite whose cases are to be counted</param>
194
/// <param name="callback">An AsyncCallback for reporting the count</param>
195
public CountTestsAction(TestController controller, AsyncCallback callback)
196
: base(controller, callback)
198
ReportResult(Runner.CountTestCases(NUnit.Core.TestFilter.Empty), true);
189
//public class CountTestsAction : TestControllerAction
192
// /// Construct a CountsTestAction and perform the count of test cases.
194
// /// <param name="controller">A TestController holding the TestSuite whose cases are to be counted</param>
195
// /// <param name="callback">An AsyncCallback for reporting the count</param>
196
// public CountTestsAction(TestController controller, AsyncCallback callback)
197
// : base(controller, callback)
199
// ReportResult(Runner.CountTestCases(TestFilter.Empty), true);
216
217
public RunTestsAction(TestController controller, AsyncCallback callback)
217
218
: base(controller, callback)
219
ReportResult(Runner.Run(this, NUnit.Core.TestFilter.Empty), true);
223
/// Construct a RunTestsAction and run tests in the loaded TestSuite that pass the supplied filter
225
/// <param name="controller">A TestController holding the TestSuite to run</param>
226
/// <param name="filter">A TestFilter used to determine which tests should be run</param>
227
/// <param name="result">A callback used to report results</param>
228
public RunTestsAction(TestController controller, NUnit.Core.TestFilter filter, AsyncCallback callback)
229
: base(controller, callback)
231
ReportResult(Runner.Run(this, filter), true);
234
#region ITestListener Members
236
public void RunStarted(NUnit.Core.TestName testName, int testCount)
240
public void RunFinished(NUnit.Core.TestResult result)
244
public void RunFinished(Exception exception)
248
public void TestStarted(NUnit.Core.TestName testName)
252
public void TestFinished(NUnit.Core.TestResult result)
256
public void SuiteStarted(NUnit.Core.TestName testName)
260
public void SuiteFinished(NUnit.Core.TestResult result)
264
public void UnhandledException(Exception exception)
268
public void TestOutput(NUnit.Core.TestOutput testOutput)
270
ReportProgress(testOutput);
280
#region Nested Classes for use with Callbacks
283
/// AsyncResult is the abstract base for all callback classes
284
/// used with the framework.
287
public abstract class AsyncResult : IAsyncResult
289
private object state;
290
private bool synchronous;
291
private bool isCompleted;
294
/// Initializes a new instance of the <see cref="AsyncResult"/> class.
296
/// <param name="state">The state of the result.</param>
297
/// <param name="isCompleted">if set to <c>true</c> [is completed].</param>
298
/// <param name="synchronous">if set to <c>true</c> [synchronous].</param>
299
public AsyncResult(object state, bool isCompleted, bool synchronous)
302
this.isCompleted = isCompleted;
303
this.synchronous = synchronous;
306
#region IAsyncResult Members
309
/// Gets the result of an operation.
312
/// <returns>The result state.</returns>
313
public object AsyncState
315
get { return state; }
319
/// Gets a <see cref="T:System.Threading.WaitHandle"/> that is used to wait for an asynchronous operation to complete.
321
/// <returns>A WaitHandle</returns>
322
public System.Threading.WaitHandle AsyncWaitHandle
324
get { throw new NotImplementedException(); }
328
/// Gets a value that indicates whether the asynchronous operation completed synchronously.
330
/// <returns>true if the operation completed synchronously; otherwise, false.
332
public bool CompletedSynchronously
334
get { return synchronous; }
337
public bool IsCompleted
339
get { return isCompleted; }
346
public class FinalResult : AsyncResult
348
public FinalResult(object state, bool synchronous) : base(state, true, synchronous) { }
352
public class ProgressReport : AsyncResult
354
public ProgressReport(object report) : base(report, false, false) { }
220
ITestResult result = controller.Runner.Run(new TestProgressReporter(callback));
221
ReportResult(result.ToXml(true), true);
225
///// Construct a RunTestsAction and run tests in the loaded TestSuite that pass the supplied filter
227
///// <param name="controller">A TestController holding the TestSuite to run</param>
228
///// <param name="filter">A TestFilter used to determine which tests should be run</param>
229
///// <param name="result">A callback used to report results</param>
230
//public RunTestsAction(TestController controller, TestFilter filter, AsyncCallback callback)
231
// : base(controller, callback)
233
// ReportResult(Runner.Run(this, filter), true);