PageRenderTime 36ms CodeModel.GetById 15ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/src/NUnit/core/ProxyTestRunner.cs

#
C# | 183 lines | 116 code | 27 blank | 40 comment | 10 complexity | 42a9c4c971c60dd1eb165877bd22cb45 MD5 | raw file
  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// ****************************************************************
  6namespace NUnit.Core
  7{
  8	using System;
  9	using System.Collections;
 10	using System.IO;
 11
 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
 26	{
 27		#region Instance Variables
 28
 29		/// <summary>
 30		/// Our runner ID
 31		/// </summary>
 32		protected int runnerID;
 33
 34		/// <summary>
 35		/// The downstream TestRunner
 36		/// </summary>
 37		private TestRunner testRunner;
 38
 39		/// <summary>
 40		/// The event listener for the currently running test
 41		/// </summary>
 42		protected EventListener listener;
 43
 44		#endregion
 45
 46		#region Construction
 47		public ProxyTestRunner(TestRunner testRunner)
 48		{
 49			this.testRunner = testRunner;
 50			this.runnerID = testRunner.ID;
 51		}
 52
 53		/// <summary>
 54		/// Protected constructor for runners that delay creation
 55		/// of their downstream runner.
 56		/// </summary>
 57		protected ProxyTestRunner( int runnerID )
 58		{
 59			this.runnerID = runnerID;
 60		}
 61		#endregion
 62
 63		#region Properties
 64		public virtual int ID
 65		{
 66			get { return runnerID; }
 67		}
 68
 69		public virtual bool Running
 70		{
 71			get { return testRunner != null && testRunner.Running; }
 72		}
 73
 74		public virtual IList AssemblyInfo
 75		{
 76			get { return testRunner == null ? null : testRunner.AssemblyInfo; }
 77		}
 78
 79		public virtual ITest Test
 80		{
 81			get { return testRunner == null ? null : testRunner.Test; }
 82		}
 83
 84		public virtual TestResult TestResult
 85		{
 86			get { return testRunner == null ? null : testRunner.TestResult; }
 87		}
 88
 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
 95		{
 96			get { return testRunner; }
 97			set { testRunner = value; }
 98		}
 99		#endregion
100
101		#region Load and Unload Methods
102		public virtual bool Load( TestPackage package )
103		{
104			return this.testRunner.Load( package );
105		}
106
107		public virtual void Unload()
108		{
109            if ( this.testRunner != null )
110			    this.testRunner.Unload();
111		}
112		#endregion
113
114		#region CountTestCases
115		public virtual int CountTestCases( ITestFilter filter )
116		{
117			return this.testRunner.CountTestCases( filter );
118		}
119		#endregion
120
121		#region Methods for Running Tests
122		public virtual TestResult Run(EventListener listener)
123		{
124			// Save active listener for derived classes
125			this.listener = listener;
126			return this.testRunner.Run(listener);
127		}
128
129		public virtual TestResult Run(EventListener listener, ITestFilter filter)
130		{
131			// Save active listener for derived classes
132			this.listener = listener;
133			return this.testRunner.Run(listener, filter);
134		}
135
136		public virtual void BeginRun( EventListener listener )
137		{
138			// Save active listener for derived classes
139			this.listener = listener;
140			this.testRunner.BeginRun( listener );
141		}
142
143		public virtual void BeginRun( EventListener listener, ITestFilter filter )
144		{
145			// Save active listener for derived classes
146			this.listener = listener;
147			this.testRunner.BeginRun( listener, filter );
148		}
149
150		public virtual TestResult EndRun()
151		{
152			return this.testRunner.EndRun();
153		}
154
155		public virtual void CancelRun()
156		{
157			this.testRunner.CancelRun();
158		}
159
160		public virtual void Wait()
161		{
162			this.testRunner.Wait();
163		}
164		#endregion
165
166		#region InitializeLifetimeService Override
167		public override object InitializeLifetimeService()
168		{
169			return null;
170		}
171		#endregion
172
173        #region IDisposable Implementation
174
175        public virtual void Dispose()
176        {
177            if (testRunner != null)
178                testRunner.Dispose();
179        }
180
181        #endregion
182    }
183}