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]);
        }
 private void CloseMethod(NodeStep currentStep, IList <NodeStep> steps)
 {
     Contents.Add("\t}");
     if (steps.Last() != currentStep)
     {
         Contents.Add(string.Empty);
     }
 }
Beispiel #3
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 static IList <NodeFeature> FeatureWithScenarioAndStep()
        {
            var features = FeatureWithScenarioAndNoStep();

            NodeStep step = new NodeStep("GivenIHaveAStep");

            features[0].Scenarios[0].Steps.Add(step);   // steps to scenario

            return(features);
        }
        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]);
        }
        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]);
        }
        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);
        }
 private void AddParameters(NodeStep step, string parameterContents)
 {
     if (parameterContents.Contains(","))
     {
         AddMultipleParameters(step, parameterContents);
     }
     else
     {
         AddOneParameter(step, parameterContents);
     }
 }
Beispiel #9
0
        private void BuildStepMethodCall(NodeStep step, NodeExamples examples, int exampleIndex)
        {
            // if we have rows and first time thru scenario outline
            if (step.Rows.Count > 0 && exampleIndex == 1) // TODO: remove exampleIndex == 1 if parameterizing table arguments
            {
                _tableNumberInScenario++;

                // TODO: could pass in NodeExamples examples to support parameterizing table arguments
                BuildTestDataTable(step.Rows, Contents);
            }

            Contents.Add(string.Format("\t\t{0};", LanguageConfig.StepMethod(step.Name, BuildParameterString(step.Parameters, step.Rows, examples, exampleIndex))));
        }
Beispiel #10
0
        private void AddStep(string formattedLine)
        {
            var tokens = GherkinParser.ParseOutStepAndParameters(formattedLine);

            if (tokens == null)  // invalid gherkin step
            {
                lastStep = null; // so that any tables don't get added to the last valid step
            }
            else
            {
                lastStep = new NodeStep(tokens);
                lastScenario.Steps.Add(lastStep);
            }
        }
        private void AddStep(string stepContents, List <NodeStep> steps)
        {
            NodeStep step = new NodeStep();
            string   openParenthesisSplit = "(";

            string[] tokens = stepContents.Split(openParenthesisSplit.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (HasParameters(tokens[1].ToString()))
            {
                AddParameters(step, tokens[1]);
            }
            step.Name = tokens[0];
            steps.Add(step);
        }
Beispiel #12
0
        public void NodesWithTableArgumentsAreEqual()
        {
            NodeStep step1 = new NodeStep("my step");

            step1.Rows.Add(new string[] {
                "| a | b | c |"
            });

            NodeStep step2 = new NodeStep("my step");

            step2.Rows.Add(new string[] {
                "| a | b | c |"
            });

            Assert.IsTrue(step1.Equals(step2));
        }
Beispiel #13
0
        private async Task Evaluate(NodeInfo nodeInfo)
        {
            NodeStep nodeStep;

            nodeInfo.Status = NodeStatus.Running;

            try
            {
                Log.Trace(DebuggerCategory, "Entering node {0}", nodeInfo.Type.Name);

                nodeStep = nodeInfo.Node.Evaluate();

                Log.Trace(DebuggerCategory, "Exiting node {0} with result {1}", nodeInfo.Type.Name, nodeStep.Result);
            }
            catch (Exception e)
            {
                Log.Error(DebuggerCategory, "Error while executing node {0}. {1}", nodeInfo.Type.Name, e.Message);
                nodeStep = new NodeStep(NodeResult.Fail, null);
            }

            if (State == DebuggerState.Idle)
            {
                return;
            }

            nodeInfo.Status = NodeStatus.Idle;
            nodeInfo.Result = nodeStep.Result;

            switch (nodeStep.Result)
            {
            case NodeResult.Skip: return;

            case NodeResult.Fail: Break(); return;

            case NodeResult.Stop: Stop(); return;
            }

            NodeInfo[] nodeInfos = nodeStep.Slot.Nodes.Select(n => NodeInfo.From(FlowInfo, n)).ToArray();

            foreach (NodeInfo node in nodeInfos)
            {
                node.Status = NodeStatus.Paused;
            }

            lock (nodes)
                nodes.AddRange(nodeInfos);
        }
Beispiel #14
0
        private void MakePreviousScenarioHookAFeatureHook()
        {
            if (hooksToAdd == null)
            {
                return;
            }
            foreach (var hook in hooksToAdd)
            {
                scenarioHooks.Remove(hook);
            }
            lastScenario = null;
            lastStep     = null;

            featureHooks  = new List <NodeHook>();
            scenarioHooks = new List <NodeHook>();
            AddDistinctHooksByName(featureHooks, hooksToAdd);
            AddDistinctHooksByName(scenarioHooks, hooksToAdd);
        }
        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 });
            }
        }
Beispiel #16
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]);
        }
Beispiel #17
0
        public static void Main(string[] args)
        {
            Console.Title = "FlowTomator";

            Options = args.Where(a => a.StartsWith("/"))
                      .Select(a => a.TrimStart('/'))
                      .Select(a => new { Parameter = a.Trim(), Separator = a.Trim().IndexOf(':') })
                      .ToDictionary(a => a.Separator == -1 ? a.Parameter : a.Parameter.Substring(0, a.Separator).ToLower(), a => a.Separator == -1 ? null : a.Parameter.Substring(a.Separator + 1));
            Parameters = args.Where(a => !a.StartsWith("/"))
                         .ToList();

            if (Options.ContainsKey("log"))
            {
                LogVerbosity verbosity;

                if (!Enum.TryParse(Options["log"], true, out verbosity))
                {
                    Log.Error("The specified log verbosity does not exist");
                    Exit(-1);
                }

                Log.Verbosity = verbosity;
            }

            string flowPath = Parameters.FirstOrDefault();

            if (flowPath == null)
            {
                Log.Error("You must specify a flow to evaluate");
                Exit(-1);
            }

            FileInfo flowInfo = new FileInfo(flowPath);

            if (!flowInfo.Exists)
            {
                Log.Error("Could not find the specified flow");
                Exit(-1);
            }

            Console.Title = "FlowTomator - " + flowInfo.Name;

            Flow flow = null;

            try
            {
                switch (flowInfo.Extension)
                {
                case ".xflow": flow = XFlow.Load(XDocument.Load(flowInfo.FullName)); break;
                }
            }
            catch { }

            if (flow == null)
            {
                Log.Error("Could not load the specified flow");
                return;
            }

            flow.Reset();
            NodeStep nodeStep = flow.Evaluate();

            Exit((int)nodeStep.Result);
        }
        protected virtual NodeStep EvaluateNode(Node node)
        {
            NodeStep step;
            Log.Trace("Entering node {0}", node.GetType().Name);

            try
            {
                step = node.Evaluate();
            }
            catch
            {
                step = new NodeStep(NodeResult.Fail, null);
            }

            if (evaluating)
                Log.Trace("Exiting node {0} with result {1}{2}", node.GetType().Name, step.Result, step.Slot == null ? "" : (" by slot " + step.Slot.Name));

            return step;
        }
Beispiel #19
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]);
        }
Beispiel #20
0
        private async Task Evaluate(NodeInfo nodeInfo)
        {
            NodeStep nodeStep;
            nodeInfo.Status = NodeStatus.Running;
           
            try
            {
                Log.Trace(DebuggerCategory, "Entering node {0}", nodeInfo.Type.Name);

                nodeStep = nodeInfo.Node.Evaluate();

                Log.Trace(DebuggerCategory, "Exiting node {0} with result {1}", nodeInfo.Type.Name, nodeStep.Result);
            }
            catch (Exception e)
            {
                Log.Error(DebuggerCategory, "Error while executing node {0}. {1}", nodeInfo.Type.Name, e.Message);
                nodeStep = new NodeStep(NodeResult.Fail, null);
            }

            if (State == DebuggerState.Idle)
                return;

            nodeInfo.Status = NodeStatus.Idle;
            nodeInfo.Result = nodeStep.Result;

            switch (nodeStep.Result)
            {
                case NodeResult.Skip: return;
                case NodeResult.Fail: Break(); return;
                case NodeResult.Stop: Stop(); return;
            }

            NodeInfo[] nodeInfos = nodeStep.Slot.Nodes.Select(n => NodeInfo.From(FlowInfo, n)).ToArray();

            foreach (NodeInfo node in nodeInfos)
                node.Status = NodeStatus.Paused;

            lock (nodes)
                nodes.AddRange(nodeInfos);
        }
Beispiel #21
0
 public NodeStep(NodeStep other)
 {
     Node  = other.Node;
     Steps = other.Steps;
 }