コード例 #1
0
        private ParameterSubstitution CreateParamToIdentifierMapping(ScenarioOutline scenarioOutline)
        {
            ParameterSubstitution paramToIdentifier = new ParameterSubstitution();

            foreach (var param in scenarioOutline.Examples.First().TableHeader.Cells)
            {
                paramToIdentifier.Add(param.Value, param.Value.ToIdentifierCamelCase());
            }
            return(paramToIdentifier);
        }
コード例 #2
0
        private void GenerateScenarioOutlineTest(CodeTypeDeclaration testType, CodeMemberMethod testSetup, ScenarioOutline scenarioOutline, Feature feature)
        {
            string testMethodName = string.Format(TEST_FORMAT, scenarioOutline.Title.ToIdentifier());

            ParameterSubstitution paramToIdentifier = new ParameterSubstitution();

            foreach (var param in scenarioOutline.Examples.ExampleSets[0].Table.Header.Cells)
            {
                paramToIdentifier.Add(param.Value, param.Value.ToIdentifierCamelCase());
            }

            if (scenarioOutline.Examples.ExampleSets.Length > 1)
            {
                //TODO: check params
            }

            var testMethod = GenerateScenarioOutlineBody(feature, scenarioOutline, paramToIdentifier, testType, testMethodName, testSetup);

            if (testGeneratorProvider.SupportsRowTests && this.allowRowTests)
            {
                SetTestMethodDeclaration(testMethod, scenarioOutline, null, rowTest: true);

                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        IEnumerable <string> arguments = exampleSet.Table.Body[rowIndex].Cells.Select(c => c.Value);
                        testGeneratorProvider.SetRow(testMethod, arguments, GetNonIgnoreTags(exampleSet.Tags), HasIgnoreTag(exampleSet.Tags));
                    }
                }
            }
            else
            {
                int exampleSetIndex = 0;
                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    string exampleSetTitle = exampleSet.Title == null
                        ? string.Format("Scenarios{0}", exampleSetIndex + 1)
                        : exampleSet.Title.ToIdentifier();

                    bool useFirstColumnAsName = CanUseFirstColumnAsName(exampleSet.Table);

                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        string variantName = useFirstColumnAsName ? exampleSet.Table.Body[rowIndex].Cells[0].Value.ToIdentifierPart() :
                                             string.Format("Variant{0}", rowIndex);
                        GenerateScenarioOutlineTestVariant(testType, scenarioOutline, testMethodName, paramToIdentifier, exampleSetTitle, exampleSet.Table.Body[rowIndex], exampleSet.Tags, variantName, exampleSet);
                    }
                    exampleSetIndex++;
                }
            }
        }
コード例 #3
0
        private void GenerateScenarioOutlineTest(CodeTypeDeclaration testType, CodeMemberMethod testSetup, ScenarioOutline scenarioOutline, Feature feature)
        {
            string testMethodName = string.Format(TEST_FORMAT, scenarioOutline.Title.ToIdentifier());

            ParameterSubstitution paramToIdentifier = new ParameterSubstitution();

            foreach (var param in scenarioOutline.Examples.ExampleSets[0].Table.Header.Cells)
            {
                paramToIdentifier.Add(param.Value, param.Value.ToIdentifierCamelCase());
            }

            if (scenarioOutline.Examples.ExampleSets.Length > 1)
            {
                //check params
                if (scenarioOutline.Examples.ExampleSets.Skip(1)
                    .Select(exampleSet => exampleSet.Table.Header.Cells.Select(c => c.Value))
                    .Any(paramNames => !paramNames.SequenceEqual(paramToIdentifier.Select(p2i => p2i.Key))))
                {
                    throw new TestGeneratorException("The example sets must provide the same parameters.");
                }
            }

            var testMethod = GenerateScenarioOutlineBody(feature, scenarioOutline, paramToIdentifier, testType, testMethodName, testSetup);

            if (testGeneratorProvider.SupportsRowTests && this.allowRowTests)
            {
                SetTestMethodDeclaration(testMethod, scenarioOutline, null, rowTest: true);

                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        IEnumerable <string> arguments = exampleSet.Table.Body[rowIndex].Cells.Select(c => c.Value);
                        testGeneratorProvider.SetRow(testMethod, arguments, GetNonIgnoreTags(exampleSet.Tags), HasIgnoreTag(exampleSet.Tags));
                    }
                }
            }
            else
            {
                int exampleSetIndex = 0;
                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    bool   useFirstColumnAsName = CanUseFirstColumnAsName(exampleSet.Table);
                    string exampleSetIdentifier = string.IsNullOrEmpty(exampleSet.Title)
                        ? scenarioOutline.Examples.ExampleSets.Count(es => string.IsNullOrEmpty(es.Title)) > 1
                            ? string.Format("ExampleSet {0}", exampleSetIndex).ToIdentifier()
                            : null
                        : exampleSet.Title.ToIdentifier();

                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        string variantName = useFirstColumnAsName ?
                                             exampleSet.Table.Body[rowIndex].Cells[0].Value :
                                             string.Format("Variant {0}", rowIndex);

                        GenerateScenarioOutlineTestVariant(testType, scenarioOutline, testMethodName, paramToIdentifier, exampleSet.Title ?? "", exampleSetIdentifier, exampleSet.Table.Body[rowIndex], exampleSet.Tags, variantName);
                    }
                    exampleSetIndex++;
                }
            }
        }