private void InvokeStep(ITestRunStep step, TestRunExecutionContext context, TestRunResult result, ITestRunLogger logger) { context.Step = step; try { step.Run(context); } catch (TestRunAssertException) { result.AddStep(new TestRunStepResult(context.StepNumber, step.ToString(), false)); throw; } catch (Exception ex) { result.IsSuccess = false; if (context.FirstException == null) { result.FailException = ex; context.FirstException = ex; } else { context.LastException = ex; } } result.AddStep(new TestRunStepResult(context.StepNumber, step.ToString(), result.IsSuccess)); }
private TestRunResult RunInternal(TestRun testRun, ITestRunLogger logger, out TestRunExecutionContext context) { if (testRun == null) { throw new ArgumentNullException(nameof(testRun)); } if (logger == null) { logger = new ConsoleTestRunLogger(); } logger.LogWithTime($"Started to run \"{testRun.Name}\" test."); context = new TestRunExecutionContext { StartedAt = DateTime.Now, Logger = logger }; Initialize(context); context.Logger.LogWithTime("Run OnBeforeTestRun."); OnBeforeTestRun(context); var result = new TestRunResult(testRun.Name); context.Logger.LogWithTime("Run Test."); InvokeTestRun(testRun, context, result, logger); return(result); }
private void InvokeTestRun(TestRun testRun, TestRunExecutionContext context, TestRunResult result, ITestRunLogger logger) { context.TestRun = testRun; context.ServiceProvider = ServiceProviderFactory.Create(); OnBeforeTestRun(context); try { int stepNumber = 1; foreach (ITestRunStep testRunStep in testRun.Steps) { context.StepNumber = stepNumber++; InvokeStep(testRunStep, context, result, logger); } } finally { context.Step = null; var disposableServiceProvider = context.ServiceProvider as IDisposable; disposableServiceProvider?.Dispose(); OnAfterTestRun(context); } }