PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/TestEventDispatcher.cs

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