コード例 #1
0
        private void GenerateScenarioOutlineTestVariant(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline, CodeMemberMethod scenatioOutlineTestMethod,
                                                        IEnumerable <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle, string exampleSetIdentifier,
                                                        GherkinTableRow row, Tags exampleSetTags, string variantName)
        {
            var variantNameIdentifier = variantName.ToIdentifier().TrimStart('_');

            CodeMemberMethod testMethod = CreateTestMethod(generationContext, scenarioOutline, exampleSetTags);

            testMethod.Name = string.IsNullOrEmpty(exampleSetIdentifier)
                ? string.Format("{0}_{1}", testMethod.Name, variantNameIdentifier)
                : string.Format("{0}_{1}_{2}", testMethod.Name, exampleSetIdentifier, variantNameIdentifier);

            //call test implementation with the params
            List <CodeExpression> argumentExpressions = row.Cells.Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList();

            argumentExpressions.Add(GetStringArrayExpression(exampleSetTags));

            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    scenatioOutlineTestMethod.Name,
                    argumentExpressions.ToArray()));

            var arguments = paramToIdentifier.Select((p2i, paramIndex) => new KeyValuePair <string, string>(p2i.Key, row.Cells[paramIndex].Value)).ToList();

            testGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioOutline.Title, exampleSetTitle, variantName, arguments);
        }
コード例 #2
0
        private void GenerateScenarioOutlineTestVariant(TestClassGenerationContext generationContext,
                                                        ScenarioOutline scenarioOutline, CodeMemberMethod scenatioOutlineTestMethod,
                                                        IEnumerable <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle,
                                                        string exampleSetIdentifier,
                                                        Gherkin.Ast.TableRow row, IEnumerable <Tag> exampleSetTags, string variantName)
        {
            CodeMemberMethod testMethod = CreateTestMethod(generationContext, scenarioOutline, exampleSetTags,
                                                           variantName, exampleSetIdentifier);

            //call test implementation with the params
            List <CodeExpression> argumentExpressions = row.Cells
                                                        .Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList();

            argumentExpressions.Add(GetStringArrayExpression(exampleSetTags));

            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    scenatioOutlineTestMethod.Name,
                    argumentExpressions.ToArray()));

            AddLineDirectiveHidden(testMethod.Statements);
            var arguments = paramToIdentifier.Select((p2i, paramIndex) =>
                                                     new KeyValuePair <string, string>(p2i.Key, row.Cells.ElementAt(paramIndex).Value)).ToList();

            _testGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioOutline.Name,
                                                      exampleSetTitle, variantName, arguments);
        }
コード例 #3
0
        private void GenerateScenarioOutlineTestVariant(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline, CodeMemberMethod scenatioOutlineTestMethod, IEnumerable <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle, string exampleSetIdentifier, Gherkin.Ast.TableRow row, IEnumerable <Tag> exampleSetTags, string variantName, string tag = null)
        {
            variantName = string.IsNullOrEmpty(tag) ? variantName : $"{variantName}_{tag}";
            var testMethod = CreateTestMethod(generationContext, scenarioOutline, exampleSetTags, variantName, exampleSetIdentifier);
            //_codeDomHelper.AddLineDirective(scenarioOutline, testMethod.Statements, _specFlowConfiguration);
            var list1 = new List <CodeExpression>();

            list1.AddRange(row.Cells.Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList());
            list1.Add(exampleSetTags.GetStringArrayExpression());

            //// NEW CODE START
            if (tag != null)
            {
                var s = new CodePrimitiveExpression(tag);
                list1.Add(s);
                _setVariantToContextForOutlineTest = true;
            }
            //// NEW CODE END

            testMethod.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), scenatioOutlineTestMethod.Name, list1.ToArray()));
            //_codeDomHelper.AddLineDirectiveHidden(testMethod.Statements, _specFlowConfiguration);
            var list2 = paramToIdentifier.Select((p2i, paramIndex) => new KeyValuePair <string, string>(p2i.Key, row.Cells.ElementAt(paramIndex).Value)).ToList();

            _testGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioOutline.Name, exampleSetTitle, variantName, list2);
        }
コード例 #4
0
 public void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod,
                                string scenarioTitle,
                                string exampleSetName, string variantName, IEnumerable <KeyValuePair <string, string> > arguments)
 {
     baseGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioTitle, exampleSetName,
                                              variantName, arguments);
 }
コード例 #5
0
        private void GenerateScenarioOutlineTestVariant(
            TestClassGenerationContext generationContext,
            ScenarioOutline scenarioOutline,
            CodeMemberMethod scenatioOutlineTestMethod,
            IEnumerable <KeyValuePair <string, string> > paramToIdentifier,
            string exampleSetTitle,
            string exampleSetIdentifier,
            Gherkin.Ast.TableRow row,
            IEnumerable <Tag> exampleSetTags,
            string variantName)
        {
            var testMethod = CreateTestMethod(generationContext, scenarioOutline, exampleSetTags, variantName, exampleSetIdentifier);


            //call test implementation with the params
            var argumentExpressions = row.Cells.Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList();

            argumentExpressions.Add(_scenarioPartHelper.GetStringArrayExpression(exampleSetTags));


            var statements = new List <CodeStatement>();

            using (new SourceLineScope(_specFlowConfiguration, _codeDomHelper, statements, generationContext.Document.SourceFilePath, scenarioOutline.Location))
            {
                statements.Add(new CodeExpressionStatement(
                                   new CodeMethodInvokeExpression(
                                       new CodeThisReferenceExpression(),
                                       scenatioOutlineTestMethod.Name,
                                       argumentExpressions.ToArray())));
            }


            testMethod.Statements.AddRange(statements.ToArray());

            //_linePragmaHandler.AddLineDirectiveHidden(testMethod.Statements);
            var arguments = paramToIdentifier.Select((p2i, paramIndex) => new KeyValuePair <string, string>(p2i.Key, row.Cells.ElementAt(paramIndex).Value)).ToList();

            // Use the identifier of the example set (e.g. ExampleSet0, ExampleSet1) if we have it.
            // Otherwise, use the title of the example set provided by the user in the feature file.
            string exampleSetName = string.IsNullOrEmpty(exampleSetIdentifier) ? exampleSetTitle : exampleSetIdentifier;

            _unitTestGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioOutline.Name, exampleSetName, variantName, arguments);
        }