public void HeaderGeneratorCreatesOneFeatureOneFeatureHookOneScenarioHookAndOneStep()
        {
            IList <NodeFeature> features;

            features = new List <NodeFeature>();

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

            //Creates Scenario 1
            NodeScenario scenario1 = new NodeScenario("TestScenario1", new List <NodeHook>()
            {
                new NodeHook("featurehook1"), new NodeHook("scenariohook1")
            });

            scenario1.Steps.Add(step1);

            //Creates Feature 1
            NodeFeature testFeature = new NodeFeature("TestFeature1", new List <NodeHook>()
            {
                new NodeHook("featurehook1")
            });

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void HeaderGeneratorCreatesOneFeatureTwoFeatureHooksAndTwoScenarioHooks()
        {
            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")
            };

            NodeFeature testFeature = new NodeFeature("TestFeature1", featureHooks);

            testFeature.Scenarios.Add(new NodeScenario("TestScenario1", scenarioHooks));

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
Example #3
0
        public void HeaderGeneratorCreatesOneFeatureOneScenarioAndTwoSteps()
        {
            IList <NodeFeature> features;

            features = new List <NodeFeature>();

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

            //Creates Step 2 & Adds to list
            NodeStep step2 = new NodeStep("GivenMethod2");

            //Creates Scenario 1
            NodeScenario scenario1 = new NodeScenario("TestScenario1");

            scenario1.Steps.Add(step1);
            scenario1.Steps.Add(step2);

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
Example #4
0
        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 void CodeBehindGeneratorCreatesScenarioWithTwoStepAndTwoTable()
        {
            var features = TestCodeBehindData.FeatureWithScenarioAndTwoSteps();

            var table = new List <string[]>()
            {
                new[] { "a", "b", "c" },
                new[] { "1", "2", "3" }
            };

            features[0].Scenarios[0].Steps[0].Rows = table;
            features[0].Scenarios[0].Steps[1].Rows = table;

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

            string[] stringsExpected = new string[] {
                string.Format("#include \"{0}.h\"", features[0].Name),
                string.Empty,
                "namespace CppUnitTest",
                "{",
                string.Format("\tvoid {0}::{1}()", features[0].Name, features[0].Scenarios[0].Name),
                "\t{",
                "\t\tstd::vector<std::vector<std::string>> table0 = {{",
                "\t\t\t{ \"a\", \"b\", \"c\" },",
                "\t\t\t{ \"1\", \"2\", \"3\" }",
                "\t\t}};",
                string.Format("\t\t{0}(table0,{1},{2});",
                              features[0].Scenarios[0].Steps[0].Name,
                              features[0].Scenarios[0].Steps[0].Rows.Count,
                              features[0].Scenarios[0].Steps[0].Rows[0].Length),
                "\t\tstd::vector<std::vector<std::string>> table1 = {{",
                "\t\t\t{ \"a\", \"b\", \"c\" },",
                "\t\t\t{ \"1\", \"2\", \"3\" }",
                "\t\t}};",
                string.Format("\t\t{0}(table1,{1},{2});",
                              features[0].Scenarios[0].Steps[1].Name,
                              features[0].Scenarios[0].Steps[1].Rows.Count,
                              features[0].Scenarios[0].Steps[1].Rows[0].Length),
                "\t}",

                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void CodeBehindGeneratorCreatesScenarioWithNoSteps()
        {
            var features = TestCodeBehindData.FeatureWithScenarioAndNoStep();
            var files    = GeneratorFactory.Generate(GeneratorType.CodeBehindGenerator, features);

            string[] stringsExpected = new string[] {
                string.Format("#include \"{0}.h\"", features[0].Name),
                string.Empty,
                "namespace CppUnitTest",
                "{",
                string.Format("\tvoid {0}::{1}()", features[0].Name, features[0].Scenarios[0].Name),
                "\t{",
                "\t}",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void CodeBehindGeneratorCreatesScenarioOutlineWithStepAndTableDeclaredOnce()
        {
            var features = TestCodeBehindData.FeatureWithScenarioOutlineAndStep();

            features[0].Scenarios[0].Steps[0].Rows = new List <string[]>()
            {
                new[] { "a", "b", "c" },
                new[] { "1", "2", "3" }
            };

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

            List <string> stringsExpected = new List <string> {
                string.Format("#include \"{0}.h\"", features[0].Name),
                string.Empty,
                "namespace CppUnitTest",
                "{",
                string.Format("\tvoid {0}::{1}()", features[0].Name, features[0].Scenarios[0].Name),
                "\t{",
                "\t\tstd::vector<std::vector<std::string>> table0 = {{",
                "\t\t\t{ \"a\", \"b\", \"c\" },",
                "\t\t\t{ \"1\", \"2\", \"3\" }",
                "\t\t}};"
            };
            NodeScenarioOutline outline = (NodeScenarioOutline)features[0].Scenarios[0];

            for (int i = 0; i < outline.Examples.Rows.Count - 1; i++)
            {
                foreach (var step in outline.Steps)
                {
                    stringsExpected.Add(string.Format("\t\t{0}(table0,2,3);", step.Name));
                }
            }
            List <string> stringsExpectedEnd = new List <string> {
                "\t}",
                "}"
            };

            stringsExpected.AddRange(stringsExpectedEnd);

            AssertExt.ContentsOfStringArray(stringsExpected.ToArray(), files[0]);
        }
        public void CodeBehindGeneratorCreatesTwoFeaturesWithScenario()
        {
            var features = TestCodeBehindData.TwoFeaturesWithScenario();
            var files    = GeneratorFactory.Generate(GeneratorType.CodeBehindGenerator, features);

            Assert.AreEqual(2, files.Count, "File count mismatch.");
            for (int i = 0; i < files.Count; i++)
            {
                string[] stringsExpected = new string[] {
                    string.Format("#include \"{0}.h\"", features[i].Name),
                    string.Empty,
                    "namespace CppUnitTest",
                    "{",
                    string.Format("\tvoid {0}::{1}()", features[i].Name, features[i].Scenarios[0].Name),
                    "\t{",
                    "\t}",
                    "}"
                };

                AssertExt.ContentsOfStringArray(stringsExpected, files[i]);
            }
        }
        public void CodeBehindGeneratorCreatesStepWithOneNumberParameter()
        {
            var features = TestCodeBehindData.FeatureWithScenarioAndStepAndParameter("int");

            string parameterName = string.Empty;

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

            string[] stringsExpected = new string[] {
                string.Format("#include \"{0}.h\"", features[0].Name),
                string.Empty,
                "namespace CppUnitTest",
                "{",
                string.Format("\tvoid {0}::{1}()", features[0].Name, features[0].Scenarios[0].Name),
                "\t{",
                string.Format("\t\t{0}({1});", features[0].Scenarios[0].Steps[0].Name, features[0].Scenarios[0].Steps[0].Parameters[0].Value),
                "\t}",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void CodeBehindGeneratorCreatesErrorAssertForUnevenTable()
        {
            var features = TestCodeBehindData.FeatureWithScenarioAndStep();

            features[0].Scenarios[0].Steps[0].Rows = new List <string[]>()
            {
                new[] { "a", "b", "c" },
                new[] { "1", "2", "3" },
                new[] { "4", "5" },
                new[] { "7", "8", "9" }
            };

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

            string[] stringsExpected = new string[] {
                string.Format("#include \"{0}.h\"", features[0].Name),
                string.Empty,
                "namespace CppUnitTest",
                "{",
                string.Format("\tvoid {0}::{1}()", features[0].Name, features[0].Scenarios[0].Name),
                "\t{",
                "\t\tAssert::Fail(L\"PARSE ERROR: Table is uneven\");",
                "\t\tstd::vector<std::vector<std::string>> table0 = {{",
                "\t\t\t{ \"a\", \"b\", \"c\" },",
                "\t\t\t{ \"1\", \"2\", \"3\" },",
                "\t\t\t{ \"4\", \"5\" },",
                "\t\t\t{ \"7\", \"8\", \"9\" }",
                "\t\t}};",
                string.Format("\t\t{0}(table0,{1},{2});",
                              features[0].Scenarios[0].Steps[0].Name,
                              features[0].Scenarios[0].Steps[0].Rows.Count,
                              features[0].Scenarios[0].Steps[0].Rows[0].Length),
                "\t}",
                "}"
            };

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

            features = new List <NodeFeature>();

            List <NodeHook> hooks = new List <NodeHook>();

            hooks.Add(new NodeHook("hook1"));
            hooks.Add(new NodeHook("hook2"));

            features.Add(new NodeFeature("TestFeature1", hooks));

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
Example #12
0
        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]);
        }
Example #13
0
        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]);
        }
Example #14
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]);
        }