private TestFilter GetNamespaceFilter(TestRunner testRunner, string filter)
        {
            TestDomain       testDomain       = (TestDomain)testRunner;
            AssemblyResolver assemblyResolver = (AssemblyResolver)testDomain.AppDomain.CreateInstanceFromAndUnwrap(
                typeof(AssemblyResolver).Assembly.CodeBase,
                typeof(AssemblyResolver).FullName);

            // Tell resolver to use the nunit-console assembly in the test domain
            assemblyResolver.AddFile(GetType().Assembly.Location);
            return(new NamespaceFilter(filter));
        }
Example #2
0
        public void AddFile()
        {
            AppDomain domain = null;

            try
            {
                domain = AppDomain.CreateDomain("AssemblyResolver", null, this.appBasePath, null, false);
                AssemblyResolver assemblyResolver = (AssemblyResolver)domain.CreateInstanceFromAndUnwrap(typeof(AssemblyResolver).Assembly.CodeBase, typeof(AssemblyResolver).FullName);
                using (assemblyResolver)
                {
                    Type type = typeof(TestAttribute);
                    // ensure that assembly containing type can be found
                    assemblyResolver.AddFile(type.Assembly.CodeBase);
                    domain.CreateInstance(type.Assembly.FullName, type.FullName);
                }
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }
Example #3
0
        /// <summary>
        /// Construct an application domain for running a test package
        /// </summary>
        /// <param name="package">The TestPackage to be run</param>
        public AppDomain CreateDomain(TestPackage package)
        {
            FileInfo testFile = new FileInfo(package.FullName);

            AppDomainSetup setup = new AppDomainSetup();

            // We always use the same application name
            setup.ApplicationName = "Tests";

            string appBase = package.BasePath;

            if (appBase == null || appBase == string.Empty)
            {
                appBase = testFile.DirectoryName;
            }
            setup.ApplicationBase = appBase;

            string configFile = package.ConfigurationFile;

            if (configFile == null || configFile == string.Empty)
            {
                configFile = testFile.Name + ".config";
            }
            // Note: Mono needs full path to config file...
            setup.ConfigurationFile = Path.Combine(appBase, configFile);

            string binPath = package.PrivateBinPath;

            if (package.AutoBinPath)
            {
                binPath = GetPrivateBinPath(appBase, package.Assemblies);
            }
            setup.PrivateBinPath = binPath;

            if (package.GetSetting("ShadowCopyFiles", true))
            {
                setup.ShadowCopyFiles       = "true";
                setup.ShadowCopyDirectories = appBase;
                setup.CachePath             = GetCachePath();
            }

            string    domainName   = "domain-" + package.Name;
            Evidence  baseEvidence = AppDomain.CurrentDomain.Evidence;
            Evidence  evidence     = new Evidence(baseEvidence);
            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

            // Inject assembly resolver into remote domain to help locate our assemblies
            AssemblyResolver assemblyResolver = (AssemblyResolver)runnerDomain.CreateInstanceFromAndUnwrap(
                typeof(AssemblyResolver).Assembly.CodeBase,
                typeof(AssemblyResolver).FullName);

            // Tell resolver to use our core assemblies in the test domain
            assemblyResolver.AddFile(typeof(NUnit.Core.RemoteTestRunner).Assembly.Location);
            assemblyResolver.AddFile(typeof(NUnit.Core.ITest).Assembly.Location);

// No reference to extensions, so we do it a different way
            string moduleName   = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string nunitDirPath = Path.GetDirectoryName(moduleName);
//            string coreExtensions = Path.Combine(nunitDirPath, "nunit.core.extensions.dll");
//			assemblyResolver.AddFile( coreExtensions );
            //assemblyResolver.AddFiles( nunitDirPath, "*.dll" );

            string addinsDirPath = Path.Combine(nunitDirPath, "addins");

            assemblyResolver.AddDirectory(addinsDirPath);

            // HACK: Only pass down our AddinRegistry one level so that tests of NUnit
            // itself start without any addins defined.
            if (!IsTestDomain(AppDomain.CurrentDomain))
            {
                runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);
            }

            return(runnerDomain);
        }