private void AddMultipleParameters(NodeStep step, string parameters)
        {
            char[] multipleParameterDelimiter = { ' ' };
            string[] arrayOfParameters = parameters.Split(multipleParameterDelimiter);
            bool foundTable = false;

            for (int i = 0; i < arrayOfParameters.Length; i += 2)
            {
                Parameter p = new Parameter();
                p.Type = arrayOfParameters[i];

                if (arrayOfParameters[i + 1].Contains(","))
                {
                    char[] commaTrim = { ',' };
                    string[] parameter = arrayOfParameters[i + 1].Split(commaTrim);
                    p.Name = parameter[0].TrimEnd();
                }
                else if (arrayOfParameters[i + 1].Contains(")"))
                {
                    char[] parenthesisTrim = { ')' };
                    string[] lastParameter = arrayOfParameters[i + 1].Split(parenthesisTrim);
                    p.Name = lastParameter[0].TrimEnd();
                }

                // don't add table parameters as step parameters
                if (p.Name == "table" || (p.Name == "rows" && p.Type == "int") || (p.Name == "cols" && p.Type == "int"))
                {
                    foundTable = true;
                }
                else
                {
                    step.Parameters.Add(p);
                }
            }

            if (foundTable)
            {
                step.Rows.Add(new string[] { string.Empty });
            }
        }
        public void StepGeneratorCreatesOneScenarioOneStepOneDecimalParameter()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            //Add parameter
            Parameter p1 = new Parameter();
            p1.Name = "Parameter1";
            p1.Type = "decimal";
            p1.Value = "2.1";

            //Add step
            NodeStep step1 = new NodeStep("GivenMethod1");
            step1.Parameters.Add(p1);

            //Add scenario
            NodeScenario scenario1 = new NodeScenario("Scenario1");
            scenario1.Steps.Add(step1);

            //Add feature
            NodeFeature feature1 = new NodeFeature("Feature1");
            feature1.Scenarios.Add(scenario1);
            features.Add(feature1);

            var files = GeneratorFactory.Generate(GeneratorType.StepDefinitionGenerator, features);

            string[] stringsExpected = new string[] {
                "#include \"Feature1.h\"",
                "",
                "namespace CppUnitTest",
                "{",
                "\tvoid Feature1::GivenMethod1(decimal Parameter1)",
                "\t{",
                "\t\tAssert::Fail(L\"Pending implementation...\");",
                "\t}",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
Beispiel #3
0
        private Parameter CreateParameter(int id, string parameterValueFromFeatureFile)
        {
            string parameterValueToCodeGenerator;
            bool isFromExampleTable = false;
            if (parameterValueFromFeatureFile.Contains(EnumNames.tickOpen))
            {
                parameterValueToCodeGenerator = parameterValueFromFeatureFile.Substring(1, parameterValueFromFeatureFile.Length - 2);
                isFromExampleTable = true;
            }
            else
            {
                parameterValueToCodeGenerator = parameterValueFromFeatureFile;
                isFromExampleTable = false;
            }

            var p = new Parameter()
            {
                Name = string.Format("p{0}", id),
                Type = GetParameterType(isFromExampleTable, parameterValueToCodeGenerator),
                Value = parameterValueToCodeGenerator,
                IsFromExampleTable = isFromExampleTable
            };
            return p;
        }
        public void HeaderGeneratorCreatesOneFeatureWithOneTableAndOneParameter()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();
            List<NodeHook> featureHooks = new List<NodeHook>();

            //Create parameter & add
            Parameter p1 = new Parameter();
            p1.Name = "MyParameter1";
            p1.Type = "string";
            p1.Value = "ValueOfMyParameter1";

            //Create step & add
            NodeStep step1 = new NodeStep("GivenStep1WithTable");
            step1.Parameters.Add(p1);
            step1.Rows = new List<string[]> {
                new [] { "a", "b", "c" },
                new [] { "1", "2", "3" }
            };

            //Create scenario & add
            NodeScenario scenario1 = new NodeScenario("MyScenario1", new List<NodeHook>() { new NodeHook("MyFeatureHook1"), new NodeHook("MyScenarioHook1") });
            scenario1.Steps.Add(step1);

            //Create feature & add
            NodeFeature feature1 = new NodeFeature("MyFeature1", new List<NodeHook>() { new NodeHook("MyFeatureHook1") });
            feature1.Scenarios.Add(scenario1);
            features.Add(feature1);

            //Call output generator
            var files = GeneratorFactory.Generate(GeneratorType.HeaderGenerator, features);

            string[] stringsExpected = new string[] {
                "#include \"CppUnitTest.h\"",
                "#include \"CppUnitTestHooks.h\"",
                "#include \"trim.hpp\"",
                "#include <vector>",
                "",
                "using namespace Microsoft::VisualStudio::CppUnitTestFramework;",
                "using namespace std;",
                "",
                "namespace CppUnitTest",
                "{",
                "\tTEST_CLASS(MyFeature1)",
                "\t{",
                "\tpublic:",
                "\t\tTEST_CLASS_HOOK_MYFEATUREHOOK1()",
                "\t\tTEST_METHOD_HOOK_MYFEATUREHOOK1_MYSCENARIOHOOK1(MyScenario1);",
                "",
                "\tprivate:",
                "\t\tvoid GivenStep1WithTable(std::vector<std::vector<std::string>> table, int rows, int cols, string MyParameter1);",
                "\t};",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void HeaderGeneratorCreatesOneFeatureOneScenarioOneStepAndTwoParameters()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            //Creates Gherkin Step 1
            TokenGherkinStep tokenStep1 = new TokenGherkinStep();
            tokenStep1.MethodName = "GivenMethod1";
            List<string> tokenParameters1 = new List<string>();
            string parameter1 = "";
            tokenParameters1.Add(parameter1);
            tokenStep1.ParameterTokens = tokenParameters1;

            //Creates Parameter For Step 1
            Parameter p1 = new Parameter();
            p1.Name = "Parameter1";
            p1.Type = "string";
            p1.Value = "ValueOfParameter1";
            Parameter p2 = new Parameter();
            p2.Name = "Parameter2";
            p2.Type = "int";
            p2.Value = "2";

            //Creates Step 1 & Adds to list
            NodeStep step1 = new NodeStep("GivenMethod1");
            step1.Parameters.Add(p1);
            step1.Parameters.Add(p2);

            //Creates Scenario 1
            NodeScenario scenario1 = new NodeScenario("TestScenario1");
            scenario1.Steps.Add(step1);

            //Creates Feature & Adds to list
            NodeFeature feature = new NodeFeature("TestFeature1");
            feature.Scenarios.Add(scenario1);
            features.Add(feature);

            var files = GeneratorFactory.Generate(GeneratorType.HeaderGenerator, features);

            string[] stringsExpected = new string[] {
                "#include \"CppUnitTest.h\"",
                "#include \"CppUnitTestHooks.h\"",
                "#include \"trim.hpp\"",
                "#include <vector>",
                "",
                "using namespace Microsoft::VisualStudio::CppUnitTestFramework;",
                "using namespace std;",
                "",
                "namespace CppUnitTest",
                "{",
                "\tTEST_CLASS(TestFeature1)",
                "\t{",
                "\tpublic:",
                "\t\tTEST_METHOD(TestScenario1);",
                "",
                "\tprivate:",
                "\t\tvoid GivenMethod1(string Parameter1, int Parameter2);",
                "\t};",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        private void AddOneParameter(NodeStep step, string parameter)
        {
            char[] oneParameterDelimiter = { ' ', ')' };
            string[] oneParameter = parameter.Split(oneParameterDelimiter);

            Parameter p = new Parameter();
            p.Type = oneParameter[0];
            p.Name = oneParameter[1];
            step.Parameters.Add(p);
        }
        public void StepGeneratorCreatesOneScenarioOneStepTwoParametersAndOneRow()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            //Add parameter 1
            Parameter p1 = new Parameter();
            p1.Name = "Parameter1";
            p1.Type = "string";
            p1.Value = "ValueOfParameter1";

            //Add parameter 2
            Parameter p2 = new Parameter();
            p2.Name = "Parameter2";
            p2.Type = "int";
            p2.Value = "2";

            //Add step
            NodeStep step1 = new NodeStep("GivenMethod1");
            step1.Parameters.Add(p1);
            step1.Parameters.Add(p2);
            step1.Rows = new List<string[]> {
                new string[] { "a", "b", "c" }
            };

            //Add scenario
            NodeScenario scenario1 = new NodeScenario("Scenario1");
            scenario1.Steps.Add(step1);

            //Add feature
            NodeFeature feature1 = new NodeFeature("Feature1");
            feature1.Scenarios.Add(scenario1);
            features.Add(feature1);

            var files = GeneratorFactory.Generate(GeneratorType.StepDefinitionGenerator, features);

            string[] stringsExpected = new string[] {
                "#include \"Feature1.h\"",
                "",
                "namespace CppUnitTest",
                "{",
                "\tvoid Feature1::GivenMethod1(std::vector<std::vector<std::string>> table, int rows, int cols, string Parameter1, int Parameter2)",
                "\t{",
                "\t\tAssert::Fail(L\"Pending implementation...\");",
                "\t}",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }