public NUnit2FrameworkDriver(AppDomain testDomain, string frameworkAssemblyName, string testAssemblyPath, IDictionary <string, object> settings) { if (!File.Exists(testAssemblyPath)) { throw new ArgumentException("testAssemblyPath", "Framework driver constructor called with a file name that doesn't exist."); } _testDomain = testDomain; _testAssemblyPath = testAssemblyPath; _frameworkAssemblyName = frameworkAssemblyName; _name = Escape(Path.GetFileName(_testAssemblyPath)); _fullname = Escape(_testAssemblyPath); var initializer = DomainInitializer.CreateInstance(_testDomain); initializer.InitializeDomain((int)InternalTrace.Level); _runner = RemoteTestRunner.CreateInstance(_testDomain, 1); _package = new Core.TestPackage(_frameworkAssemblyName); foreach (var key in settings.Keys) { _package.Settings[key] = settings[key]; } }
/// <summary> /// Create a new NUnit2FrameworkDriver /// </summary> /// <param name="testDomain">The AppDomain to use for the runner</param> /// <remarks> /// The framework assembly name is needed because this driver is used for both the /// nunit.framework 2.x and nunitlite 1.0. /// </remarks> public NUnit2FrameworkDriver(AppDomain testDomain) { _testDomain = testDomain; var initializer = DomainInitializer.CreateInstance(_testDomain); initializer.InitializeDomain((int)InternalTrace.Level); }
public DefaultUmbracoSitemapContentProvider(DomainInitializer domainInitializer) { Initializer = domainInitializer; Filters = new List <IFilter> { new NoTemplateFilter(), new PropertiesFilter(new List <PropertyFilterOptions> { new PropertyFilterOptions() { Alias = "metaHideFromSitemap", Operator = FilterOperator.Equals, Required = false, Value = "false" } }) }; }
/// <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) { AppDomainSetup setup = new AppDomainSetup(); //For paralell tests, we need to use distinct application name setup.ApplicationName = "Tests" + "_" + Environment.TickCount; FileInfo testFile = package.FullName != null && package.FullName != string.Empty ? new FileInfo(package.FullName) : null; string appBase = package.BasePath; string configFile = package.ConfigurationFile; string binPath = package.PrivateBinPath; if (testFile != null) { if (appBase == null || appBase == string.Empty) { appBase = testFile.DirectoryName; } if (configFile == null || configFile == string.Empty) { configFile = Services.ProjectService.CanLoadProject(testFile.Name) ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config" : testFile.Name + ".config"; } } else if (appBase == null || appBase == string.Empty) { appBase = GetCommonAppBase(package.Assemblies); } char lastChar = appBase[appBase.Length - 1]; if (lastChar != Path.DirectorySeparatorChar && lastChar != Path.AltDirectorySeparatorChar) { appBase += Path.DirectorySeparatorChar; } setup.ApplicationBase = appBase; // TODO: Check whether Mono still needs full path to config file... setup.ConfigurationFile = appBase != null && configFile != null ? Path.Combine(appBase, configFile) : configFile; 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; // TODO: Try to eliminate this test. Currently, running on // Linux with the permission set specified causes an // unexplained crash when unloading the domain. #if CLR_2_0 || CLR_4_0 if (Environment.OSVersion.Platform == PlatformID.Win32NT) { PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted); runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup, permissionSet, null); } else #endif runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup); // Set PrincipalPolicy for the domain if called for in the settings if (Services.UserSettings.GetSetting("Options.TestLoader.SetPrincipalPolicy", false)) { runnerDomain.SetPrincipalPolicy((PrincipalPolicy)Services.UserSettings.GetSetting( "Options.TestLoader.PrincipalPolicy", PrincipalPolicy.UnauthenticatedPrincipal)); } // 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); // HACK: Under nunit-console, direct use of the enum fails int traceLevel = IsTestDomain(AppDomain.CurrentDomain) ? (int)InternalTraceLevel.Off : (int)InternalTrace.Level; initializer.InitializeDomain(traceLevel); return(runnerDomain); }