public ITestResult Run(IIntent intent, ITestProvider provider) { if (provider.Ignored) { return(_resultFactory.CreateIgnoredTestResult(provider)); } _listener.OnTestStarted(intent); IOutputRecording outputRecording; var operationResults = new List <IOperationResult>(); var cleanupProviderStack = new Stack <IOperationProvider>(); var stopWatch = Stopwatch.StartNew(); using (outputRecording = _resultFactory.CreateOutputRecording()) { // TODO: Repetition with ContextRunner foreach (var operationProvider in provider.OperationProviders) { Trace.Assert( !cleanupProviderStack.Contains(operationProvider) || operationProvider == cleanupProviderStack.Pop(), string.Format("Cleanup ({0}) is not in order to setup.", operationProvider.Action)); var operationResult = _operationRunner.Run(operationProvider); operationResults.Add(operationResult); if (operationResult.State == State.Failed && operationResult.Type != OperationType.Assertion) { break; } if (operationProvider.CleanupProvider != null) { cleanupProviderStack.Push(operationProvider.CleanupProvider); } } Trace.Assert( !cleanupProviderStack.Any() || operationResults.Any(x => x.State == State.Failed), "Either cleanup stack must be empty, or any result must have failed."); operationResults.AddRange(cleanupProviderStack.Select(_operationRunner.Run)); } var result = _resultFactory.CreateTestResult(provider, stopWatch.Elapsed, outputRecording, operationResults); _listener.OnTestFinished(result); return(result); }
private ISuiteResult RunWithResourcesAcquired( IIntent intent, ISuiteProvider provider, IEnumerable <Tuple <IIntent, ISuiteProvider> > suitePairs, IEnumerable <Tuple <IIntent, ITestProvider> > testPairs) { _listener.OnSuiteStarted(intent, provider.Text); IOutputRecording outputRecording; IContextScope contextScope; ICollection <ISuiteResult> suiteResults = new ISuiteResult[0]; ICollection <ITestResult> testResults = new ITestResult[0]; using (outputRecording = _resultFactory.CreateOutputRecording()) { using (contextScope = _contextRunner.Run(provider.ContextProviders)) { if (contextScope.SetupResults.All(x => x.State == State.Passed)) { suiteResults = suitePairs.AsParallel() .WithDegreeOfParallelism(degreeOfParallelism: 1) .WithCancellation(_cancellationTokenSource.Token) .Select(x => Run(x.Item1, x.Item2)).ToList(); testResults = testPairs.AsParallel() .WithDegreeOfParallelism(degreeOfParallelism: 1) .WithCancellation(_cancellationTokenSource.Token) .Select(x => _testRunner.Run(x.Item1, x.Item2)).ToList(); } } } var result = _resultFactory.CreateSuiteResult( provider, outputRecording, contextScope.SetupResults, contextScope.CleanupResults, suiteResults, testResults); _listener.OnSuiteFinished(result); return(result); }