private static ScenarioTestCase CreateScenarioTestCase(string skipReason = null)
        {
            var testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases),
                                                   nameof(XunitExtensionsTestCases.Method_with_one_scenario));
            var scenarioIdentifier = TestScenarioDiscoverer.CreateScenarioIdentifier(testMethod);

            var target = new ScenarioTestCase(new NullMessageSink(), TestMethodDisplay.ClassAndMethod,
                                              TestMethodDisplayOptions.All, testMethod, scenarioIdentifier, skipReason);

            return(target);
        }
Beispiel #2
0
        protected override bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus,
                                                 ITestFrameworkDiscoveryOptions discoveryOptions)
        {
            if (!IsSpecFlowTest(testClass))
            {
                return(base.FindTestsForType(testClass, includeSourceInformation, messageBus, discoveryOptions));
            }

            var featureTestClass = (SpecFlowFeatureTestClass)testClass;
            var gherkinDocument  = featureTestClass.GetDocument();

            if (gherkinDocument?.SpecFlowFeature != null)
            {
                featureTestClass.FeatureName = gherkinDocument.SpecFlowFeature.Name;
                var featureTags = gherkinDocument.SpecFlowFeature.Tags.GetTags().ToArray();
                foreach (var scenarioDefinition in gherkinDocument.SpecFlowFeature.ScenarioDefinitions.Where(sd => !(sd is Background)))
                {
                    var scenario = scenarioDefinition as Scenario;
                    if (scenario != null)
                    {
                        var scenarioTestCase = new ScenarioTestCase(featureTestClass, scenario, featureTags);
                        if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(scenarioTestCase)))
                        {
                            return(false);
                        }
                    }
                    var scenarioOutline = scenarioDefinition as ScenarioOutline;
                    if (scenarioOutline != null)
                    {
                        foreach (var example in scenarioOutline.Examples)
                        {
                            foreach (var exampleRow in example.TableBody)
                            {
                                var parameters = SpecFlowParserHelper.GetScenarioOutlineParameters(example, exampleRow);
                                var scenarioOutlineTestCase = new ScenarioTestCase(featureTestClass, scenarioOutline, featureTags, parameters, SpecFlowParserHelper.GetExampleRowId(scenarioOutline, exampleRow), exampleRow.Location);
                                if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(scenarioOutlineTestCase)))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }