39
40
object testController;
41
public FrameworkController(CommandLineOptions options)
42
public FrameworkController(AppDomain testDomain)
43
this.testDomain = options.UseAppDomain
44
? CreateDomain(Path.GetDirectoryName(Path.GetFullPath(options.Parameters[0])))
45
: AppDomain.CurrentDomain;
44
this.testDomain = testDomain;
47
45
this.testController = CreateObject("NUnit.Framework.Api.TestController");
50
public bool Load(string assemblyFileName)
48
public bool Load(string assemblyFileName, IDictionary options)
52
50
CallbackHandler handler = new CallbackHandler();
54
52
CreateObject("NUnit.Framework.Api.TestController+LoadTestsAction",
55
testController, assemblyFileName, handler.Callback);
53
testController, assemblyFileName, options, handler.Callback);
55
Debug.Assert(handler.Result is bool, "Returned result was not a bool");
57
57
return (bool)handler.Result;
60
public TestResult Run(ITestListener listener, TestFilter filter)
62
CallbackHandler handler = new CallbackHandler();
62
CallbackHandler handler = new RunTestsCallbackHandler();
64
64
CreateObject("NUnit.Framework.Api.TestController+RunTestsAction", testController, handler.Callback);
66
return (TestResult)handler.Result;
69
#region CallbackHandler class
71
private class CallbackHandler : MarshalByRefObject
73
private object result;
74
private TextWriter output;
76
public CallbackHandler()
78
this.output = Console.Out;
83
get { return result; }
86
public AsyncCallback Callback
88
get { return new AsyncCallback(CallbackMethod); }
91
private void CallbackMethod(IAsyncResult ar)
93
object state = ar.AsyncState;
97
else if (state is TestOutput)
98
output.Write(((TestOutput)state).Text);
101
public override object InitializeLifetimeService()
66
Debug.Assert(handler.Result is XmlNode, "Returned result was not an XmlNode");
68
return handler.Result as XmlNode;
109
71
#region Helper Methods
111
private static AppDomain CreateDomain(string appBase)
113
AppDomainSetup setup = new AppDomainSetup();
114
setup.ApplicationBase = appBase;
115
AppDomain domain = AppDomain.CreateDomain("test-domain", null, setup);
119
73
private object CreateObject(string typeName, params object[] args)
121
75
return this.testDomain.CreateInstanceAndUnwrap(