Exemplo n.º 1
0
        /// <summary>
        /// Fault handled from flowchart in a try catch block.
        /// </summary>
        /// Disabled in desktop and failing.
        //[Fact]
        private void FlowchartInTryCatchBlock_FaultHandled()
        {
            TestFlowchart flowchart = new TestFlowchart();

            flowchart.AddStartLink(new TestThrow <Exception>()
            {
                ExpectedOutcome = Outcome.CaughtException()
            });

            TestTryCatch tryCatchFinally = new TestTryCatch
            {
                Try     = flowchart,
                Catches =
                {
                    new TestCatch <Exception>
                    {
                        Body = new TestWriteLine("ExceptionHandler", "Handled"),
                    }
                }
            };

            TestRuntime.RunAndValidateWorkflow(tryCatchFinally);
        }
Exemplo n.º 2
0
        public void FlowSwitchWithNullFlowNode()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <int> expression = new Variable <int> {
                Name = "expression", Default = 1
            };

            flowchart.Variables.Add(expression);

            Dictionary <int, TestActivity> cases = new Dictionary <int, TestActivity>();

            cases.Add(1, null);

            List <int> hints = new List <int>()
            {
                -1
            };

            flowchart.AddSwitchLink <int>(new TestWriteLine("Start", "Flowchart started"), cases, hints, expression);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 3
0
        public void NullAsValueOfElements()
        {
            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel For Each")
            {
                Body = new TestWriteLine("Writeline")
                {
                    Message = "I will  be displayed"
                },
                HintValues = new List <string>()
                {
                    null
                },
                ValuesExpression   = (context => new List <string>()
                {
                    null
                }),
                HintIterationCount = 1,
            };

            ExpectedTrace tr = parallelForEach.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelForEach, tr);
        }
Exemplo n.º 4
0
        public void SimpleEmptyWhile()
        {
            //  Test case description:
            //  Set  condition to a valid rule and run 5-6 iterations without any activities in.

            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

            TestSequence rootSequence = new TestSequence("rootSequence");

            rootSequence.Variables.Add(counter);

            TestWhile whileAct = new TestWhile("while act")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 0),
                Body = new TestSequence("innerseq"),
                HintIterationCount = 10,
            };

            rootSequence.Activities.Add(whileAct);

            whileAct.Body = null;
            TestRuntime.RunAndValidateWorkflow(rootSequence);
        }
Exemplo n.º 5
0
        public void ConnectFromFlowconditionalTrueToFlowconditional()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine w1 = new TestWriteLine("w1", "w1");
            TestWriteLine w2 = new TestWriteLine("w2", "w2");

            TestFlowConditional conditional1 = new TestFlowConditional
            {
                Condition = true
            };

            TestFlowConditional conditional2 = new TestFlowConditional
            {
                Condition = true
            };

            flowchart.AddConditionalLink(w1, conditional1);
            flowchart.AddConditionalLink(null, conditional2, w2, (TestActivity)null);
            flowchart.AddConditionalLink(null, conditional1, conditional2, (TestActivity)null);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
        public void SimpleParallel()
        {
            TestWriteLine writeLine1 = new TestWriteLine
            {
                Message     = "writeLine1",
                DisplayName = "writeLine1"
            };

            TestWriteLine writeLine2 = new TestWriteLine
            {
                Message     = "writeLine2",
                DisplayName = "writeLine2"
            };

            TestParallel parallelActivity = new TestParallel("Parallel Activity");

            parallelActivity.Branches.Add(writeLine1);
            parallelActivity.Branches.Add(writeLine2);

            ExpectedTrace trace = parallelActivity.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelActivity, trace);
        }
Exemplo n.º 7
0
        public void TryCatchFinallyInLoops()
        {
            Variable <int> count    = new Variable <int>("Counter", 0);
            TestWhile      whileAct = new TestWhile
            {
                Variables           = { count },
                ConditionExpression = e => count.Get(e) < 5,
                Body = new TestSequence
                {
                    Activities =
                    {
                        new TestTryCatch
                        {
                            Try = new TestThrow <ArgumentException>()
                            {
                                ExpectedOutcome = Outcome.CaughtException()
                            },
                            Catches =     {           { new TestCatch <ArgumentException>()
                                                        {
                                                            Body = new TestWriteLine("Caught", "Caught")
                                                        } } },
                            Finally = new TestSequence{
                                Activities ={ new TestWriteLine("Finally", "Finally") }
                            }
                        },
                        new TestIncrement
                        {
                            CounterVariable = count,
                            IncrementCount  = 1
                        }
                    }
                },
                HintIterationCount = 5
            };

            TestRuntime.RunAndValidateWorkflow(whileAct);
        }
Exemplo n.º 8
0
        public void FlowSwitchConnectedToFlowDecision()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine wStart   = new TestWriteLine("Start", "Flowchart started");
            TestWriteLine wDefault = new TestWriteLine("Default", "Default");
            TestWriteLine w1       = new TestWriteLine("One", "One wont execute");
            TestWriteLine w3       = new TestWriteLine("Three", "Three wont execute");
            TestWriteLine w2True   = new TestWriteLine("True", "True will execute");
            TestWriteLine w2False  = new TestWriteLine("False", "False wont execute");

            TestFlowStep fs1 = new TestFlowStep(w1);
            TestFlowStep fs3 = new TestFlowStep(w3);

            Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10);

            flowchart.Variables.Add(margin);
            TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True);

            flowDecision.ConditionExpression = (context => margin.Get(context) > 0);
            flowchart.AddConditionalLink(null, flowDecision, w2True, w2False);

            Dictionary <string, TestFlowElement> cases = new Dictionary <string, TestFlowElement>();

            cases.Add("One", fs1);
            cases.Add("Two", flowDecision);
            cases.Add("Three", fs3);

            List <int> hints = new List <int>();

            hints.Add(1);

            flowchart.AddStartLink(wStart);
            flowchart.AddSwitchLink <string>(wStart, cases, hints, "Two", wDefault);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 9
0
        public void ThrowWithCaseInfinity()
        {
            TestSwitch <float> switchAct = new TestSwitch <float>();
            Variable <float>   temp      = VariableHelper.CreateInitialized <float>("temp", 3);
            float        temp1           = 1;
            float        temp2           = 0;
            TestSequence seq             = new TestSequence();

            seq.Activities.Add(switchAct);
            seq.Variables.Add(temp);

            switchAct.AddCase(123, new TestWriteLine("Seq")
            {
                Message = ""
            });
            switchAct.AddCase(temp1 / temp2, new TestWriteLine()
            {
                Message = "Infinity is the value"
            });
            switchAct.ExpressionExpression = (env) => (float)(1 / (temp.Get(env) - 3));
            switchAct.Hints.Add(1);

            TestRuntime.RunAndValidateWorkflow(seq);
        }
Exemplo n.º 10
0
        public void IfThenBodyHasVariable()
        {
            const string      varValue = "hello world";
            Variable <string> var      = VariableHelper.CreateInitialized <string>("aVariable", varValue);

            TestIf testIf = new TestIf("MyIf", HintThenOrElse.Then)
            {
                Condition    = true,
                ThenActivity = new TestSequence("then Branch")
                {
                    Variables =
                    {
                        var,
                    },
                    Activities =
                    {
                        new TestWriteLine("Then WriteLine", var, varValue),
                    },
                },
                ElseActivity = new TestWriteLine("else Branch", "it would not be displayed"),
            };

            TestRuntime.RunAndValidateWorkflow(testIf);
        }
Exemplo n.º 11
0
        public void AccessFirstItemOfAnArray()
        {
            Variable <Complex[]> complexArrayVar = new Variable <Complex[]> {
                Name = "ComplexArrVar"
            };

            Variable <Complex> result = new Variable <Complex>()
            {
                Name = "Result"
            };

            TestSequence seq = new TestSequence
            {
                Variables  = { complexArrayVar, result },
                Activities =
                {
                    new TestAssign <Complex[]> {
                        ToVariable = complexArrayVar, ValueExpression = (context => new Complex[]{ new Complex(0,                                                    0), new Complex(1, 1) })
                    },
                    new TestArrayItemValue <Complex>
                    {
                        DisplayName   = "GetValue",
                        ArrayVariable = complexArrayVar,
                        Index         = 0,
                        Result        = result
                    },
                    new TestWriteLine
                    {
                        MessageExpression = e => result.Get(e).ToString(),
                        HintMessage       = new Complex(0, 0).ToString()
                    }
                }
            };

            TestRuntime.RunAndValidateWorkflow(seq);
        }
Exemplo n.º 12
0
        public void DoWhileConditionExpressionInConstructor()
        {
            Variable <bool> var = new Variable <bool>("var", false);

            TestSequence seq = new TestSequence()
            {
                Activities =
                {
                    new TestDoWhile(env => var.Get(env).Equals(true))
                    {
                        Body = new TestWriteLine("Hello", "Hello"),
                        HintIterationCount = 1
                    }
                },
                Variables =
                {
                    var
                }
            };



            TestRuntime.RunAndValidateWorkflow(seq);
        }
Exemplo n.º 13
0
        public void FlowDecisionAndFlowSwitchNotConnected()
        {
            TestFlowchart flowchart1 = new TestFlowchart("flowChart1");
            TestWriteLine start1     = new TestWriteLine("Start", "Executing Start");
            TestWriteLine w1         = new TestWriteLine("W1", "Executing W1");
            TestWriteLine w2         = new TestWriteLine("W2", "Executing W2");
            TestWriteLine w3         = new TestWriteLine("W3", "Executing W3");
            TestWriteLine wDefault   = new TestWriteLine("wDefault", "Executing wDefault");

            Dictionary <string, TestActivity> cases = new Dictionary <string, TestActivity>();

            cases.Add("One", w1);
            cases.Add("Two", w2);

            List <int> hints = new List <int>();

            hints.Add(1);

            flowchart1.AddSwitchLink <string>(null, cases, hints, "Two", wDefault);

            TestWriteLine w2True  = new TestWriteLine("True", "True will execute");
            TestWriteLine w2False = new TestWriteLine("False", "False wont execute");

            Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10);

            flowchart1.Variables.Add(margin);
            TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True)
            {
                ConditionExpression = (context => margin.Get(context) > 0)
            };
            TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, w2True, w2False);

            flowchart1.Elements.Add(tCond);

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Exemplo n.º 14
0
        public void NestedFlowchartInLoop()
        {
            TestFlowchart parentFlowchart = new TestFlowchart("ParentFlowchart");

            TestFlowchart childFlowchart = new TestFlowchart("ChildFlowchart");

            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

            parentFlowchart.Variables.Add(counter);

            TestAssign <int> assign = new TestAssign <int>("Assign1")
            {
                ValueExpression = (env => ((int)counter.Get(env)) + 1),
                ToVariable      = counter
            };

            List <HintTrueFalse> hints = new List <HintTrueFalse>();

            for (int i = 0; i < 5; i++)
            {
                hints.Add(HintTrueFalse.True);
            }
            hints.Add(HintTrueFalse.False);
            TestFlowConditional flowDecision = new TestFlowConditional(hints.ToArray())
            {
                ConditionExpression = (env => counter.Get(env) <= 5)
            };

            parentFlowchart.AddLink(new TestWriteLine("Start", "Parent started"), childFlowchart);

            parentFlowchart.AddConditionalLink(childFlowchart, flowDecision, childFlowchart, new TestWriteLine("End", "Parent ended"));

            childFlowchart.AddStartLink(assign);

            TestRuntime.RunAndValidateWorkflow(parentFlowchart);
        }
Exemplo n.º 15
0
        public void BasicParallelForEachTest()
        {
            TestSequence outerSequence    = new TestSequence("sequence1");
            TestSequence innerSequence    = new TestSequence("innerSeq");
            DelegateInArgument <string> i = new DelegateInArgument <string>()
            {
                Name = "i"
            };

            string[] strArray = new string[] { "var1", "var2", "var3" };

            TestParallelForEach <string> foreachAct = new TestParallelForEach <string>("foreach");

            foreachAct.HintValues         = new string[] { "var1", "var2", "var3" };
            foreachAct.ValuesExpression   = (context => new string[] { "var1", "var2", "var3" });
            foreachAct.CurrentVariable    = i;
            foreachAct.HintIterationCount = 3;

            TestWriteLine writeLine = new TestWriteLine("write hello");

            writeLine.MessageExpression = ((env) => string.Format("WriteLine Argument: {0}", i.Get(env)));

            for (int counter = strArray.Length - 1; counter > -1; counter--)
            {
                writeLine.HintMessageList.Add("WriteLine Argument: " + strArray[counter]);
            }

            foreachAct.Body = innerSequence;

            innerSequence.Activities.Add(writeLine);
            outerSequence.Activities.Add(foreachAct);

            ExpectedTrace tr = outerSequence.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(outerSequence, tr);
        }
Exemplo n.º 16
0
        public void FlowSwitchExpressionEvaluationEmptyExecuteEmptyCase()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <string> expVariable = new Variable <string> {
                Name = "ExpVar", Default = string.Empty
            };

            flowchart.Variables.Add(expVariable);

            Dictionary <string, TestActivity> cases = new Dictionary <string, TestActivity>();

            cases.Add(string.Empty, new TestWriteLine("Hello0", "Hello0"));
            cases.Add("One", new TestWriteLine("Hello1", "Hello1"));

            List <int> hints = new List <int>()
            {
                0
            };

            flowchart.AddSwitchLink(new TestWriteLine("Start", "Flowchart started"), cases, hints, e => expVariable.Get(e), new TestWriteLine("Default", "Default Activity"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 17
0
        public void OneBranch()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "OneBranch",
                        Trigger     = new TestWriteLine("Trigger1")
                        {
                            Message = "Trigger1 Executing",
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                }
            };

            TestRuntime.RunAndValidateWorkflow(pick);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Simple tcf scenario in a flowchart wf. Exception is thrown then caught.
        /// </summary>
        /// Disabled and failed in desktop
        //[Fact]
        public void SimpleTryCatchFlowchart()
        {
            // try
            TestSequence trySeq = new TestSequence();

            trySeq.Activities.Add(new TestWriteLine("Try", "Try"));
            trySeq.Activities.Add(new TestThrow <ArgumentException>());
            trySeq.Activities.Add(new TestWriteLine("NotCalled", "NotCalled"));

            // catch
            TestCatch[] catches = new TestCatch[] {
                new TestCatch <ArgumentException>()
            };
            catches[0].HintHandleException = true;
            catches[0].Body = new TestWriteLine("Catch", "Catch");

            // finally
            TestSequence finalSeq = new TestSequence();

            finalSeq.Activities.Add(new TestWriteLine("Final", "Final"));

            TestRuntime.RunAndValidateWorkflow
                (CreateTryCatchFinally(trySeq, catches, finalSeq, WFType.FLOW, false));
        }
Exemplo n.º 19
0
        public void WriteTextUsingStringWriter()
        {
            StringBuilder stringBuilder = new StringBuilder();
            string        stringToWrite = "\nWriting text to  a file with StreamWriter object";

            using (StringWriter stringWriter = new StringWriter(stringBuilder))
            {
                TestSequence sequence = new TestSequence
                {
                    Activities =
                    {
                        new TestProductWriteline("Write with StringWriter")
                        {
                            Text = stringToWrite,
                            TextWriterExpression = context => stringWriter
                        }
                    }
                };

                TestRuntime.RunAndValidateWorkflow(sequence);

                Assert.True((stringBuilder.ToString().Equals(stringToWrite + "\r\n")), "String builder did not equal the string to be written.");
            }
        }
Exemplo n.º 20
0
        public void SimpleIfElse()
        {
            //  Test case description:
            //  Have simple if-else scenario with if, and else

            TestSequence     outerSequence = new TestSequence("sequence1");
            TestSequence     innerSequence = new TestSequence("sequence act");
            TestAssign <int> changeCounter = new TestAssign <int>("Elif");
            Variable <int>   counter       = VariableHelper.CreateInitialized <int>("counter", 0);

            TestWriteLine writeLine = new TestWriteLine("write hello");

            writeLine.Message             = "Its a small world after all";
            changeCounter.ToVariable      = counter;
            changeCounter.ValueExpression = (env) => ((int)counter.Get(env)) + 15;

            TestIf ifAct = new TestIf("if act1", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting", "Wont Execute"),
                ElseActivity        = changeCounter
            };

            TestIf ifAct2 = new TestIf("if act 2", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = innerSequence,
            };

            outerSequence.Activities.Add(ifAct);
            outerSequence.Activities.Add(ifAct2);
            innerSequence.Activities.Add(writeLine);
            outerSequence.Variables.Add(counter);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Exemplo n.º 21
0
        public void FlowSwitchWithBothKeyAndValueNull()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <string> stringVar = VariableHelper.CreateInitialized <string>("stringVar", (string)null);

            flowchart.Variables.Add(stringVar);

            Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>();

            cases.Add("One", new TestWriteLine("One", "One"));
            cases.Add("Two", new TestWriteLine("Two", "Two"));
            cases.Add("Three", new TestWriteLine("Three", "Three"));

            List <int> hints = new List <int> {
                3
            };

            TestFlowSwitch <object> flowSwitch = flowchart.AddSwitchLink <object>(new TestWriteLine("Start", "Flowchart started"), cases, hints, e => stringVar.Get(e)) as TestFlowSwitch <object>;

            flowSwitch.AddNullCase(null);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 22
0
        public void SimpleFlowSwitchWithThreeElements()
        {
            TestFlowchart     flowchart  = new TestFlowchart();
            Variable <object> expression = new Variable <object>("expression", context => "Two");

            flowchart.Variables.Add(expression);

            TestWriteLine w1 = new TestWriteLine("One", "One wont execute");
            TestWriteLine w2 = new TestWriteLine("Two", "Two will execute");
            TestWriteLine w3 = new TestWriteLine("Three", "Three wont execute");

            Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>();

            cases.Add("One", w1);
            cases.Add("Two", w2);
            cases.Add("Three", w3);

            List <int> hints = new List <int>();

            hints.Add(1);
            flowchart.AddSwitchLink(new TestWriteLine("Start", "Flowchart started"), cases, hints, expression, new TestWriteLine("Default", "Default"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 23
0
        public void NestedIfElseWhenTheConditionsAreTotallyOpposite()
        {
            //  Test case description:
            //   Have nested if-else activities in which: if branch checks if A is true,Its first child is another if
            //  else and checks if A is false, meaning that it will not be executed at all. In this case we probably
            //  will not be having a validation errror that foresees that it wont be executed however this case is
            //  still valid to check the behavior - this leads to the question of if there will be "detection of
            //  unreachable code"


            TestSequence   outerSequence = new TestSequence("sequence1");
            TestSequence   innerSequence = new TestSequence("inner sequence");
            Variable <int> counter       = VariableHelper.CreateInitialized <int>("counter", 5);

            TestWriteLine writeLine = new TestWriteLine("write hello")
            {
                Message = "Its a small world after all"
            };

            TestIf ifAct = new TestIf("if1", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "NotExecuting"),
                ElseActivity        = innerSequence,
            };

            TestIf ifAct2 = new TestIf("if2", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                ThenActivity        = ifAct,
            };

            TestIf ifAct3 = new TestIf("if3", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "NotExecuting"),
                ElseActivity        = ifAct2,
            };

            TestIf ifAct4 = new TestIf("if4", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                ThenActivity        = ifAct3,
            };

            TestIf ifAct5 = new TestIf("if5", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "NotExecuting"),
                ElseActivity        = ifAct4,
            };

            TestIf ifAct6 = new TestIf("if6", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                ThenActivity        = ifAct5,
            };

            TestIf ifAct7 = new TestIf("if7", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "NotExecuting"),
                ElseActivity        = ifAct6,
            };

            TestIf ifAct8 = new TestIf("if8", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                ThenActivity        = ifAct7,
            };

            TestIf ifAct9 = new TestIf("if9", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "NotExecuting"),
                ElseActivity        = ifAct8,
            };

            TestIf ifAct10 = new TestIf("if10", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                ThenActivity        = ifAct9,
            };

            innerSequence.Activities.Add(writeLine);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(ifAct10);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Exemplo n.º 24
0
        public void WriteLineInWhileActivity()
        {
            Variable <int>   counter   = VariableHelper.CreateInitialized <int>("counter", 0);
            TestAssign <int> increment = new TestAssign <int>("Increment Counter");

            string textVariable = "Loop";

            Variable <string> stringToWrite = VariableHelper.CreateInitialized <string>(
                "stringToWrite",
                textVariable);

            // We don't really need to do Console.SetOut for this test. But we use
            // ConsoleSetOut to create the streamWriter that we use as the TextWriter
            // property of the product's WriteLine activity.
            using (StreamWriter streamWriter = ConsoleSetOut(false))
            {
                Variable <TextWriter> writer = VariableHelper.CreateInitialized <TextWriter>(
                    "writer",
                    streamWriter);

                increment.ToVariable      = counter;
                increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1);

                TestSequence innersequence = new TestSequence
                {
                    Variables =
                    {
                        stringToWrite,
                        writer
                    },

                    Activities =
                    {
                        new TestProductWriteline("Write on a file in while loop")
                        {
                            TextExpression     = ((env) => (((string)stringToWrite.Get(env))) + counter.Get(env).ToString()),
                            TextWriterVariable = writer,
                        },

                        increment,
                    }
                };

                TestSequence outerSequence = new TestSequence
                {
                    Activities =
                    {
                        new TestWhile("While loop")
                        {
                            Body = innersequence,
                            ConditionExpression = ((env) => ((int)counter.Get(env)) < 5),
                            HintIterationCount  = 5
                        }
                    },

                    Variables =
                    {
                        counter
                    }
                };

                TestRuntime.RunAndValidateWorkflow(outerSequence);
            }

            VerifyTextOfWriteLine(
                _tempFilePath,
                textVariable + "0",
                textVariable + "1",
                textVariable + "2",
                textVariable + "3",
                textVariable + "4");
        }
Exemplo n.º 25
0
        public void ExecuteEmptyFlowchart()
        {
            TestFlowchart flowchart = new TestFlowchart("Flowchart1");

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 26
0
        public void StartNodeNullNodeCollectionNull()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Exemplo n.º 27
0
        public void DifferentArguments()
        {
            //Testing Different argument types for If.Condition
            // DelegateInArgument
            // DelegateOutArgument
            // Activity<T>
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <bool>  delegateInArgument  = new DelegateInArgument <bool>("Condition");
            DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output");

            TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct(
                new InvokeFunc <bool, bool>
            {
                Argument = true,
                Func     = new ActivityFunc <bool, bool>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new System.Activities.Statements.Sequence
                    {
                        DisplayName = "Sequence1",
                        Activities  =
                        {
                            new System.Activities.Statements.If
                            {
                                DisplayName = "If1",
                                Condition   = delegateInArgument,
                                Then        = new System.Activities.Statements.Sequence
                                {
                                    DisplayName = "Sequence2",
                                    Activities  =
                                    {
                                        new System.Activities.Statements.Assign <bool>
                                        {
                                            DisplayName = "Assign1",
                                            Value       = delegateInArgument,
                                            To          = delegateOutArgument,
                                        },
                                        new System.Activities.Statements.If
                                        {
                                            DisplayName = "If2",
                                            Condition   = delegateOutArgument,
                                            Then        = new System.Activities.Statements.WriteLine
                                            {
                                                DisplayName = "W1",
                                                Text        = "Tested DelegateIn and DelegateOut arguments in If condition"
                                            },
                                        }
                                    }
                                }
                            }
                        },
                    }
                }
            }
                );

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  =
                {
                    new TestIf(HintThenOrElse.Then)
                    {
                        DisplayName  = "If1",
                        ThenActivity = new TestSequence
                        {
                            DisplayName = "Sequence2",
                            Activities  =
                            {
                                new TestAssign <bool> {
                                    DisplayName = "Assign1"
                                },
                                new TestIf(HintThenOrElse.Then)
                                {
                                    DisplayName  = "If2",
                                    ThenActivity = new TestSequence("W1"),
                                }
                            }
                        }
                    }
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);


            TestIf root = new TestIf(HintThenOrElse.Then)
            {
                ConditionActivity = invokeFunc,
                ThenActivity      = new TestWriteLine {
                    Message = "True", HintMessage = "True"
                },
                ElseActivity = new TestWriteLine {
                    Message = "False", HintMessage = "This is not expected"
                },
            };

            TestRuntime.RunAndValidateWorkflow(root);
        }
Exemplo n.º 28
0
        public void BasicSeqeunceDifferentTypesOfVariables()
        {
            //  Test case description:
            //  Sequence activity with  variables of different data types (i.e. enums, enum with flags, nullables,
            //  Type, collections, generic collections, structs, UDTs)

            Dictionary <double, Guid> dict = new Dictionary <double, Guid>();

            dict.Add(12.123, Guid.Empty);
            dict.Add(23.44, new Guid("03998230918103948213098130981309"));
            dict.Add(-0.233, new Guid("99999999-9999-9999-0000-123456789102"));

            HashSet <ulong> hashSet = new HashSet <ulong>();

            hashSet.Add(90923023);
            hashSet.Add(232300000);
            hashSet.Add(0);
            hashSet.Add(333);
            hashSet.Add(ulong.MaxValue);
            hashSet.Add(ulong.MinValue);

            UriBuilder anotherweirdtype = new UriBuilder("http://www.live.com");

            Stream stream = new MemoryStream();

            Variable <Dictionary <double, Guid> > dictionary = VariableHelper.CreateInitialized <Dictionary <double, Guid> >("dictionary", context => dict);
            Variable <HashSet <ulong> >           hash       = VariableHelper.CreateInitialized <HashSet <ulong> >("hash", hashSet);
            Variable <UriBuilder> uribuild    = VariableHelper.CreateInitialized <UriBuilder>("uribuild", anotherweirdtype);
            Variable <Stream>     streaminUSA = VariableHelper.CreateInitialized <Stream>("streaminUSA", stream);

            Guid         outguid  = Guid.Empty;
            TestSequence sequence = new TestSequence("Sequence1")
            {
                Variables =
                {
                    dictionary,
                    hash,
                    uribuild,
                    streaminUSA
                },
                Activities =
                {
                    new TestIf("if activity")
                    {
                        ConditionExpression = ((env) => ((Dictionary <double, Guid>)dictionary.Get(env)).TryGetValue(-0.233, out outguid)),
                        ThenActivity        = new TestWriteLine("In if 1", "In if 1"),
                    },
                    new TestIf("if activity")
                    {
                        ConditionExpression = ((env) => ((HashSet <ulong>)hash.Get(env)).SetEquals(hashSet)),
                        ThenActivity        = new TestWriteLine("In if 2", "In if 2"),
                    },
                    new TestIf("if activity")
                    {
                        ConditionExpression = ((env) => ((UriBuilder)uribuild.Get(env)).Equals(new Uri("http://www.live.com"))),
                        ThenActivity        = new TestWriteLine("In if 3", "In if 3"),
                    },
                    new TestIf("if activity")
                    {
                        ConditionExpression = ((env) => ((Stream)streaminUSA.Get(env)).Equals(stream)),
                        ThenActivity        = new TestWriteLine("In if 4", "In if 4"),
                    },
                }
            };

            TestRuntime.RunAndValidateWorkflow(sequence);

            if (outguid.CompareTo(new Guid("99999999-9999-9999-0000-123456789102")) != 0)
            {
                throw new Exception("guid value is wrong");
            }
        }
Exemplo n.º 29
0
        public void DifferentArguments()
        {
            //Testing Different argument types for Switch.Expression
            // DelegateInArgument
            // DelegateOutArgument
            // Activity<T>
            // Variable<T> , Activity<T> and Expression is already implemented.

            DelegateInArgument <string>  delegateInArgument  = new DelegateInArgument <string>("Input");
            DelegateOutArgument <string> delegateOutArgument = new DelegateOutArgument <string>("Output");

            TestCustomActivity <InvokeFunc <string, string> > invokeFunc = TestCustomActivity <InvokeFunc <string, string> > .CreateFromProduct(
                new InvokeFunc <string, string>
            {
                Argument = "PassedInValue",
                Func     = new ActivityFunc <string, string>
                {
                    Argument = delegateInArgument,
                    Result   = delegateOutArgument,
                    Handler  = new CoreWf.Statements.Sequence
                    {
                        DisplayName = "Sequence1",
                        Activities  =
                        {
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch1",
                                Expression  = delegateInArgument,
                                Cases       =
                                {
                                    {
                                        "PassedInValue",
                                        new CoreWf.Statements.Assign <string>
                                        {
                                            DisplayName = "Assign1",
                                            To          = delegateOutArgument,
                                            Value       = "OutValue",
                                        }
                                    },
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W1", Message = "This should not be printed"
                                },
                            },
                            new CoreWf.Statements.Switch <string>
                            {
                                DisplayName = "Switch2",
                                Expression  = delegateOutArgument,
                                Cases       =
                                {
                                    {
                                        "OutValue",
                                        new Test.Common.TestObjects.CustomActivities.WriteLine {
                                            DisplayName = "W2", Message = delegateOutArgument
                                        }
                                    }
                                },
                                Default = new Test.Common.TestObjects.CustomActivities.WriteLine{
                                    DisplayName = "W3", Message = "This should not be printed"
                                },
                            }
                        }
                    }
                }
            }
                );

            TestSwitch <string> switch1 = new TestSwitch <string>
            {
                DisplayName = "Switch1",
                Hints       = { 0 }
            };

            switch1.AddCase("PassedInValue", new TestAssign <string> {
                DisplayName = "Assign1"
            });
            switch1.Default = new TestWriteLine {
                DisplayName = "W1"
            };

            TestSwitch <string> switch2 = new TestSwitch <string>
            {
                DisplayName = "Switch2",
                Hints       = { 0 }
            };

            switch2.AddCase("OutValue", new TestWriteLine {
                DisplayName = "W2", HintMessage = "OutValue"
            });
            switch2.Default = new TestWriteLine {
                DisplayName = "W3"
            };

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  =
                {
                    switch1,
                    switch2,
                }
            };

            invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace);

            TestRuntime.RunAndValidateWorkflow(invokeFunc);
        }
Exemplo n.º 30
0
        public void BasicSequenceWithMultipleChildren()
        {
            //  Test case description:
            //  Execute sequence activity that has multiple different children in the Activities list and expect the
            //  execution result be sequential as in the order they were added to the Activities list

            Stack <Guid> stackOfGuids = new Stack <Guid>();

            stackOfGuids.Push(new Guid("11111111-1111-1111-1111-111111111111"));
            TestSequence sequence = new TestSequence("Sequence1");

            TestSequence sequence2 = new TestSequence("InnerSequence1");
            TestSequence sequence3 = new TestSequence("InnerSequence2");
            TestSequence sequence4 = new TestSequence("InnerSequence3");
            TestSequence sequence5 = new TestSequence("InnerSequence4");

            Variable <Stack <Guid> > stack = VariableHelper.Create <Stack <Guid> >("keyed_collection");

            TestInvokeMethod invokeact = new TestInvokeMethod("method invoke act", typeof(Sequence).GetMethod("CheckValue"));

            invokeact.TargetObject = new TestArgument <Sequence>(Direction.In, "TargetObject", (context => new Sequence()));
            invokeact.Arguments.Add(new TestArgument <Stack <Guid> >(Direction.In, "stack", stack));
            TestSequence sequence6 = new TestSequence("seq5")
            {
                Variables =
                {
                    stack
                },
                Activities =
                {
                    new TestWriteLine("hello writeline", "Hello from Mars"),
                    new TestAssign <Stack <Guid> >("assign activity ")
                    {
                        ToVariable      = stack,
                        ValueExpression = context => stackOfGuids,
                    },
                    new TestIf("ifact")
                    {
                        Condition    = true,
                        ThenActivity = invokeact
                    }
                }
            };
            TestSequence sequence7 = new TestSequence("seq6");
            TestSequence sequence8 = new TestSequence("seq7");
            TestSequence sequence9 = new TestSequence("seq8");


            TestWriteLine writeLine2 = new TestWriteLine("Hello Two");

            writeLine2.Message = string.Format("Hello world in {0} , {1} , {2}!", sequence.DisplayName, sequence3.DisplayName, sequence7.DisplayName);
            TestWriteLine writeLine3 = new TestWriteLine("Hello Three");

            writeLine3.Message = string.Format("Hello world in {0} , {1} , {2}!", sequence.DisplayName, sequence4.DisplayName, sequence8.DisplayName);
            TestWriteLine writeLine4 = new TestWriteLine("Hello Four");

            writeLine4.Message = string.Format("Hello world in {0} , {1} , {2}!", sequence.DisplayName, sequence5.DisplayName, sequence9.DisplayName);

            sequence7.Activities.Add(writeLine2);
            sequence8.Activities.Add(writeLine3);
            sequence9.Activities.Add(writeLine4);
            sequence2.Activities.Add(sequence6);
            sequence3.Activities.Add(sequence7);
            sequence4.Activities.Add(sequence8);
            sequence5.Activities.Add(sequence9);
            sequence.Activities.Add(sequence2);
            sequence.Activities.Add(sequence3);
            sequence.Activities.Add(sequence4);
            sequence.Activities.Add(sequence5);

            TestRuntime.RunAndValidateWorkflow(sequence);
        }