private void RunTest() { _context.CurrentTest = this.Test; _context.CurrentResult = this.Result; _context.Listener.TestStarted(this.Test); _context.StartTime = DateTime.Now; TestExecutionContext.SetCurrentContext(_context); #if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0 long startTicks = Stopwatch.GetTimestamp(); #endif try { PerformWork(); } finally { #if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0 long tickCount = Stopwatch.GetTimestamp() - startTicks; double seconds = (double)tickCount / Stopwatch.Frequency; Result.Duration = TimeSpan.FromSeconds(seconds); #else Result.Duration = DateTime.Now - Context.StartTime; #endif Result.AssertCount = _context.AssertCount; _context.Listener.TestFinished(Result); _context = _context.Restore(); _context.AssertCount += Result.AssertCount; } }
public void SetAndRestoreCurrentDirectory() { Assert.AreEqual(currentDirectory, TestExecutionContext.CurrentContext.CurrentDirectory, "Directory not in initial context"); TestExecutionContext.Save(); try { string otherDirectory = System.IO.Path.GetTempPath(); if (otherDirectory[otherDirectory.Length - 1] == System.IO.Path.DirectorySeparatorChar) { otherDirectory = otherDirectory.Substring(0, otherDirectory.Length - 1); } TestExecutionContext.CurrentContext.CurrentDirectory = otherDirectory; Assert.AreEqual(otherDirectory, Environment.CurrentDirectory, "Directory was not set"); Assert.AreEqual(otherDirectory, TestExecutionContext.CurrentContext.CurrentDirectory, "Directory not in new context"); } finally { TestExecutionContext.Restore(); } Assert.AreEqual(currentDirectory, Environment.CurrentDirectory, "Directory was not restored"); Assert.AreEqual(currentDirectory, TestExecutionContext.CurrentContext.CurrentDirectory, "Directory not in final context"); }
public static TestResult Execute(TestCommand command) { TestExecutionContext.Save(); TestExecutionContext currentContext = TestExecutionContext.CurrentContext; currentContext.CurrentTest = command.Test; currentContext.CurrentResult = command.Test.MakeTestResult(); currentContext.Listener.TestStarted(command.Test); long ticks = DateTime.Now.Ticks; TestResult testResult; try { TestSuiteCommand testSuiteCommand = command as TestSuiteCommand; testResult = ((testSuiteCommand == null) ? command.Execute(currentContext) : ExecuteSuiteCommand(testSuiteCommand, currentContext)); testResult.AssertCount = currentContext.AssertCount; long ticks2 = DateTime.Now.Ticks; double num2 = (testResult.Time = (double)(ticks2 - ticks) / 10000000.0); currentContext.Listener.TestFinished(testResult); } catch (Exception ex) { if (ex is ThreadAbortException) { Thread.ResetAbort(); } currentContext.CurrentResult.RecordException(ex); return(currentContext.CurrentResult); } finally { TestExecutionContext.Restore(); } return(testResult); }
public static TestResult RunTestFixture(Type type) { TestSuite suite = MakeFixture(type); TestCommand command = suite.GetTestCommand(TestFilter.Empty); TestExecutionContext.Save(); TestExecutionContext.CurrentContext.TestObject = null; try { return(CommandRunner.Execute(command)); } finally { TestExecutionContext.Restore(); } }
public static ITestResult RunTest(Test test, object testObject) { TestCommand command = test.GetTestCommand(TestFilter.Empty); //TestExecutionContext context = new TestExecutionContext(); //context.TestObject = testObject; TestExecutionContext.Save(); TestExecutionContext.CurrentContext.TestObject = testObject; try { return(CommandRunner.Execute(command)); } finally { TestExecutionContext.Restore(); } }
public static TestResult RunTestFixture(object fixture) { TestSuite suite = MakeFixture(fixture); TestCommand command = suite.GetTestCommand(TestFilter.Empty); //TestExecutionContext context = new TestExecutionContext(); //context.TestObject = fixture; TestExecutionContext.Save(); TestExecutionContext.CurrentContext.TestObject = fixture; try { return(CommandRunner.Execute(command)); } finally { TestExecutionContext.Restore(); } }
public void SetAndRestoreCurrentPrincipal() { Assert.AreEqual(currentPrincipal, TestExecutionContext.CurrentContext.CurrentPrincipal, "Principal not in initial context"); TestExecutionContext.Save(); try { GenericIdentity identity = new GenericIdentity("foo"); TestExecutionContext.CurrentContext.CurrentPrincipal = new GenericPrincipal(identity, new string[0]); Assert.AreEqual("foo", Thread.CurrentPrincipal.Identity.Name, "Principal was not set"); Assert.AreEqual("foo", TestExecutionContext.CurrentContext.CurrentPrincipal.Identity.Name, "Principal not in new context"); } finally { TestExecutionContext.Restore(); } Assert.AreEqual(currentPrincipal, Thread.CurrentPrincipal, "Principal was not restored"); Assert.AreEqual(currentPrincipal, TestExecutionContext.CurrentContext.CurrentPrincipal, "Principal not in final context"); }
public void SetAndRestoreCurrentUICulture() { Assert.AreEqual(currentUICulture, TestExecutionContext.CurrentContext.CurrentUICulture, "UICulture not in initial context"); TestExecutionContext.Save(); try { CultureInfo otherCulture = new CultureInfo(currentUICulture.Name == "fr-FR" ? "en-GB" : "fr-FR"); TestExecutionContext.CurrentContext.CurrentUICulture = otherCulture; Assert.AreEqual(otherCulture, CultureInfo.CurrentUICulture, "UICulture was not set"); Assert.AreEqual(otherCulture, TestExecutionContext.CurrentContext.CurrentUICulture, "UICulture not in new context"); } finally { TestExecutionContext.Restore(); } Assert.AreEqual(currentUICulture, CultureInfo.CurrentUICulture, "UICulture was not restored"); Assert.AreEqual(currentUICulture, TestExecutionContext.CurrentContext.CurrentUICulture, "UICulture not in final context"); }
private void RunTest() { _context.CurrentTest = this.Test; _context.CurrentResult = this.Result; _context.Listener.TestStarted(this.Test); _context.StartTime = DateTime.Now; TestExecutionContext.SetCurrentContext(_context); try { PerformWork(); } finally { Result.AssertCount = _context.AssertCount; Result.Time = (DateTime.Now - _context.StartTime).TotalSeconds; _context.Listener.TestFinished(Result); _context = _context.Restore(); _context.AssertCount += Result.AssertCount; } }
/// <summary> /// Runs a TestCommand, sending notifications to a listener. /// </summary> /// <param name="command">A TestCommand to be executed.</param> /// <param name="context">The context in which to execute the command.</param> /// <returns>A TestResult.</returns> public static TestResult Execute(TestCommand command) { TestResult testResult; TestExecutionContext.Save(); TestExecutionContext context = TestExecutionContext.CurrentContext; //context = new TestExecutionContext(context); context.CurrentTest = command.Test; context.CurrentResult = command.Test.MakeTestResult(); context.Listener.TestStarted(command.Test); long startTime = DateTime.Now.Ticks; try { TestSuiteCommand suiteCommand = command as TestSuiteCommand; if (suiteCommand != null) { testResult = ExecuteSuiteCommand(suiteCommand, context); } //{ // suiteCommand.DoOneTimeSetup(); // foreach (TestCommand childCommand in suiteCommand.Children) // Execute(childCommand, context); // suiteCommand.DoOneTimeTearDown(); //} else { testResult = command.Execute(context); } testResult.AssertCount = context.AssertCount; long stopTime = DateTime.Now.Ticks; double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond; testResult.Time = time; context.Listener.TestFinished(testResult); } catch (Exception ex) { #if !NETCF if (ex is ThreadAbortException) { Thread.ResetAbort(); } #endif context.CurrentResult.RecordException(ex); return(context.CurrentResult); } finally { TestExecutionContext.Restore(); //context.ReverseChanges(); //context = context.prior; } return(testResult); }