public void HeaderGeneratorCreatesOneFeatureAndTwoScenarios()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            NodeFeature featureScenario = new NodeFeature("TestFeature1");
            featureScenario.Scenarios.Add(new NodeScenario("TestScenario1"));
            featureScenario.Scenarios.Add(new NodeScenario("TestScenario2"));

            features.Add(featureScenario);

            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);",
                "\t\tTEST_METHOD(TestScenario2);",
                "\t};",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        private void BuildTestClass(NodeFeature feature)
        {
            List<string> privateContents = new List<string>();
            List<string> publicContents = new List<string>();
            List<NodeStep> filterUniqueSteps = new List<NodeStep>();

            foreach (var scenario in feature.Scenarios)
            {
                AddScenario(scenario, feature.Hooks, publicContents);
                if ((scenario.Steps.Count > 0) && (feature.Scenarios.First() == scenario))
                {
                    OpenTestClassPrivateSection(privateContents);
                }
                AddSteps(GeneratorHelper.FindUniqueSteps(filterUniqueSteps, scenario.Steps), scenario, privateContents);
            }

            OpenTestClassPublicSection(feature.Hooks);

            Contents.AddRange(publicContents);

            if (privateContents.Count > 0)
            {
                Contents.AddRange(privateContents);
            }
        }
        public void StepGeneratorCreatesOneScenarioOneStep()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

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

            //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()",
                "\t{",
                "\t\tAssert::Fail(L\"Pending implementation...\");",
                "\t}",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        protected override string[] BuildContents(NodeFeature feature)
        {
            BuildIncludeStatements(feature.Name);
            OpenNameSpace(LanguageConfig.NameSpace);
            BuildScenarioMethods(feature.Name, feature.Scenarios);
            CloseNameSpace();

            return Contents.ToArray();
        }
        public static IList<NodeFeature> FeatureWithScenarioAndNoStep()
        {
            IList<NodeFeature> features = new List<NodeFeature>();
            NodeFeature featureWithScenario = new NodeFeature("Feature1");
            NodeScenario scenario = new NodeScenario("Scenario1");
            featureWithScenario.Scenarios.Add(scenario);    // scenario to feature
            features.Add(featureWithScenario);              // feature to feature list

            return features;
        }
        protected override string[] BuildContents(NodeFeature feature)
        {
            BuildIncludeStatement();
            BuildHeaderStatement();
            OpenNameSpace();
            BuildStepClass(feature.Name, feature.Scenarios);
            CloseNameSpace();

            return Contents.ToArray();
        }
        public void HeaderGeneratorCreatesOneFeatureWithOneTable()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();
            List<NodeHook> featureHooks = new List<NodeHook>();

            List<string[]> rows = new List<string[]>();

            //Create row array & add
            string[] row1 = new string[] { "a", "b", "c" };
            string[] row2 = new string[] { "1", "2", "3" };
            rows.Add(row1);
            rows.Add(row2);

            //Create step & add
            NodeStep step1 = new NodeStep("GivenStep1WithTable");
            step1.Rows = rows;

            //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);",
                "\t};",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        protected override string[] BuildContents(NodeFeature feature)
        {
            BuildIncludeStatements();
            BuildUsingStatements();
            OpenNameSpace(LanguageConfig.NameSpace);
            OpenTestClass(feature.Name);
            BuildTestClass(feature);
            CloseTestClass();
            CloseNameSpace();

            return Contents.ToArray();
        }
        public void HeaderGeneratorCreatesOneFeatureWithDuplicateSteps()
        {
            IList<NodeFeature> features = new List<NodeFeature>();

            //Create scenario & add
            NodeScenario scenario1 = new NodeScenario("MyScenario1");
            scenario1.Steps.Add(new NodeStep("GivenAMethod1"));
            scenario1.Steps.Add(new NodeStep("WhenUsingAMethod1"));
            scenario1.Steps.Add(new NodeStep("ThenUsingAMethod1"));
            scenario1.Steps.Add(new NodeStep("GivenAMethod1"));
            scenario1.Steps.Add(new NodeStep("WhenUsingAMethod1"));
            scenario1.Steps.Add(new NodeStep("ThenUsingAMethod1"));

            //Create feature & add
            NodeFeature feature1 = new NodeFeature("MyFeature1");
            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_METHOD(MyScenario1);",
                "",
                "\tprivate:",
                "\t\tvoid GivenAMethod1();",
                "\t\tvoid WhenUsingAMethod1();",
                "\t\tvoid ThenUsingAMethod1();",
                "\t};",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public static IList<NodeFeature> FeatureWithScenarioOutlineAndStep()
        {
            IList<NodeFeature> features = new List<NodeFeature>();
            NodeFeature featureWithScenario = new NodeFeature("Feature1", new List<NodeHook>());
            NodeScenarioOutline scenario = new NodeScenarioOutline("Scenario1", new List<NodeHook>());
            scenario.Examples.Rows = new List<string[]>() {
                new[] { "a", "b", "c" },
                new[] { "1", "2", "3" },
                new[] { "4", "5", "6" }
            };

            scenario.Steps.Add(new NodeStep("GivenIHaveAStep"));
            featureWithScenario.Scenarios.Add(scenario);
            features.Add(featureWithScenario);

            return features;
        }
示例#11
0
 private static void RemoveAutoGeneratedStepsThatDuplicateUserSteps(string file, NodeFeature feature)
 {
     string[] contents = File.ReadAllLines(file);
     StepDefinitionParser parser = new StepDefinitionParser();
     List<FeatureGroup> groups = parser.Parse(contents);
     var filterGroup = groups.FirstOrDefault(featureGroup => featureGroup.FeatureName == feature.Name);
     if (filterGroup != null)
     {
         foreach (var scenario in feature.Scenarios)
         {
             foreach (var filterStep in filterGroup.Steps)
             {
                 scenario.Steps.RemoveAll(step => step.Equals(filterStep));
             }
         }
     }
 }
        public void StepGeneratorCreatesTwoFeaturesWithScenario()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            NodeFeature feature = new NodeFeature("Feature1");
            NodeScenario scenario = new NodeScenario("Scenario1");
            scenario.Steps.Add(new NodeStep("GivenMethod"));
            feature.Scenarios.Add(scenario);
            features.Add(feature);
            feature = new NodeFeature("Feature2");
            scenario = new NodeScenario("Scenario2");
            scenario.Steps.Add(new NodeStep("GivenMethod"));
            feature.Scenarios.Add(scenario);
            features.Add(feature);

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

            Assert.AreEqual(2, files.Count, "File count mismatch.");
            for (int i = 0; i < files.Count; i++)
            {
                string[] stringsExpected = new string[] {
                    string.Format("#include \"Feature{0}.h\"", i+1),
                    "",
                    "namespace CppUnitTest",
                    "{",
                    string.Format("\tvoid Feature{0}::GivenMethod()", i+1),
                    "\t{",
                    "\t\tAssert::Fail(L\"Pending implementation...\");",
                    "\t}",
                    "}"
                };
                AssertExt.ContentsOfStringArray(stringsExpected, files[i]);
            }
        }
        public void StepGeneratorCreatesOneScenarioOneStepOneParameterAndOneRow()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

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

            //Add step
            NodeStep step1 = new NodeStep("GivenMethod1");
            step1.Parameters.Add(p1);
            step1.Rows = new List<string[]>() {
                new [] { "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)",
                "\t{",
                "\t\tAssert::Fail(L\"Pending implementation...\");",
                "\t}",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void HeaderGeneratorCreatesOneFeatureOneScenarioAndOneStep()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            //Creates Step 1 & Adds to list
            NodeStep step1 = new NodeStep("GivenMethod1");

            //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();",
                "\t};",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
 private static void VerifyFeature(NodeFeature feature, string changingText)
 {
     Assert.AreEqual(string.Format("Feature{0}", changingText), feature.Name);
     Assert.AreEqual(1, feature.Hooks.Count, string.Format("feature{0} hook count mismatch", changingText));
     Assert.AreEqual(string.Format("f{0}", changingText), feature.Hooks[0].Name);
     Assert.AreEqual(1, feature.Scenarios.Count, string.Format("scenario{0} count mismatch", changingText));
     Assert.AreEqual(string.Format("Scenario{0}", changingText), feature.Scenarios[0].Name);
     Assert.AreEqual(2, feature.Scenarios[0].Hooks.Count, string.Format("scenario{0} hook count mismatch", changingText));
     Assert.AreEqual(string.Format("f{0}", changingText), feature.Scenarios[0].Hooks[0].Name);
     Assert.AreEqual(string.Format("s{0}", changingText), feature.Scenarios[0].Hooks[1].Name);
 }
        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]);
        }
        public void StepGeneratorCreatesOneScenarioOneStepTwoParameters()
        {
            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);

            //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(string Parameter1, int Parameter2)",
                "\t{",
                "\t\tAssert::Fail(L\"Pending implementation...\");",
                "\t}",
                "}"
            };
            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void HeaderGeneratorCreatesOneFeatureTwoFeatureHooksTwoScenarioHooksAndTwoSteps()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            List<NodeHook> featureHooks = new List<NodeHook>() {
                new NodeHook("featurehook1"),
                new NodeHook("featurehook2")
            };

            List<NodeHook> scenarioHooks = new List<NodeHook>() {
                new NodeHook("featurehook1"),
                new NodeHook("featurehook2"),
                new NodeHook("scenariohook1"),
                new NodeHook("scenariohook2")
            };

            //Creates Step 1
            NodeStep step1 = new NodeStep("GivenMethod1");

            //Creates Step 2
            NodeStep step2 = new NodeStep("GivenMethod2");

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

            //Creates Feature 1
            NodeFeature testFeature = new NodeFeature("TestFeature1", featureHooks);
            testFeature.Scenarios.Add(scenario1);

            features.Add(testFeature);

            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_CLASS_HOOK_FEATUREHOOK1()",
                "\t\tTEST_CLASS_HOOK_FEATUREHOOK2()",
                "\t\tTEST_METHOD_HOOK_FEATUREHOOK1_FEATUREHOOK2_SCENARIOHOOK1_SCENARIOHOOK2(TestScenario1);",
                "",
                "\tprivate:",
                "\t\tvoid GivenMethod1();",
                "\t\tvoid GivenMethod2();",
                "\t};",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void HeaderGeneratorCreatesOneFeatureOneFeatureHookAndOneScenarioHook()
        {
            IList<NodeFeature> features;
            features = new List<NodeFeature>();

            NodeFeature testFeature = new NodeFeature("TestFeature1", new List<NodeHook>() { new NodeHook("featurehook1") });
            testFeature.Scenarios.Add(new NodeScenario("TestScenario1", new List<NodeHook>() { new NodeHook("featurehook1"), new NodeHook("scenariohook1") }));

            features.Add(testFeature);

            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_CLASS_HOOK_FEATUREHOOK1()",
                "\t\tTEST_METHOD_HOOK_FEATUREHOOK1_SCENARIOHOOK1(TestScenario1);",
                "\t};",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
示例#20
0
 private void AddFeature(string formattedLine, string label)
 {
     if (MakePreviousScenarioHookAFeatureHookHack)
     {
         MakePreviousScenarioHookAFeatureHook(); // undo previous scenario hook in scenarioHooks
         MakePreviousScenarioHookAFeatureHookHack = false;
     } // else no need to undo previous scenario hook
     lastFeature = new NodeFeature(GherkinParser.ParseNameWithLabel(formattedLine, label), featureHooks);
     features.Add(lastFeature);
 }