1 // ****************************************************************
\r
2 // Copyright 2007, Charlie Poole
\r
3 // This is free software licensed under the NUnit license. You may
\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
\r
5 // ****************************************************************
\r
7 using System.Collections;
\r
8 using System.Threading;
\r
10 namespace NUnit.Core
\r
12 #region Individual Event Classes
\r
15 /// NUnit.Core.Event is the abstract base for all stored events.
\r
16 /// An Event is the stored representation of a call to the
\r
17 /// EventListener interface and is used to record such calls
\r
18 /// or to queue them for forwarding on another thread or at
\r
21 public abstract class Event
\r
23 abstract public void Send( EventListener listener );
\r
26 public class RunStartedEvent : Event
\r
31 public RunStartedEvent( string name, int testCount )
\r
34 this.testCount = testCount;
\r
37 public override void Send( EventListener listener )
\r
39 listener.RunStarted(name, testCount);
\r
43 public class RunFinishedEvent : Event
\r
46 Exception exception;
\r
48 public RunFinishedEvent( TestResult result )
\r
50 this.result = result;
\r
53 public RunFinishedEvent( Exception exception )
\r
55 this.exception = exception;
\r
58 public override void Send( EventListener listener )
\r
60 if ( this.exception != null )
\r
61 listener.RunFinished( this.exception );
\r
63 listener.RunFinished( this.result );
\r
67 public class TestStartedEvent : Event
\r
71 public TestStartedEvent( TestName testName )
\r
73 this.testName = testName;
\r
76 public override void Send( EventListener listener )
\r
78 listener.TestStarted( this.testName );
\r
82 public class TestFinishedEvent : Event
\r
84 TestCaseResult result;
\r
86 public TestFinishedEvent( TestCaseResult result )
\r
88 this.result = result;
\r
91 public override void Send( EventListener listener )
\r
93 listener.TestFinished( this.result );
\r
97 public class SuiteStartedEvent : Event
\r
101 public SuiteStartedEvent( TestName suiteName )
\r
103 this.suiteName = suiteName;
\r
106 public override void Send( EventListener listener )
\r
108 listener.SuiteStarted( this.suiteName );
\r
112 public class SuiteFinishedEvent : Event
\r
114 TestSuiteResult result;
\r
116 public SuiteFinishedEvent( TestSuiteResult result )
\r
118 this.result = result;
\r
121 public override void Send( EventListener listener )
\r
123 listener.SuiteFinished( this.result );
\r
127 public class UnhandledExceptionEvent : Event
\r
129 Exception exception;
\r
131 public UnhandledExceptionEvent( Exception exception )
\r
133 this.exception = exception;
\r
136 public override void Send( EventListener listener )
\r
138 listener.UnhandledException( this.exception );
\r
142 public class OutputEvent : Event
\r
146 public OutputEvent( TestOutput output )
\r
148 this.output = output;
\r
151 public override void Send( EventListener listener )
\r
153 listener.TestOutput( this.output );
\r
160 /// Implements a queue of work items each of which
\r
161 /// is queued as a WaitCallback.
\r
163 public class EventQueue
\r
165 private Queue queue = new Queue();
\r
173 return this.queue.Count;
\r
178 public void Enqueue( Event e )
\r
182 this.queue.Enqueue( e );
\r
183 Monitor.Pulse( this );
\r
187 public Event Dequeue()
\r
191 return (Event)this.queue.Dequeue();
\r