~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to src/runner/FrameworkController.cs

  • Committer: Andreas Schlapsi
  • Date: 2010-01-23 23:14:05 UTC
  • mfrom: (18.1.137 work)
  • Revision ID: a.schlapsi@gmx.at-20100123231405-17deqoh18nfnbq1j
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
// ***********************************************************************
23
23
 
24
24
using System;
 
25
using System.Diagnostics;
25
26
using System.IO;
26
27
using System.Collections;
27
 
using NUnit.Core;
 
28
using System.Xml;
28
29
 
29
30
namespace NUnit.AdhocTestRunner
30
31
{
38
39
 
39
40
        object testController;
40
41
 
41
 
        public FrameworkController(CommandLineOptions options)
 
42
        public FrameworkController(AppDomain testDomain)
42
43
        {
43
 
            this.testDomain = options.UseAppDomain
44
 
                ? CreateDomain(Path.GetDirectoryName(Path.GetFullPath(options.Parameters[0])))
45
 
                : AppDomain.CurrentDomain;
46
 
 
 
44
            this.testDomain = testDomain;
47
45
            this.testController = CreateObject("NUnit.Framework.Api.TestController");
48
46
        }
49
47
 
50
 
        public bool Load(string assemblyFileName)
 
48
        public bool Load(string assemblyFileName, IDictionary options)
51
49
        {
52
50
            CallbackHandler handler = new CallbackHandler();
53
51
 
54
52
            CreateObject("NUnit.Framework.Api.TestController+LoadTestsAction", 
55
 
                testController, assemblyFileName, handler.Callback);
 
53
                testController, assemblyFileName, options, handler.Callback);
 
54
 
 
55
            Debug.Assert(handler.Result is bool, "Returned result was not a bool");
56
56
 
57
57
            return (bool)handler.Result;
58
58
        }
59
59
 
60
 
        public TestResult Run(ITestListener listener, TestFilter filter)
 
60
        public XmlNode Run()
61
61
        {
62
 
            CallbackHandler handler = new CallbackHandler();
 
62
            CallbackHandler handler = new RunTestsCallbackHandler();
63
63
 
64
64
            CreateObject("NUnit.Framework.Api.TestController+RunTestsAction", testController, handler.Callback);
65
65
 
66
 
            return (TestResult)handler.Result;
67
 
        }
68
 
 
69
 
        #region CallbackHandler class
70
 
 
71
 
        private class CallbackHandler : MarshalByRefObject
72
 
        {
73
 
            private object result;
74
 
            private TextWriter output;
75
 
 
76
 
            public CallbackHandler()
77
 
            {
78
 
                this.output = Console.Out;
79
 
            }
80
 
 
81
 
            public object Result
82
 
            {
83
 
                get { return result; }
84
 
            }
85
 
 
86
 
            public AsyncCallback Callback
87
 
            {
88
 
                get { return new AsyncCallback(CallbackMethod); }
89
 
            }
90
 
 
91
 
            private void CallbackMethod(IAsyncResult ar)
92
 
            {
93
 
                object state = ar.AsyncState;
94
 
 
95
 
                if (ar.IsCompleted)
96
 
                    this.result = state;
97
 
                else if (state is TestOutput)
98
 
                    output.Write(((TestOutput)state).Text);
99
 
            }
100
 
 
101
 
            public override object InitializeLifetimeService()
102
 
            {
103
 
                return null;
104
 
            }
105
 
        }
106
 
 
107
 
        #endregion
 
66
            Debug.Assert(handler.Result is XmlNode, "Returned result was not an XmlNode");
 
67
 
 
68
            return handler.Result as XmlNode;
 
69
        }
108
70
 
109
71
        #region Helper Methods
110
72
 
111
 
        private static AppDomain CreateDomain(string appBase)
112
 
        {
113
 
            AppDomainSetup setup = new AppDomainSetup();
114
 
            setup.ApplicationBase = appBase;
115
 
            AppDomain domain = AppDomain.CreateDomain("test-domain", null, setup);
116
 
            return domain;
117
 
        }
118
 
 
119
73
        private object CreateObject(string typeName, params object[] args)
120
74
        {
121
75
            return this.testDomain.CreateInstanceAndUnwrap(