本文整理汇总了C#中NUnit.Core.TestPackage.GetSetting方法的典型用法代码示例。如果您正苦于以下问题:C# TestPackage.GetSetting方法的具体用法?C# TestPackage.GetSetting怎么用?C# TestPackage.GetSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Core.TestPackage
的用法示例。
在下文中一共展示了TestPackage.GetSetting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public override bool Load(TestPackage package)
{
log.Info("Loading Test Package " + package.Name );
// Initialize ExtensionHost if not already done
if ( !CoreExtensions.Host.Initialized )
CoreExtensions.Host.InitializeService();
// Delayed creation of downstream runner allows us to
// use a different runner type based on the package
bool useThreadedRunner = package.GetSetting( "UseThreadedRunner", true );
TestRunner runner = new SimpleTestRunner( this.runnerID );
if (useThreadedRunner)
{
ApartmentState apartmentState = (ApartmentState)package.GetSetting("ApartmentState", ApartmentState.Unknown);
ThreadPriority priority = (ThreadPriority)package.GetSetting("ThreadPriority", ThreadPriority.Normal);
runner = new ThreadedTestRunner(runner, apartmentState, priority);
}
this.TestRunner = runner;
if( base.Load (package) )
{
log.Info("Loaded package successfully" );
return true;
}
else
{
log.Info("Package load failed" );
return false;
}
}
示例2: Build
/// <summary>
/// Build a suite based on a TestPackage
/// </summary>
/// <param name="package">The TestPackage</param>
/// <returns>A TestSuite</returns>
public TestSuite Build( TestPackage package )
{
bool autoNamespaceSuites = package.GetSetting( "AutoNamespaceSuites", true );
bool mergeAssemblies = package.GetSetting( "MergeAssemblies", false );
TestExecutionContext.CurrentContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0);
if ( package.IsSingleAssembly )
return BuildSingleAssembly( package );
string targetAssemblyName = null;
if( package.TestName != null && package.Assemblies.Contains( package.TestName ) )
{
targetAssemblyName = package.TestName;
package.TestName = null;
}
TestSuite rootSuite = new ProjectRootSuite( package.FullName );
NamespaceTreeBuilder namespaceTree =
new NamespaceTreeBuilder( rootSuite );
builders.Clear();
foreach(string assemblyName in package.Assemblies)
{
if ( targetAssemblyName == null || targetAssemblyName == assemblyName )
{
TestAssemblyBuilder builder = new TestAssemblyBuilder();
builders.Add( builder );
Test testAssembly = builder.Build( assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies );
if ( testAssembly != null )
{
if (!mergeAssemblies)
{
rootSuite.Add(testAssembly);
}
else if (autoNamespaceSuites)
{
namespaceTree.Add(testAssembly.Tests);
rootSuite = namespaceTree.RootSuite;
}
else
{
foreach (Test test in testAssembly.Tests)
rootSuite.Add(test);
}
}
}
}
ProviderCache.Clear();
if (rootSuite.Tests.Count == 0)
return null;
return rootSuite;
}
示例3: Load
public override bool Load(TestPackage package)
{
log.Info("Loading Test Package " + package.Name );
// Initialize ExtensionHost if not already done
if ( !CoreExtensions.Host.Initialized )
CoreExtensions.Host.InitializeService();
// Delayed creation of downstream runner allows us to
// use a different runner type based on the package
bool useThreadedRunner = package.GetSetting( "UseThreadedRunner", true );
TestRunner runner = new SimpleTestRunner( this.runnerID );
if ( useThreadedRunner )
runner = new ThreadedTestRunner( runner );
this.TestRunner = runner;
if( base.Load (package) )
{
log.Info("Loaded package successfully" );
return true;
}
else
{
log.Info("Package load failed" );
return false;
}
}
示例4: Build
/// <summary>
/// Build a suite based on a TestPackage
/// </summary>
/// <param name="package">The TestPackage</param>
/// <returns>A TestSuite</returns>
public TestSuite Build( TestPackage package )
{
bool autoNamespaceSuites = package.GetSetting( "AutoNamespaceSuites", true );
bool mergeAssemblies = package.GetSetting( "MergeAssemblies", false );
if ( package.IsSingleAssembly )
return BuildSingleAssembly( package );
TestSuite rootSuite = new TestSuite( package.FullName );
NamespaceTreeBuilder namespaceTree =
new NamespaceTreeBuilder( rootSuite );
builders.Clear();
foreach(string assemblyName in package.Assemblies)
{
TestAssemblyBuilder builder = new TestAssemblyBuilder();
builders.Add( builder );
Test testAssembly = builder.Build( assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies );
if ( testAssembly != null )
{
if (!mergeAssemblies)
{
rootSuite.Add(testAssembly);
}
else if (autoNamespaceSuites)
{
namespaceTree.Add(testAssembly.Tests);
rootSuite = namespaceTree.RootSuite;
}
else
{
foreach (Test test in testAssembly.Tests)
rootSuite.Add(test);
}
}
}
if ( rootSuite.Tests.Count == 0 )
return null;
return rootSuite;
}
示例5: GetTargetProcessModel
private ProcessModel GetTargetProcessModel(TestPackage package)
{
RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework;
RuntimeFramework targetFramework = selector.SelectRuntimeFramework(package);
ProcessModel processModel = (ProcessModel)package.GetSetting("ProcessModel", ProcessModel.Default);
if (processModel == ProcessModel.Default)
if (!currentFramework.Supports(targetFramework))
processModel = ProcessModel.Separate;
return processModel;
}
示例6: MakeTestRunner
/// <summary>
/// Returns a test runner based on the settings in a TestPackage.
/// Any setting that is "consumed" by the factory is removed, so
/// that downstream runners using the factory will not repeatedly
/// create the same type of runner.
/// </summary>
/// <param name="package">The TestPackage to be loaded and run</param>
/// <returns>A TestRunner</returns>
public static TestRunner MakeTestRunner(TestPackage package)
{
RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework;
RuntimeFramework targetFramework = package.Settings["RuntimeFramework"] as RuntimeFramework;
if (targetFramework == null)
targetFramework = currentFramework;
else if (targetFramework.Runtime == RuntimeType.Any)
{
targetFramework = new RuntimeFramework(currentFramework.Runtime, targetFramework.Version);
package.Settings["RuntimeFramework"] = targetFramework;
}
log.Debug("Test requires {0} framework", targetFramework);
ProcessModel processModel = (ProcessModel)package.GetSetting("ProcessModel", ProcessModel.Default);
if ( processModel == ProcessModel.Default )
if ( !targetFramework.Matches( currentFramework ) )
processModel = ProcessModel.Separate;
switch (processModel)
{
case ProcessModel.Multiple:
package.Settings.Remove("ProcessModel");
return new MultipleTestProcessRunner();
case ProcessModel.Separate:
package.Settings.Remove("ProcessModel");
return new ProcessRunner();
default:
DomainUsage domainUsage =
(DomainUsage)package.GetSetting("DomainUsage", DomainUsage.Default);
if (domainUsage == DomainUsage.Multiple)
{
package.Settings.Remove("DomainUsage");
return new MultipleTestDomainRunner();
}
else
return new TestDomain();
}
}
示例7: MakeTestRunner
/// <summary>
/// Returns a test runner based on the settings in a TestPackage.
/// Any setting that is "consumed" by the factory is removed, so
/// that downstream runners using the factory will not repeatedly
/// create the same type of runner.
/// </summary>
/// <param name="package">The TestPackage to be loaded and run</param>
/// <returns>A TestRunner</returns>
public virtual TestRunner MakeTestRunner(TestPackage package)
{
DomainUsage domainUsage =
(DomainUsage)package.GetSetting("DomainUsage", DomainUsage.Default);
switch (domainUsage)
{
case DomainUsage.Multiple:
package.Settings.Remove("DomainUsage");
return new MultipleTestDomainRunner();
case DomainUsage.None:
return new RemoteTestRunner();
case DomainUsage.Single:
default:
return new TestDomain();
}
}
示例8: Load
public override bool Load(TestPackage package)
{
// Initialize ExtensionHost if not already done
if ( !CoreExtensions.Host.Initialized )
CoreExtensions.Host.InitializeService();
// Delayed creation of downstream runner allows us to
// use a different runner type based on the package
bool useThreadedRunner = package.GetSetting( "UseThreadedRunner", true );
TestRunner runner = new SimpleTestRunner( this.runnerID );
if ( useThreadedRunner )
runner = new ThreadedTestRunner( runner );
this.TestRunner = runner;
return base.Load (package);
}
示例9: CanReuse
public override bool CanReuse(TestRunner runner, TestPackage package)
{
RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework;
RuntimeFramework targetFramework = selector.SelectRuntimeFramework(package);
ProcessModel processModel = (ProcessModel)package.GetSetting("ProcessModel", ProcessModel.Default);
if (processModel == ProcessModel.Default)
if (!currentFramework.Supports(targetFramework))
processModel = ProcessModel.Separate;
switch (processModel)
{
case ProcessModel.Multiple:
return runner is MultipleTestProcessRunner;
case ProcessModel.Separate:
ProcessRunner processRunner = runner as ProcessRunner;
return processRunner != null && processRunner.RuntimeFramework == targetFramework;
default:
return base.CanReuse(runner, package);
}
}
示例10: MakeTestRunner
/// <summary>
/// Returns a test runner based on the settings in a TestPackage.
/// Any setting that is "consumed" by the factory is removed, so
/// that downstream runners using the factory will not repeatedly
/// create the same type of runner.
/// </summary>
/// <param name="package">The TestPackage to be loaded and run</param>
/// <returns>A TestRunner</returns>
public override TestRunner MakeTestRunner(TestPackage package)
{
RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework;
RuntimeFramework targetFramework = selector.SelectRuntimeFramework(package);
ProcessModel processModel = (ProcessModel)package.GetSetting("ProcessModel", ProcessModel.Default);
if ( processModel == ProcessModel.Default )
if ( !targetFramework.Matches( currentFramework ) )
processModel = ProcessModel.Separate;
switch (processModel)
{
case ProcessModel.Multiple:
package.Settings.Remove("ProcessModel");
return new MultipleTestProcessRunner();
case ProcessModel.Separate:
package.Settings.Remove("ProcessModel");
return new ProcessRunner();
default:
return base.MakeTestRunner(package);
}
}
示例11: Load
public override bool Load(TestPackage package)
{
log.Info("Loading " + package.Name);
Unload();
runtimeFramework = package.Settings["RuntimeFramework"] as RuntimeFramework;
if ( runtimeFramework == null )
runtimeFramework = RuntimeFramework.CurrentFramework;
bool enableDebug = package.GetSetting("EnableDebug", false);
bool loaded = false;
try
{
if (this.agent == null)
{
this.agent = Services.TestAgency.GetAgent(
runtimeFramework,
30000,
enableDebug);
if (this.agent == null)
return false;
}
if ( this.TestRunner == null )
this.TestRunner = agent.CreateRunner(this.runnerID);
loaded = base.Load (package);
return loaded;
}
finally
{
// Clean up if the load failed
if ( !loaded ) Unload();
}
}
示例12: CreateDomain
/// <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);
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 NET_2_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);
// 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;
}
示例13: BuildSingleAssembly
private TestSuite BuildSingleAssembly( TestPackage package )
{
TestAssemblyBuilder builder = new TestAssemblyBuilder();
builders.Clear();
builders.Add( builder );
return (TestSuite)builder.Build(
package.FullName,
package.TestName, package.GetSetting( "AutoNamespaceSuites", true ) );
}
示例14: CreateDomain
/// <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;
}
示例15: CreateDomain
/// <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;
}