2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / nunit24 / NUnitCore / core / ProxyTestRunner.cs
blobe171aa61f639d4c4c417b83d2fd5e54a510af039
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/?p=license&r=2.4.
5 // ****************************************************************
6 namespace NUnit.Core
8 using System;
9 using System.Collections;
10 using System.IO;
12 /// <summary>
13 /// DelegatingTestRUnner is the abstract base for core TestRunner
14 /// implementations that operate by controlling a downstream
15 /// TestRunner. All calls are simply passed on to the
16 /// TestRunner that is provided to the constructor.
17 ///
18 /// Although the class is abstract, it has no abstract
19 /// methods specified because each implementation will
20 /// need to override different methods. All methods are
21 /// specified using interface syntax and the derived class
22 /// must explicitly implement TestRunner in order to
23 /// redefine the selected methods.
24 /// </summary>
25 public abstract class ProxyTestRunner : MarshalByRefObject, TestRunner
27 #region Instance Variables
29 /// <summary>
30 /// Our runner ID
31 /// </summary>
32 protected int runnerID;
34 /// <summary>
35 /// The downstream TestRunner
36 /// </summary>
37 private TestRunner testRunner;
39 /// <summary>
40 /// The event listener for the currently running test
41 /// </summary>
42 protected EventListener listener;
44 #endregion
46 #region Construction
47 public ProxyTestRunner(TestRunner testRunner)
49 this.testRunner = testRunner;
50 this.runnerID = testRunner.ID;
53 /// <summary>
54 /// Protected constructor for runners that delay creation
55 /// of their downstream runner.
56 /// </summary>
57 protected ProxyTestRunner( int runnerID )
59 this.runnerID = runnerID;
61 #endregion
63 #region Properties
64 public virtual int ID
66 get { return runnerID; }
69 public virtual bool Running
71 get { return testRunner != null && testRunner.Running; }
74 public virtual IList AssemblyInfo
76 get { return testRunner == null ? null : testRunner.AssemblyInfo; }
79 public virtual ITest Test
81 get { return testRunner == null ? null : testRunner.Test; }
84 public virtual TestResult TestResult
86 get { return testRunner == null ? null : testRunner.TestResult; }
89 /// <summary>
90 /// Protected property copies any settings to the downstream test runner
91 /// when it is set. Derived runners overriding this should call the base
92 /// or copy the settings themselves.
93 /// </summary>
94 protected virtual TestRunner TestRunner
96 get { return testRunner; }
97 set { testRunner = value; }
99 #endregion
101 #region Load and Unload Methods
102 public virtual bool Load( TestPackage package )
104 return this.testRunner.Load( package );
107 public virtual void Unload()
109 if ( this.testRunner != null )
110 this.testRunner.Unload();
112 #endregion
114 #region CountTestCases
115 public virtual int CountTestCases( ITestFilter filter )
117 return this.testRunner.CountTestCases( filter );
119 #endregion
121 #region Methods for Running Tests
122 public virtual TestResult Run(EventListener listener)
124 // Save active listener for derived classes
125 this.listener = listener;
126 return this.testRunner.Run(listener);
129 public virtual TestResult Run(EventListener listener, ITestFilter filter)
131 // Save active listener for derived classes
132 this.listener = listener;
133 return this.testRunner.Run(listener, filter);
136 public virtual void BeginRun( EventListener listener )
138 // Save active listener for derived classes
139 this.listener = listener;
140 this.testRunner.BeginRun( listener );
143 public virtual void BeginRun( EventListener listener, ITestFilter filter )
145 // Save active listener for derived classes
146 this.listener = listener;
147 this.testRunner.BeginRun( listener, filter );
150 public virtual TestResult EndRun()
152 return this.testRunner.EndRun();
155 public virtual void CancelRun()
157 this.testRunner.CancelRun();
160 public virtual void Wait()
162 this.testRunner.Wait();
164 #endregion
166 #region InitializeLifetimeService Override
167 public override object InitializeLifetimeService()
169 return null;
171 #endregion