本文整理汇总了C#中NUnit.Framework.Internal.TestExecutionContext类的典型用法代码示例。如果您正苦于以下问题:C# TestExecutionContext类的具体用法?C# TestExecutionContext怎么用?C# TestExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestExecutionContext类属于NUnit.Framework.Internal命名空间,在下文中一共展示了TestExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override TestResult Execute(TestExecutionContext context)
{
string setCulture = (string)Test.Properties.Get(PropertyNames.SetCulture);
if (setCulture != null)
context.CurrentCulture = new System.Globalization.CultureInfo(setCulture);
return innerCommand.Execute(context);
}
示例2: Initialize
public void Initialize()
{
setupContext = new TestExecutionContext(TestExecutionContext.CurrentContext);
#if !NETCF
currentCulture = CultureInfo.CurrentCulture;
currentUICulture = CultureInfo.CurrentUICulture;
currentDirectory = Environment.CurrentDirectory;
currentPrincipal = Thread.CurrentPrincipal;
#endif
}
示例3: RunTestFixture
public static TestResult RunTestFixture(Type type)
{
TestSuite suite = MakeFixture(type);
TestExecutionContext context = new TestExecutionContext();
context.TestObject = null;
CompositeWorkItem work = new CompositeWorkItem(suite, TestFilter.Empty);
return ExecuteAndWaitForResult(work, context);
}
示例4: Initialize
public void Initialize()
{
setupContext = new TestExecutionContext(TestExecutionContext.CurrentContext);
#if !NETCF && !PORTABLE
originalCulture = CultureInfo.CurrentCulture;
originalUICulture = CultureInfo.CurrentUICulture;
#endif
#if !NETCF && !SILVERLIGHT && !PORTABLE
originalDirectory = Environment.CurrentDirectory;
originalPrincipal = Thread.CurrentPrincipal;
#endif
}
示例5: Execute
public override TestResult Execute(TestExecutionContext context)
{
Type caughtType = null;
Exception exception = null;
try
{
innerCommand.Execute(context);
}
catch (Exception ex)
{
exception = ex;
if (exception is NUnitException)
exception = ex.InnerException;
caughtType = exception.GetType();
}
if (caughtType == _expectedType)
{
if (_expectedMessage == null || _expectedMessage == exception.Message)
context.CurrentResult.SetResult(ResultState.Success);
else
context.CurrentResult.SetResult(ResultState.Failure,
"Expected {0} but got {1}".Args(_expectedMessage, exception.Message));
}
else if (caughtType != null)
{
context.CurrentResult.SetResult(ResultState.Failure,
"Expected {0} but got {1}".Args(_expectedType.Name, caughtType.Name));
}
else
{
context.CurrentResult.SetResult(ResultState.Failure,
"Expected {0} but no exception was thrown".Args(_expectedType.Name));
}
return context.CurrentResult;
}
示例6: TestExecutionContext
/// <summary>
/// Initializes a new instance of the <see cref="TestExecutionContext"/> class.
/// </summary>
/// <param name="other">An existing instance of TestExecutionContext.</param>
public TestExecutionContext( TestExecutionContext other )
{
this.prior = other;
this.currentTest = other.currentTest;
this.currentResult = other.currentResult;
this.testObject = other.testObject;
this.workDirectory = other.workDirectory;
this.listener = other.listener;
this.stopOnError = other.stopOnError;
this.testCaseTimeout = other.testCaseTimeout;
#if !NETCF
this.currentCulture = CultureInfo.CurrentCulture;
this.currentUICulture = CultureInfo.CurrentUICulture;
#endif
#if !NETCF && !SILVERLIGHT
this.outWriter = other.outWriter;
this.errorWriter = other.errorWriter;
this.traceWriter = other.traceWriter;
this.tracing = other.tracing;
#endif
#if !NUNITLITE
this.logging = other.logging;
this.currentDirectory = Environment.CurrentDirectory;
this.logCapture = other.logCapture;
this.currentPrincipal = Thread.CurrentPrincipal;
#endif
}
示例7: InitializeTestEngine
/// <summary>
/// Initializes the underlying test engine.
/// </summary>
private static void InitializeTestEngine()
{
TestExecutionContext context = new TestExecutionContext();
context.WorkDirectory = Environment.CurrentDirectory;
CallContext.SetData( "NUnit.Framework.TestContext", context );
}
示例8: TestExecutionContext
/// <summary>
/// Initializes a new instance of the <see cref="TestExecutionContext"/> class.
/// </summary>
/// <param name="other">An existing instance of TestExecutionContext.</param>
public TestExecutionContext(TestExecutionContext other)
{
_priorContext = other;
this.CurrentTest = other.CurrentTest;
this.CurrentResult = other.CurrentResult;
this.TestObject = other.TestObject;
this.WorkDirectory = other.WorkDirectory;
_listener = other._listener;
this.StopOnError = other.StopOnError;
this.TestCaseTimeout = other.TestCaseTimeout;
this.UpstreamActions = new List<ITestAction>(other.UpstreamActions);
_currentCulture = CultureInfo.CurrentCulture;
_currentUICulture = CultureInfo.CurrentUICulture;
#if !NETCF && !SILVERLIGHT && !PORTABLE
_currentPrincipal = other.CurrentPrincipal;
#endif
this.Dispatcher = other.Dispatcher;
this.ParallelScope = other.ParallelScope;
}
示例9: GetWorkItem
public static FakeWorkItem GetWorkItem(object obj, string name, TestExecutionContext context)
{
return GetWorkItem(obj.GetType(), name, context);
}
示例10: Save
/// <summary>
/// Saves the old context and makes a fresh one
/// current without changing any settings.
/// </summary>
public static void Save()
{
TestExecutionContext.current = new TestExecutionContext(current);
}
示例11: SetUp
public void SetUp()
{
_context = new TestExecutionContext();
}
示例12: TestContext
/// <summary>
/// Construct a TestContext for an ExecutionContext
/// </summary>
/// <param name="ec">The ExecutionContext to adapt</param>
public TestContext(TestExecutionContext ec)
{
this.ec = ec;
}
示例13: RunTest
// This method can't currently be used. It would be more efficient
// to run test cases using the command directly, but that would
// cause errors in tests that have a timeout or that require a
// separate thread or a specific apartment. Those features are
// handled at the level of the WorkItem in the current build.
// Therefore, we run all tests, both test cases and fixtures,
// by creating a WorkItem and executing it. See the RunTest
// method below.
//public static ITestResult RunTestMethod(TestMethod testMethod, object fixture)
//{
// TestExecutionContext context = new TestExecutionContext();
// context.CurrentTest = testMethod;
// context.CurrentResult = testMethod.MakeTestResult();
// context.TestObject = fixture;
// TestCommand command = testMethod.MakeTestCommand();
// return command.Execute(context);
//}
//public static ITestResult RunTest(Test test)
//{
// return RunTest(test, null);
//}
public static ITestResult RunTest(Test test, object testObject)
{
TestExecutionContext context = new TestExecutionContext();
context.TestObject = testObject;
WorkItem work = WorkItem.CreateWorkItem(test, TestFilter.Empty);
work.InitializeContext(context);
work.Execute();
// TODO: Replace with an event - but not while method is static
while (work.State != WorkItemState.Complete)
{
#if PORTABLE
System.Threading.Tasks.Task.Delay(1);
#else
Thread.Sleep(1);
#endif
}
return work.Result;
}
示例14: ExecutionStatusIsPromulgatedAcrossBranches
public void ExecutionStatusIsPromulgatedAcrossBranches()
{
var topContext = new TestExecutionContext();
var leftContext = new TestExecutionContext(new TestExecutionContext(new TestExecutionContext(topContext)));
var rightContext = new TestExecutionContext(new TestExecutionContext(new TestExecutionContext(topContext)));
leftContext.ExecutionStatus = TestExecutionStatus.StopRequested;
Assert.That(rightContext.ExecutionStatus, Is.EqualTo(TestExecutionStatus.StopRequested));
}
示例15: OneTimeSetUp
public void OneTimeSetUp()
{
fixtureContext = TestExecutionContext.CurrentContext;
}