~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/NUnitFramework/core/TestRunner.cs

  • Committer: jnewkirk
  • Date: 2002-07-10 20:00:13 UTC
  • Revision ID: vcs-imports@canonical.com-20020710200013-j8us5mbi0usp7p02
initialĀ load

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (C) 2002. James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
 
3
//
 
4
namespace Nunit.Core
 
5
{
 
6
        using System;
 
7
        using System.Runtime.Remoting;
 
8
        using System.Security.Policy;
 
9
        using System.Reflection;
 
10
        using System.IO;
 
11
        
 
12
        /// <summary>
 
13
        /// Summary description for TestRunner.
 
14
        /// </summary>
 
15
        public class TestRunner
 
16
        {
 
17
                private string assemblyName;
 
18
                private Nunit.Core.EventListener eventHandler;
 
19
                private AppDomain runnerDomain;
 
20
                private RemoteTestRunner runner;
 
21
                private string fullName;
 
22
                private TextWriter stdOutWriter;
 
23
                private TextWriter stdErrWriter;
 
24
 
 
25
                public TestRunner(string assemblyName, Nunit.Core.EventListener listener, TextWriter stdOutWriter, TextWriter stdErrWriter)
 
26
                {
 
27
                        this.assemblyName = assemblyName;
 
28
                        this.eventHandler = listener;
 
29
                        this.stdErrWriter = stdErrWriter;
 
30
                        this.stdOutWriter = stdOutWriter;
 
31
                        LoadRunner();
 
32
                }
 
33
 
 
34
                public void LoadRunner()
 
35
                {
 
36
                        FileInfo info = new FileInfo(assemblyName);
 
37
                        
 
38
                        AppDomainSetup setup = new AppDomainSetup();
 
39
                        setup.ShadowCopyDirectories = info.DirectoryName;
 
40
                        setup.ShadowCopyFiles = "true";
 
41
 
 
42
                        Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
 
43
                        Evidence evidence = new Evidence(baseEvidence);
 
44
                        
 
45
                        runnerDomain = AppDomain.CreateDomain("RemoteRunnerDomain", evidence, setup);
 
46
                        //runnerDomain.ClearShadowCopyPath();
 
47
                        ObjectHandle handle = runnerDomain.CreateInstance(
 
48
                typeof(RemoteTestRunner).Assembly.FullName, typeof(RemoteTestRunner).FullName,
 
49
                                false,
 
50
                                BindingFlags.Default,null,new object[]{assemblyName,eventHandler,stdOutWriter, stdErrWriter},null,null,null);
 
51
                        Object runnerObject = handle.Unwrap();
 
52
                        runner = (RemoteTestRunner)runnerObject;
 
53
                }
 
54
 
 
55
                public TestResult Run()
 
56
                {
 
57
                        LoadRunner();
 
58
 
 
59
                        //Assembly[] assemblies = runnerDomain.GetAssemblies();
 
60
                        //foreach(Assembly assembly in assemblies)
 
61
                        //      Console.Out.WriteLine("{0}", assembly.Location);
 
62
                        runner.TestName = fullName;
 
63
                        TestResult result = runner.Run();
 
64
                        //Console.WriteLine("after");
 
65
                        //foreach(Assembly assembly in runnerDomain.GetAssemblies())
 
66
                        //      Console.Out.WriteLine("{0}", assembly.Location);
 
67
                        return result;
 
68
                }
 
69
 
 
70
                public Test Test
 
71
                {
 
72
                        get 
 
73
                        {
 
74
                                LoadRunner();
 
75
                                return runner.Test;
 
76
                        }
 
77
                }
 
78
 
 
79
                public string TestName 
 
80
                {
 
81
                        get { return fullName; }
 
82
                        set { fullName = value;}
 
83
                }
 
84
        }
 
85
}