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

            features = new List <NodeFeature>();

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

            hooks.Add(new NodeHook("integration"));

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

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

            features[0].Scenarios[0].Steps.Add(new NodeStep("GivenIHaveAStep"));
            features[0].Scenarios[0].Steps.Add(new NodeStep("WhenIHaveAStep"));
            features[0].Scenarios[0].Steps.Add(new NodeStep("ThenIHaveAStep"));

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

            string parameterName = string.Empty;

            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, parameterName),
                string.Format("\t\t{0}({1});", features[0].Scenarios[0].Steps[1].Name, parameterName),
                string.Format("\t\t{0}({1});", features[0].Scenarios[0].Steps[2].Name, parameterName),
                "\t}",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        public void CodeBehindGeneratorCreatesScenarioOutlineWithStepAndParameterized()
        {
            var features = TestCodeBehindData.FeatureWithScenarioOutlineAndStepAndParameterized("string");

            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{"
            };
            NodeScenarioOutline outline = (NodeScenarioOutline)features[0].Scenarios[0];

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

            stringsExpected.AddRange(stringsExpectedEnd);

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

            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);

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
예제 #5
0
        public void HeaderGeneratorCreatesOneFeatureAndOneScenario()
        {
            IList <NodeFeature> features;

            features = new List <NodeFeature>();

            NodeFeature featureScenario = new NodeFeature("TestFeature1");

            featureScenario.Scenarios.Add(new NodeScenario("TestScenario1"));

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

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
예제 #6
0
        public void HeaderGeneratorCreatesTwoFeaturesNoHooksNoScenariosNoSteps()
        {
            IList <NodeFeature> features;

            features = new List <NodeFeature>();
            features.Add(new NodeFeature("MyTestFeature1"));
            features.Add(new NodeFeature("MyTestFeature2"));

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

            Assert.AreEqual(2, files.Count, "File count mismatch.");
            for (int i = 0; i < files.Count; i++)
            {
                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",
                    "{",
                    string.Format("\tTEST_CLASS(MyTestFeature{0})", i + 1),
                    "\t{",
                    "\tpublic:",
                    "\t};",
                    "}"
                };
                AssertExt.ContentsOfStringArray(stringsExpected, files[i]);
            }
        }
예제 #7
0
        public void HeaderGeneratorCreatesOneFeatureTwoScenariosAndOneStep()
        {
            IList <NodeFeature> features;

            features = new List <NodeFeature>();

            //Creates Step 1 for Scenario 1 & Adds to list
            NodeStep step1Scenario1 = new NodeStep("GivenMethod1Scenario1");

            //Creates Step 1 for Scenario 2 & Adds to list
            NodeStep step1Scenario2 = new NodeStep("GivenMethod1Scenario2");

            //Creates Scenario 1 & Adds to list
            NodeScenario scenario1 = new NodeScenario("TestScenario1");

            scenario1.Steps.Add(step1Scenario1);

            //Creates Scenario 2 & Adds to list
            NodeScenario scenario2 = new NodeScenario("TestScenario2");

            scenario2.Steps.Add(step1Scenario2);

            //Creates Feature & Adds to list
            NodeFeature feature = new NodeFeature("TestFeature1");

            feature.Scenarios.Add(scenario1);
            feature.Scenarios.Add(scenario2);
            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);",
                "\t\tTEST_METHOD(TestScenario2);",
                "",
                "\tprivate:",
                "\t\tvoid GivenMethod1Scenario1();",
                "\t\tvoid GivenMethod1Scenario2();",
                "\t};",
                "}"
            };

            AssertExt.ContentsOfStringArray(stringsExpected, files[0]);
        }
        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]);
        }
예제 #10
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]);
        }
예제 #11
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]);
        }
예제 #13
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]);
            }
        }
예제 #14
0
        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]);
        }
예제 #15
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]);
        }
예제 #16
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]);
        }