Example #1
0
 public NodeStep(TokenGherkinStep tokens)
 {
     Name = tokens.MethodName;
     Rows = new List<string[]>();
     MapParameters(tokens.ParameterTokens);
 }
        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 static TokenGherkinStep TokenizeGherkinStep(string gherkinStep, string delimiterOpen, string delimiterClose, bool includeDelimits)
        {
            var sentenceTokens = new List<string>();
            var parameterTokens = new List<string>();
            int posStart = 0;
            bool isOpenTick = false;
            while (posStart >= 0 && posStart < gherkinStep.Length)
            {
                int posTick = isOpenTick ? FindPositionOfTick(gherkinStep, posStart, delimiterClose) : FindPositionOfTick(gherkinStep, posStart, delimiterOpen);

                if (!isOpenTick)
                {
                    int length = posTick - posStart;
                    if (length > 0) // no sentence token if parameters are back to back (it's an empty string)
                    {
                        if (includeDelimits)
                        {
                            posStart = Math.Max(posStart - delimiterOpen.Length, 0);
                            sentenceTokens.Add(CapitalCamelCase(gherkinStep.Substring(posStart, (posTick - posStart) - delimiterOpen.Length)));
                        }
                        else
                        {
                            sentenceTokens.Add(CapitalCamelCase(gherkinStep.Substring(posStart, posTick - posStart)));
                        }
                    }
                }
                else
                {
                    if (includeDelimits)
                    {
                        parameterTokens.Add(gherkinStep.Substring(posStart - delimiterOpen.Length, (posTick - posStart) + (delimiterOpen.Length + delimiterClose.Length)));
                    }
                    else
                    {
                        parameterTokens.Add(gherkinStep.Substring(posStart, posTick - posStart));
                    }
                }
                posStart = posTick + (isOpenTick ? delimiterClose.Length : delimiterOpen.Length);
                isOpenTick = !isOpenTick;
            }
            TokenGherkinStep tokens = new TokenGherkinStep();
            tokens.MethodName = string.Join(string.Empty, sentenceTokens);
            tokens.ParameterTokens = parameterTokens;
            return tokens;
        }
Example #4
0
 public NodeStep(TokenGherkinStep tokens)
 {
     Name = tokens.MethodName;
     Rows = new List <string[]>();
     MapParameters(tokens.ParameterTokens);
 }
        private static TokenGherkinStep ParameterWasNotEscapedBySingleQuote(string gherkinStep)
        {
            TokenGherkinStep tokens;
            if (gherkinStep.Contains(EnumNames.tickOpen))
            {
                return TokenizeGherkinStep(gherkinStep, EnumNames.tickOpen, EnumNames.tickClose, true);
            }

            tokens = new TokenGherkinStep();
            tokens.MethodName = CapitalCamelCase(gherkinStep);
            tokens.ParameterTokens = new List<string>();
            return tokens;
        }