Esempio n. 1
0
        private async Task ExecuteSteps(
            IServiceProvider serviceProvider,
            TestResult testResult,
            IEnumerable <IStep> steps,
            DiscoveredTestData testData,
            TestRunContext testRunContext)
        {
            var scenarioExecutionStartTime = DateTime.UtcNow;
            var stepsIterator = new StepsIterator(steps);

            foreach (var step in stepsIterator.Iterate())
            {
                testResult.Messages.Add(
                    new TestResultMessage(
                        TestResultMessage.StandardOutCategory,
                        $"{step.Title}{Environment.NewLine}"));

                var stepBinding       = stepBinder.GetBindingFor(step, testData.Assembly);
                var executionStrategy = StepExecutionStrategyFactory.GetFor(stepBinding);

                try
                {
                    await executionStrategy
                    .Execute(stepBinding, serviceProvider, testResult.Messages, testRunContext)
                    .ConfigureAwait(false);

                    testResult.Messages.Add(
                        new TestResultMessage(
                            TestResultMessage.StandardOutCategory,
                            $"{StepLogIndent}Completed at {DateTime.UtcNow:o}{Environment.NewLine}{Environment.NewLine}"));
                }
                catch (Exception exception)
                {
                    if (ScenarioFailureIsTerminal(
                            testData.Scenario,
                            scenarioExecutionStartTime,
                            stepsIterator))
                    {
                        testResult.Messages.Add(
                            new TestResultMessage(
                                TestResultMessage.StandardOutCategory,
                                $"{StepLogIndent}Failed at {DateTime.UtcNow:o}{Environment.NewLine}{Environment.NewLine}"));

                        testResult.Messages.Add(
                            new TestResultMessage(
                                TestResultMessage.StandardErrorCategory,
                                $"{exception}{Environment.NewLine}"));

                        throw;
                    }

                    testResult.Messages.Add(
                        new TestResultMessage(
                            TestResultMessage.StandardOutCategory,
                            $"{StepLogIndent}Failed at {DateTime.UtcNow:o}, waiting and retrying scenario from last When step{Environment.NewLine}"));

                    await Task.Delay(testData.Scenario.EventuallyConsistentConfiguration.RetryInterval).ConfigureAwait(false);
                }
            }
        }
Esempio n. 2
0
        private bool TryGoToMostRecentWhenStep(StepsIterator stepsIterator)
        {
            try
            {
                stepsIterator.GoToMostRecentWhenStep();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        private bool ScenarioFailureIsTerminal(Scenario scenario, DateTime scenarioExecutionStartTime, StepsIterator stepsIterator)
        {
            if (!scenario.IsEventuallyConsistent ||
                scenario.EventuallyConsistentConfiguration == null ||
                DateTime.UtcNow >= scenarioExecutionStartTime.Add(scenario.EventuallyConsistentConfiguration.Within) ||
                !TryGoToMostRecentWhenStep(stepsIterator))
            {
                return(true);
            }

            return(false);
        }