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 // ****************************************************************
11 using System
.Diagnostics
;
12 using System
.Security
.Policy
;
13 using System
.Reflection
;
14 using System
.Collections
;
15 using System
.Configuration
;
20 public class TestDomain
: ProxyTestRunner
, TestRunner
22 #region Instance Variables
25 /// The appdomain used to load tests
27 private AppDomain domain
;
32 public TestDomain() : base( 0 ) { }
34 public TestDomain( int runnerID
) : base( runnerID
) { }
38 public AppDomain AppDomain
40 get { return domain; }
44 #region Loading and Unloading Tests
45 public override bool Load( TestPackage package
)
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
);
66 public override void Unload()
68 this.TestRunner
= null;
72 Services
.DomainManager
.Unload(domain
);
78 #region MakeRemoteTestRunner Helper
79 private TestRunner
MakeRemoteTestRunner( AppDomain runnerDomain
)
81 Type runnerType
= typeof( RemoteTestRunner
);
82 object obj
= runnerDomain
.CreateInstanceAndUnwrap(
83 runnerType
.Assembly
.FullName
,
85 false, BindingFlags
.Default
,null,new object[] { this.ID }
,null,null,null);
87 RemoteTestRunner runner
= (RemoteTestRunner
) obj
;