/src/NUnit/util/TestEventDispatcher.cs
C# | 234 lines | 185 code | 38 blank | 11 comment | 3 complexity | a33ec41bfc8622ffb57c6f54084255a9 MD5 | raw file
1// **************************************************************** 2// Copyright 2002-2003, 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 5// **************************************************************** 6 7using System; 8using System.Collections; 9using NUnit.Core; 10 11namespace NUnit.Util 12{ 13 /// <summary> 14 /// Helper class used to dispatch test events 15 /// </summary> 16 public class TestEventDispatcher : ITestEvents 17 { 18 #region Events 19 20 // Project loading events 21 public event TestEventHandler ProjectLoading; 22 public event TestEventHandler ProjectLoaded; 23 public event TestEventHandler ProjectLoadFailed; 24 public event TestEventHandler ProjectUnloading; 25 public event TestEventHandler ProjectUnloaded; 26 public event TestEventHandler ProjectUnloadFailed; 27 28 // Test loading events 29 public event TestEventHandler TestLoading; 30 public event TestEventHandler TestLoaded; 31 public event TestEventHandler TestLoadFailed; 32 33 public event TestEventHandler TestReloading; 34 public event TestEventHandler TestReloaded; 35 public event TestEventHandler TestReloadFailed; 36 37 public event TestEventHandler TestUnloading; 38 public event TestEventHandler TestUnloaded; 39 public event TestEventHandler TestUnloadFailed; 40 41 // Test running events 42 public event TestEventHandler RunStarting; 43 public event TestEventHandler RunFinished; 44 45 public event TestEventHandler SuiteStarting; 46 public event TestEventHandler SuiteFinished; 47 48 public event TestEventHandler TestStarting; 49 public event TestEventHandler TestFinished; 50 51 public event TestEventHandler TestException; 52 public event TestEventHandler TestOutput; 53 54 #endregion 55 56 #region Methods for Firing Events 57 58 protected virtual void Fire( TestEventHandler handler, TestEventArgs e ) 59 { 60 if ( handler != null ) 61 handler( this, e ); 62 } 63 64 public void FireProjectLoading( string fileName ) 65 { 66 Fire( 67 ProjectLoading, 68 new TestEventArgs( TestAction.ProjectLoading, fileName ) ); 69 } 70 71 public void FireProjectLoaded( string fileName ) 72 { 73 Fire( 74 ProjectLoaded, 75 new TestEventArgs( TestAction.ProjectLoaded, fileName ) ); 76 } 77 78 public void FireProjectLoadFailed( string fileName, Exception exception ) 79 { 80 Fire( 81 ProjectLoadFailed, 82 new TestEventArgs( TestAction.ProjectLoadFailed, fileName, exception ) ); 83 } 84 85 public void FireProjectUnloading( string fileName ) 86 { 87 Fire( 88 ProjectUnloading, 89 new TestEventArgs( TestAction.ProjectUnloading, fileName ) ); 90 } 91 92 public void FireProjectUnloaded( string fileName ) 93 { 94 Fire( 95 ProjectUnloaded, 96 new TestEventArgs( TestAction.ProjectUnloaded, fileName ) ); 97 } 98 99 public void FireProjectUnloadFailed( string fileName, Exception exception ) 100 { 101 Fire( 102 ProjectUnloadFailed, 103 new TestEventArgs( TestAction.ProjectUnloadFailed, fileName, exception ) ); 104 } 105 106 public void FireTestLoading( string fileName ) 107 { 108 Fire( 109 TestLoading, 110 new TestEventArgs( TestAction.TestLoading, fileName ) ); 111 } 112 113 public void FireTestLoaded( string fileName, ITest test ) 114 { 115 Fire( 116 TestLoaded, 117 new TestEventArgs( TestAction.TestLoaded, fileName, test ) ); 118 } 119 120 public void FireTestLoadFailed( string fileName, Exception exception ) 121 { 122 Fire( 123 TestLoadFailed, 124 new TestEventArgs( TestAction.TestLoadFailed, fileName, exception ) ); 125 } 126 127 public void FireTestUnloading( string fileName ) 128 { 129 Fire( 130 TestUnloading, 131 new TestEventArgs( TestAction.TestUnloading, fileName ) ); 132 } 133 134 public void FireTestUnloaded( string fileName ) 135 { 136 Fire( 137 TestUnloaded, 138 new TestEventArgs( TestAction.TestUnloaded, fileName ) ); 139 } 140 141 public void FireTestUnloadFailed( string fileName, Exception exception ) 142 { 143 Fire( 144 TestUnloadFailed, 145 new TestEventArgs( TestAction.TestUnloadFailed, fileName, exception ) ); 146 } 147 148 public void FireTestReloading( string fileName ) 149 { 150 Fire( 151 TestReloading, 152 new TestEventArgs( TestAction.TestReloading, fileName ) ); 153 } 154 155 public void FireTestReloaded( string fileName, ITest test ) 156 { 157 Fire( 158 TestReloaded, 159 new TestEventArgs( TestAction.TestReloaded, fileName, test ) ); 160 } 161 162 public void FireTestReloadFailed( string fileName, Exception exception ) 163 { 164 Fire( 165 TestReloadFailed, 166 new TestEventArgs( TestAction.TestReloadFailed, fileName, exception ) ); 167 } 168 169 public void FireRunStarting( string name, int testCount ) 170 { 171 Fire( 172 RunStarting, 173 new TestEventArgs( TestAction.RunStarting, name, testCount ) ); 174 } 175 176 public void FireRunFinished( TestResult result ) 177 { 178 Fire( 179 RunFinished, 180 new TestEventArgs( TestAction.RunFinished, result ) ); 181 } 182 183 public void FireRunFinished( Exception exception ) 184 { 185 Fire( 186 RunFinished, 187 new TestEventArgs( TestAction.RunFinished, exception ) ); 188 } 189 190 public void FireTestStarting( TestName testName ) 191 { 192 Fire( 193 TestStarting, 194 new TestEventArgs( TestAction.TestStarting, testName ) ); 195 } 196 197 public void FireTestFinished( TestResult result ) 198 { 199 Fire( 200 TestFinished, 201 new TestEventArgs( TestAction.TestFinished, result ) ); 202 } 203 204 public void FireSuiteStarting( TestName testName ) 205 { 206 Fire( 207 SuiteStarting, 208 new TestEventArgs( TestAction.SuiteStarting, testName ) ); 209 } 210 211 public void FireSuiteFinished( TestResult result ) 212 { 213 Fire( 214 SuiteFinished, 215 new TestEventArgs( TestAction.SuiteFinished, result ) ); 216 } 217 218 public void FireTestException( string name, Exception exception ) 219 { 220 Fire( 221 TestException, 222 new TestEventArgs( TestAction.TestException, name, exception ) ); 223 } 224 225 public void FireTestOutput( TestOutput testOutput ) 226 { 227 Fire( 228 TestOutput, 229 new TestEventArgs( TestAction.TestOutput, testOutput ) ); 230 } 231 232 #endregion 233 } 234}