PageRenderTime 92ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/ProxyTestRunner.cs

#
C# | 183 lines | 116 code | 27 blank | 40 comment | 10 complexity | 42a9c4c971c60dd1eb165877bd22cb45 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You
  3. // may obtain a copy of the license as well as information regarding
  4. // copyright ownership at http://nunit.org.
  5. // ****************************************************************
  6. namespace NUnit.Core
  7. {
  8. using System;
  9. using System.Collections;
  10. using System.IO;
  11. /// <summary>
  12. /// DelegatingTestRUnner is the abstract base for core TestRunner
  13. /// implementations that operate by controlling a downstream
  14. /// TestRunner. All calls are simply passed on to the
  15. /// TestRunner that is provided to the constructor.
  16. ///
  17. /// Although the class is abstract, it has no abstract
  18. /// methods specified because each implementation will
  19. /// need to override different methods. All methods are
  20. /// specified using interface syntax and the derived class
  21. /// must explicitly implement TestRunner in order to
  22. /// redefine the selected methods.
  23. /// </summary>
  24. public abstract class ProxyTestRunner : MarshalByRefObject, TestRunner
  25. {
  26. #region Instance Variables
  27. /// <summary>
  28. /// Our runner ID
  29. /// </summary>
  30. protected int runnerID;
  31. /// <summary>
  32. /// The downstream TestRunner
  33. /// </summary>
  34. private TestRunner testRunner;
  35. /// <summary>
  36. /// The event listener for the currently running test
  37. /// </summary>
  38. protected EventListener listener;
  39. #endregion
  40. #region Construction
  41. public ProxyTestRunner(TestRunner testRunner)
  42. {
  43. this.testRunner = testRunner;
  44. this.runnerID = testRunner.ID;
  45. }
  46. /// <summary>
  47. /// Protected constructor for runners that delay creation
  48. /// of their downstream runner.
  49. /// </summary>
  50. protected ProxyTestRunner( int runnerID )
  51. {
  52. this.runnerID = runnerID;
  53. }
  54. #endregion
  55. #region Properties
  56. public virtual int ID
  57. {
  58. get { return runnerID; }
  59. }
  60. public virtual bool Running
  61. {
  62. get { return testRunner != null && testRunner.Running; }
  63. }
  64. public virtual IList AssemblyInfo
  65. {
  66. get { return testRunner == null ? null : testRunner.AssemblyInfo; }
  67. }
  68. public virtual ITest Test
  69. {
  70. get { return testRunner == null ? null : testRunner.Test; }
  71. }
  72. public virtual TestResult TestResult
  73. {
  74. get { return testRunner == null ? null : testRunner.TestResult; }
  75. }
  76. /// <summary>
  77. /// Protected property copies any settings to the downstream test runner
  78. /// when it is set. Derived runners overriding this should call the base
  79. /// or copy the settings themselves.
  80. /// </summary>
  81. protected virtual TestRunner TestRunner
  82. {
  83. get { return testRunner; }
  84. set { testRunner = value; }
  85. }
  86. #endregion
  87. #region Load and Unload Methods
  88. public virtual bool Load( TestPackage package )
  89. {
  90. return this.testRunner.Load( package );
  91. }
  92. public virtual void Unload()
  93. {
  94. if ( this.testRunner != null )
  95. this.testRunner.Unload();
  96. }
  97. #endregion
  98. #region CountTestCases
  99. public virtual int CountTestCases( ITestFilter filter )
  100. {
  101. return this.testRunner.CountTestCases( filter );
  102. }
  103. #endregion
  104. #region Methods for Running Tests
  105. public virtual TestResult Run(EventListener listener)
  106. {
  107. // Save active listener for derived classes
  108. this.listener = listener;
  109. return this.testRunner.Run(listener);
  110. }
  111. public virtual TestResult Run(EventListener listener, ITestFilter filter)
  112. {
  113. // Save active listener for derived classes
  114. this.listener = listener;
  115. return this.testRunner.Run(listener, filter);
  116. }
  117. public virtual void BeginRun( EventListener listener )
  118. {
  119. // Save active listener for derived classes
  120. this.listener = listener;
  121. this.testRunner.BeginRun( listener );
  122. }
  123. public virtual void BeginRun( EventListener listener, ITestFilter filter )
  124. {
  125. // Save active listener for derived classes
  126. this.listener = listener;
  127. this.testRunner.BeginRun( listener, filter );
  128. }
  129. public virtual TestResult EndRun()
  130. {
  131. return this.testRunner.EndRun();
  132. }
  133. public virtual void CancelRun()
  134. {
  135. this.testRunner.CancelRun();
  136. }
  137. public virtual void Wait()
  138. {
  139. this.testRunner.Wait();
  140. }
  141. #endregion
  142. #region InitializeLifetimeService Override
  143. public override object InitializeLifetimeService()
  144. {
  145. return null;
  146. }
  147. #endregion
  148. #region IDisposable Implementation
  149. public virtual void Dispose()
  150. {
  151. if (testRunner != null)
  152. testRunner.Dispose();
  153. }
  154. #endregion
  155. }
  156. }