retag
[mcs.git] / nunit24 / ClientUtilities / util / TestDomain.cs
blob70101494b2f83cef34c4d0de49c81f3f36cdd25d
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 // ****************************************************************
7 using System;
9 namespace NUnit.Util
11 using System.Diagnostics;
12 using System.Security.Policy;
13 using System.Reflection;
14 using System.Collections;
15 using System.Configuration;
16 using System.IO;
18 using NUnit.Core;
20 public class TestDomain : ProxyTestRunner, TestRunner
22 #region Instance Variables
24 /// <summary>
25 /// The appdomain used to load tests
26 /// </summary>
27 private AppDomain domain;
29 #endregion
31 #region Constructors
32 public TestDomain() : base( 0 ) { }
34 public TestDomain( int runnerID ) : base( runnerID ) { }
35 #endregion
37 #region Properties
38 public AppDomain AppDomain
40 get { return domain; }
42 #endregion
44 #region Loading and Unloading Tests
45 public override bool Load( TestPackage package )
47 Unload();
49 try
51 if ( this.domain == null )
52 this.domain = Services.DomainManager.CreateDomain( package );
54 if ( this.TestRunner == null )
55 this.TestRunner = MakeRemoteTestRunner( domain );
57 return TestRunner.Load( package );
59 catch
61 Unload();
62 throw;
66 public override void Unload()
68 this.TestRunner = null;
70 if(domain != null)
72 Services.DomainManager.Unload(domain);
73 domain = null;
76 #endregion
78 #region MakeRemoteTestRunner Helper
79 private TestRunner MakeRemoteTestRunner( AppDomain runnerDomain )
81 Type runnerType = typeof( RemoteTestRunner );
82 object obj = runnerDomain.CreateInstanceAndUnwrap(
83 runnerType.Assembly.FullName,
84 runnerType.FullName,
85 false, BindingFlags.Default,null,new object[] { this.ID },null,null,null);
87 RemoteTestRunner runner = (RemoteTestRunner) obj;
89 return runner;
91 #endregion