~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/NUnit/NUnitRunner/NUnitTestRunner.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
{
44
44
        public class NUnitTestRunner: MarshalByRefObject
45
45
        {
46
 
                public void Initialize (string nunitPath, string nunitCorePath)
47
 
                {
48
 
                        // In some cases MS.NET can't properly resolve assemblies even if they
49
 
                        // are already loaded. For example, when deserializing objects from remoting.
50
 
                        AppDomain.CurrentDomain.AssemblyResolve += delegate (object s, ResolveEventArgs args) {
51
 
                                foreach (Assembly am in AppDomain.CurrentDomain.GetAssemblies ()) {
52
 
                                        if (am.GetName ().FullName == args.Name)
53
 
                                                return am;
54
 
                                }
55
 
                                return null;
56
 
                        };
57
 
 
 
46
                public NUnitTestRunner ()
 
47
                {
 
48
                }
 
49
 
 
50
                public void PreloadAssemblies (string nunitPath, string nunitCorePath, string nunitCoreInterfacesPath)
 
51
                {
 
52
                        // Note: We need to load all nunit.*.dll assemblies before we do *anything* else in this class
 
53
                        // This is to ensure that we always load the assemblies from the monodevelop directory and not
 
54
                        // from the directory of the assembly under test. For example we wnat to load
 
55
                        // /Applications/MonoDevelop/lib/Addins/nunit.framework.dll and not /user/app/foo/bin/debug/nunit.framework.dll
 
56
 
 
57
                        // In some cases MS.NET can't properly resolve assemblies even if they
 
58
                        // are already loaded. For example, when deserializing objects from remoting.
 
59
                        AppDomain.CurrentDomain.AssemblyResolve += delegate (object s, ResolveEventArgs args) {
 
60
                                foreach (Assembly am in AppDomain.CurrentDomain.GetAssemblies ()) {
 
61
                                        if (am.GetName ().FullName == args.Name)
 
62
                                                return am;
 
63
                                }
 
64
                                return null;
 
65
                        };
 
66
                        
58
67
                        // Force the loading of the NUnit.Framework assembly.
59
68
                        // It's needed since that dll is not located in the test dll directory.
 
69
                        Assembly.LoadFrom (nunitCoreInterfacesPath);
60
70
                        Assembly.LoadFrom (nunitCorePath);
61
71
                        Assembly.LoadFrom (nunitPath);
62
 
 
 
72
                }
 
73
 
 
74
                public void Initialize ()
 
75
                {
63
76
                        // Initialize ExtensionHost if not already done
64
77
                        if ( !CoreExtensions.Host.Initialized )
65
78
                                CoreExtensions.Host.InitializeService();
66
79
                }
67
80
                
68
 
                public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies)
 
81
                public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies, string testRunnerType, string testRunnerAssembly)
69
82
                {
70
83
                        InitSupportAssemblies (supportAssemblies);
71
84
                        
72
85
                        if (filter == null)
73
86
                                filter = TestFilter.Empty;
74
 
                        
75
 
                        RemoteTestRunner tr = new RemoteTestRunner ();
 
87
 
 
88
                        TestRunner tr;
 
89
                        if (!string.IsNullOrEmpty (testRunnerType)) {
 
90
                                Type runnerType;
 
91
                                if (string.IsNullOrEmpty (testRunnerAssembly))
 
92
                                        runnerType = Type.GetType (testRunnerType, true);
 
93
                                else {
 
94
                                        var asm = Assembly.LoadFrom (testRunnerAssembly);
 
95
                                        runnerType = asm.GetType (testRunnerType);
 
96
                                }
 
97
                                tr = (TestRunner)Activator.CreateInstance (runnerType);
 
98
                        } else
 
99
                                tr = new RemoteTestRunner ();
 
100
 
76
101
                        TestPackage package = new TestPackage (path);
77
102
                        if (!string.IsNullOrEmpty (suiteName))
78
103
                                package.TestName = suiteName;
135
160
                {
136
161
                        return null;
137
162
                }
 
163
        }
138
164
 
139
 
        }
140
 
        
141
165
        [Serializable]
142
166
        public class NunitTestInfo
143
167
        {