Add test, fix regression
[mono.git] / mcs / nunit20 / core / TestEventDispatcher.cs
1 using System;
2
3 namespace NUnit.Core
4 {
5         /// <summary>
6         /// Helper class used by runner to dispatch test events
7         /// </summary>
8         public class TestEventDispatcher : ITestEvents
9         {
10                 #region Events
11
12                 // Test loading events
13                 public event TestEventHandler TestLoading;      
14                 public event TestEventHandler TestLoaded;       
15                 public event TestEventHandler TestLoadFailed;
16
17                 public event TestEventHandler TestReloading;
18                 public event TestEventHandler TestReloaded;
19                 public event TestEventHandler TestReloadFailed;
20
21                 public event TestEventHandler TestUnloading;
22                 public event TestEventHandler TestUnloaded;
23                 public event TestEventHandler TestUnloadFailed;
24
25                 // Test running events
26                 public event TestEventHandler RunStarting;      
27                 public event TestEventHandler RunFinished;
28                 
29                 public event TestEventHandler SuiteStarting;
30                 public event TestEventHandler SuiteFinished;
31
32                 public event TestEventHandler TestStarting;
33                 public event TestEventHandler TestFinished;
34
35                 public event TestEventHandler TestException;
36
37                 #endregion
38
39                 #region Methods for Firing Events
40                 
41                 private void Fire( 
42                         TestEventHandler handler, TestEventArgs e )
43                 {
44                         if ( handler != null )
45                                 handler( this, e );
46                 }
47
48                 public void FireTestLoading( string fileName )
49                 {
50                         Fire( 
51                                 TestLoading,
52                                 new TestEventArgs( TestAction.TestLoading, fileName ) );
53                 }
54
55                 public void FireTestLoaded( string fileName, Test test )
56                 {
57                         Fire( 
58                                 TestLoaded,
59                                 new TestEventArgs( TestAction.TestLoaded, fileName, test ) );
60                 }
61
62                 public void FireTestLoadFailed( string fileName, Exception exception )
63                 {
64                         Fire(
65                                 TestLoadFailed,
66                                 new TestEventArgs( TestAction.TestLoadFailed, fileName, exception ) );
67                 }
68
69                 public void FireTestUnloading( string fileName, Test test )
70                 {
71                         Fire(
72                                 TestUnloading,
73                                 new TestEventArgs( TestAction.TestUnloading, fileName, test ) );
74                 }
75
76                 public void FireTestUnloaded( string fileName, Test test )
77                 {
78                         Fire(
79                                 TestUnloaded,
80                                 new TestEventArgs( TestAction.TestUnloaded, fileName, test ) );
81                 }
82
83                 public void FireTestUnloadFailed( string fileName, Exception exception )
84                 {
85                         Fire(
86                                 TestUnloadFailed, 
87                                 new TestEventArgs( TestAction.TestUnloadFailed, fileName, exception ) );
88                 }
89
90                 public void FireTestReloading( string fileName, Test test )
91                 {
92                         Fire(
93                                 TestReloading,
94                                 new TestEventArgs( TestAction.TestReloading, fileName, test ) );
95                 }
96
97                 public void FireTestReloaded( string fileName, Test test )
98                 {
99                         Fire(
100                                 TestReloaded,
101                                 new TestEventArgs( TestAction.TestReloaded, fileName, test ) );
102                 }
103
104                 public void FireTestReloadFailed( string fileName, Exception exception )
105                 {
106                         Fire(
107                                 TestReloadFailed, 
108                                 new TestEventArgs( TestAction.TestReloadFailed, fileName, exception ) );
109                 }
110
111                 public void FireRunStarting( Test[] tests, int count )
112                 {
113                         Fire(
114                                 RunStarting,
115                                 new TestEventArgs( TestAction.RunStarting, tests, count ) );
116                 }
117
118                 public void FireRunFinished( TestResult[] results )
119                 {       
120                         Fire(
121                                 RunFinished,
122                                 new TestEventArgs( TestAction.RunFinished, results ) );
123                 }
124
125                 public void FireRunFinished( Exception exception )
126                 {
127                         Fire(
128                                 RunFinished,
129                                 new TestEventArgs( TestAction.RunFinished, exception ) );
130                 }
131
132                 public void FireTestStarting( Test test )
133                 {
134                         Fire(
135                                 TestStarting,
136                                 new TestEventArgs( TestAction.TestStarting, test ) );
137                 }
138
139                 public void FireTestFinished( TestResult result )
140                 {       
141                         Fire(
142                                 TestFinished,
143                                 new TestEventArgs( TestAction.TestFinished, result ) );
144                 }
145
146                 public void FireSuiteStarting( Test test )
147                 {
148                         Fire(
149                                 SuiteStarting,
150                                 new TestEventArgs( TestAction.SuiteStarting, test ) );
151                 }
152
153                 public void FireSuiteFinished( TestResult result )
154                 {       
155                         Fire(
156                                 SuiteFinished,
157                                 new TestEventArgs( TestAction.SuiteFinished, result ) );
158                 }
159
160                 public void FireTestException( Exception exception )
161                 {
162                         Fire(
163                                 TestException,
164                                 new TestEventArgs( TestAction.TestException, exception ) );
165                 }
166
167                 #endregion
168         }
169 }