Esempio n. 1
0
        public void RunGherkinBasedTests(IMessageSerializer messageSerializer)
        {
            WriteOutput($"Starting Gherkin-based tests with serializer: {messageSerializer.GetType().Name}");
            Gremlin.InstantiateTranslationsForTestRun();
            var stepDefinitionTypes = GetStepDefinitionTypes();
            var results             = new List <ResultFeature>();

            using var scenarioData   = new ScenarioData(messageSerializer);
            CommonSteps.ScenarioData = scenarioData;
            foreach (var feature in GetFeatures())
            {
                var resultFeature = new ResultFeature(feature);
                results.Add(resultFeature);
                foreach (var child in feature.Children)
                {
                    var scenario    = (Scenario)child;
                    var failedSteps = new Dictionary <Step, Exception>();
                    resultFeature.Scenarios[scenario] = failedSteps;
                    if (IgnoredScenarios.TryGetValue(scenario.Name, out var reason))
                    {
                        failedSteps.Add(scenario.Steps.First(), new IgnoreException(reason));
                        continue;
                    }

                    StepBlock?     currentStep    = null;
                    StepDefinition stepDefinition = null;
                    foreach (var step in scenario.Steps)
                    {
                        var previousStep = currentStep;
                        currentStep = GetStepBlock(currentStep, step.Keyword);
                        if (currentStep == StepBlock.Given && previousStep != StepBlock.Given)
                        {
                            stepDefinition = GetStepDefinitionInstance(stepDefinitionTypes, step.Text);
                        }

                        if (stepDefinition == null)
                        {
                            throw new NotSupportedException(
                                      $"Step '{step.Text} not supported without a 'Given' step first");
                        }

                        scenarioData.CurrentScenario = scenario;
                        var result = ExecuteStep(stepDefinition, currentStep.Value, step);
                        if (result != null)
                        {
                            failedSteps.Add(step, result);
                            // Stop processing scenario
                            break;
                        }
                    }
                }
            }

            OutputResults(results);
            WriteOutput($"Finished Gherkin-based tests with serializer: {messageSerializer.GetType().Name}.");
        }
Esempio n. 2
0
        public MessagePublisher(Lazy <IEventStoreConnection> lazyConnection, string streamName, IMessageSerializer serializer,
                                Func <TMessage, Dictionary <string, string> > propertyProvider)
        {
            _propertySerializer = new JsonPropertySerializer();
            _lazyConnection     = lazyConnection;
            _streamName         = streamName;
            _serializer         = serializer;
            _propertyProvider   = propertyProvider;
            _setProperties      = propertyProvider != null;

            _isJsonSerializer = _serializer.GetType().FullName.ToUpperInvariant().Contains("JSON");
        }