Esempio n. 1
0
        public NUnitProject LoadProject(string path)
        {
            if (NUnitProject.IsProjectFile(path))
            {
                NUnitProject project = new NUnitProject(path);
                project.Load();
                return(project);
            }

            return(ConvertFrom(path));
        }
 /// <summary>
 /// Return a test project by either loading it from
 /// the supplied path, creating one from a VS file
 /// or wrapping an assembly.
 /// </summary>
 public static NUnitProject LoadProject(string path)
 {
     if (NUnitProject.IsProjectFile(path))
     {
         NUnitProject project = new NUnitProject(path);
         project.Load();
         return(project);
     }
     else if (VSProject.IsProjectFile(path))
     {
         return(NUnitProject.FromVSProject(path));
     }
     else if (VSProject.IsSolutionFile(path))
     {
         return(NUnitProject.FromVSSolution(path));
     }
     else
     {
         return(NUnitProject.FromAssembly(path));
     }
 }
Esempio n. 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();

            //For paralell tests, we need to use distinct application name
            setup.ApplicationName = "Tests" + "_" + Environment.TickCount;
            //setup.ApplicationName = package.Name;

            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 = NUnitProject.IsProjectFile(testFile.Name)
                                        ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config"
                                        : 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();
            }
            else
            {
                setup.ShadowCopyFiles = "false";
            }

            string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);

            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url      url      = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

            // 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);
            }

            // Inject DomainInitializer into the remote domain - there are other
            // approaches, but this works for all CLR versions.
            DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);

            initializer.InitializeDomain(IsTestDomain(AppDomain.CurrentDomain)
                ? TraceLevel.Off : InternalTrace.Level);

            return(runnerDomain);
        }
        /// <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 = NUnitProject.IsProjectFile(testFile.Name)
                         ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config"
                         : 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);
        }
Esempio n. 5
0
 public bool CanLoadProject(string path)
 {
     return(NUnitProject.IsProjectFile(path) || CanConvertFrom(path));
 }