Exemplo n.º 1
0
        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);
        }