Example #1
0
        public virtual void OnAfterLastStep()
        {
            HandleBlockSwitch(ScenarioBlock.None);

            if (_specFlowConfiguration.TraceTimings)
            {
                _contextManager.ScenarioContext.Stopwatch.Stop();
                var duration = _contextManager.ScenarioContext.Stopwatch.Elapsed;
                _testTracer.TraceDuration(duration, "Scenario: " + _contextManager.ScenarioContext.ScenarioInfo.Title);
            }

            var testResultResult = _testResultFactory.BuildFromContext(_contextManager.ScenarioContext, _contextManager.FeatureContext);

            switch (testResultResult)
            {
            case ISuccess <TestResult> success:
                _cucumberMessageSender.SendTestCaseFinished(_contextManager.ScenarioContext.ScenarioInfo, success.Result);
                _testRunResultCollector.CollectTestResultForScenario(_contextManager.ScenarioContext.ScenarioInfo, success.Result);
                break;

            case IFailure failure:
                _testTracer.TraceWarning(failure.ToString());
                break;
            }

            if (_contextManager.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.OK)
            {
                return;
            }

            if (_contextManager.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.Skipped)
            {
                _unitTestRuntimeProvider.TestIgnore("Scenario ignored using @Ignore tag");
                return;
            }

            if (_contextManager.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.StepDefinitionPending)
            {
                string pendingStepExceptionMessage = _testPendingMessageFactory.BuildFromScenarioContext(_contextManager.ScenarioContext);
                _errorProvider.ThrowPendingError(_contextManager.ScenarioContext.ScenarioExecutionStatus, pendingStepExceptionMessage);
                return;
            }

            if (_contextManager.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.UndefinedStep)
            {
                string undefinedStepExceptionMessage = _testUndefinedMessageFactory.BuildFromContext(_contextManager.ScenarioContext, _contextManager.FeatureContext);
                _errorProvider.ThrowPendingError(_contextManager.ScenarioContext.ScenarioExecutionStatus, undefinedStepExceptionMessage);
                return;
            }

            if (_contextManager.ScenarioContext.TestError == null)
            {
                throw new InvalidOperationException("test failed with an unknown error");
            }

            _contextManager.ScenarioContext.TestError.PreserveStackTrace();
            throw _contextManager.ScenarioContext.TestError;
        }
Example #2
0
        public IResult <TestResult> BuildFromContext(ScenarioContext scenarioContext, FeatureContext featureContext)
        {
            if (scenarioContext is null)
            {
                return(Result <TestResult> .Failure(new ArgumentNullException(nameof(scenarioContext))));
            }

            ulong nanoseconds = ConvertTicksToPositiveNanoseconds(scenarioContext.Stopwatch.Elapsed.Ticks);

            switch (scenarioContext.ScenarioExecutionStatus)
            {
            case ScenarioExecutionStatus.OK: return(BuildPassedResult(nanoseconds));

            case ScenarioExecutionStatus.TestError: return(BuildFailedResult(nanoseconds, _testErrorMessageFactory.BuildFromScenarioContext(scenarioContext)));

            case ScenarioExecutionStatus.StepDefinitionPending: return(BuildPendingResult(nanoseconds, _testPendingMessageFactory.BuildFromScenarioContext(scenarioContext)));

            case ScenarioExecutionStatus.BindingError: return(BuildAmbiguousResult(nanoseconds, _testAmbiguousMessageFactory.BuildFromScenarioContext(scenarioContext)));

            case ScenarioExecutionStatus.UndefinedStep: return(BuildUndefinedResult(nanoseconds, _testUndefinedMessageFactory.BuildFromContext(scenarioContext, featureContext)));

            default: return(Result <TestResult> .Failure($"Status '{scenarioContext.ScenarioExecutionStatus}' is unknown or not supported."));
            }
        }
 public IResult <TestResult> BuildPendingResult(ulong durationInNanoseconds, ScenarioContext scenarioContext)
 {
     return(BuildTestResult(durationInNanoseconds, Status.Pending, _testPendingMessageFactory.BuildFromScenarioContext(scenarioContext)));
 }