コード例 #1
0
        public void ThrowExceptionInElseBody()
        {
            //  Test case description:
            //  2 bracnhes:throw exception in the condition throw exception in if body, else executingthrow exception
            //  in else body if executingthrow exception in both branches if executingthrow exception in both branches
            //  else executing

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

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

            TestIf ifAct = new TestIf("if act", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestSequence("sequence in if"),
                ElseActivity        = innerSequence
            };

            TestThrow <ArithmeticException> throwArt = new TestThrow <ArithmeticException>("throw");

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

            TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>());
        }
コード例 #2
0
        public void CancelElseDuringExecution()
        {
            TestIf testIf = new TestIf("MyIf", HintThenOrElse.Else)
            {
                Condition    = false,
                ThenActivity = new TestWriteLine("Then Branch", "The message would not be displayed"),
                ElseActivity = new TestSequence("Else Branch")
                {
                    Activities =
                    {
                        new TestCustomActivity <BlockingActivity>("BlockingActivity", null)
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },
                        new TestWriteLine("Test WriteLine",                           "The message would not be displayed"),
                    },
                },
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testIf))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
コード例 #3
0
        public void SimpleIfThenOnly()
        {
            TestSequence   outerSequence = new TestSequence("sequence1");
            TestSequence   innerSequence = new TestSequence("innerseq");
            Variable <int> counter       = VariableHelper.CreateInitialized <int>("counter", 0);

            TestSequence ifSequence = new TestSequence("ifSequence");

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

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

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

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #4
0
        public void IfElseBodyHasVariable()
        {
            const string      varValue = "hello world";
            Variable <string> var      = VariableHelper.CreateInitialized <string>("aVariable", varValue);

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

            TestRuntime.RunAndValidateWorkflow(testIf);
        }
コード例 #5
0
    private static void Main()
    {
        TestIf test = new TestIf();

        test.SelectLanguage();

        Console.ReadKey();
    }
コード例 #6
0
        public void NoIfOrElseBranches()
        {
            TestIf ifAct = new TestIf("MyIf", HintThenOrElse.Then)
            {
                Condition = true,
            };


            TestRuntime.RunAndValidateWorkflow(ifAct);
        }
コード例 #7
0
        public void GetChildrenModifyChildrenExecute()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

            TestIf testIf = new TestIf("If", HintThenOrElse.Then, HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 1),
                ThenActivity        = new TestWriteLine("WriteLine Then")
                {
                    Message = "Executing activity in Then branch",
                },
                ElseActivity = new TestWriteLine("WriteLine Else")
                {
                    Message = "Executing activity in Else branch",
                },
            };

            TestSequence outerSequence = new TestSequence("Outer sequence")
            {
                Variables  = { counter },
                Activities =
                {
                    new TestDoWhile("DoWhile")
                    {
                        ConditionExpression = ((env) => counter.Get(env) < 2),
                        Body = new TestSequence("Inner sequence")
                        {
                            Activities =
                            {
                                testIf,
                                new TestAssign <int>("Increment Counter")
                                {
                                    ValueExpression = (env) => counter.Get(env) + 1,
                                    ToVariable      = counter,
                                },
                            }
                        },
                        HintIterationCount = 2,
                    }
                },
            };

            WorkflowInspectionServices.GetActivities(testIf.ProductActivity);

            testIf.ThenActivity = new TestWriteLine("Then")
            {
                Message = "In Then branch",
            };
            testIf.ElseActivity = new TestWriteLine("Else")
            {
                Message = "In Else branch",
            };

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #8
0
        public void IfConditionSetToTrue()
        {
            //  Test case description:
            //  Set condition to null
            TestIf ifAct = new TestIf("if act", HintThenOrElse.Then)
            {
                Condition    = true,
                ThenActivity = new TestWriteLine("Write Hello", "It's a small world after all"),
            };

            TestRuntime.RunAndValidateUsingWorkflowInvoker(ifAct, null, null, null);
        }
コード例 #9
0
        //[HostWorkflowAsWebService]
        public void IfInWhileSometimesIfThenTrueSometimesElseTrue()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

            TestWriteLine writeTrue = new TestWriteLine("writeTrue")
            {
                Message = "I say you are RIGHT!"
            };

            TestWriteLine writeFalse = new TestWriteLine("writeFalse")
            {
                Message = "I say you are WRONG!"
            };

            TestIf ifAct = new TestIf("if act",
                                      HintThenOrElse.Then,
                                      HintThenOrElse.Else,
                                      HintThenOrElse.Then,
                                      HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) % 2 == 0),
                ThenActivity        = writeTrue,
                ElseActivity        = writeFalse,
            };

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

            TestSequence sequence = new TestSequence("innerSequence");

            sequence.Activities.Add(ifAct);
            sequence.Activities.Add(increment);

            TestWhile whileAct = new TestWhile("while act")
            {
                ConditionExpression = (env) => ((int)counter.Get(env)) < 4,
                Body = sequence,
                HintIterationCount = 4,
            };

            TestSequence rootSequence = new TestSequence("rootSequence");

            rootSequence.Activities.Add(whileAct);
            rootSequence.Variables.Add(counter);

            TestRuntime.RunAndValidateWorkflow(rootSequence);
        }
コード例 #10
0
        public void IfWithWorkflowInvoker()
        {
            TestIf ifAct = new TestIf("MyIf", HintThenOrElse.Then)
            {
                ThenActivity = new TestWriteLine("w", "I'm Funny"),
                ElseActivity = new TestWriteLine("w", "I'm not Funny!")
            };


            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("Condition", true);
            TestRuntime.RunAndValidateUsingWorkflowInvoker(ifAct, args, null, null);
        }
コード例 #11
0
        public void CompositeProcedurals()
        {
            Variable <bool> cond = new Variable <bool> {
                Default = true
            };
            Variable <string> value = new Variable <string> {
                Default = "Apple"
            };
            DelegateInArgument <string> arg = new DelegateInArgument <string> {
                Name = "Apple"
            };

            string[] values = { "a", "b" };

            TestSwitch <string> switchAct = new TestSwitch <string>
            {
                ExpressionVariable = value
            };

            switchAct.AddCase("Apple", new TestWriteLine("Apple", "this is an apple"));
            switchAct.AddCase("Orange", new TestWriteLine("Orange", "this is an orange"));
            switchAct.Hints.Add(0);

            TestIf ifAct = new TestIf(HintThenOrElse.Then)
            {
                ConditionVariable = cond,
                ThenActivity      = new TestWriteLine("W", "Yes thats true"),
                ElseActivity      = new TestWriteLine("W", "No thats not true")
            };

            TestForEach <string> forEachAct = new TestForEach <string>
            {
                Values             = values,
                CurrentVariable    = arg,
                HintIterationCount = 2,
                Body = new TestWriteLine {
                    DisplayName = "w1", MessageExpression = context => arg.Get(context), HintMessageList = { "a", "b" }
                }
            };

            TestSequence seq = new TestSequence
            {
                Variables  = { cond, value },
                Activities = { switchAct, ifAct, forEachAct }
            };

            TestRuntime.RunAndValidateWorkflow(seq);
        }
コード例 #12
0
        public void SimpleIfElseOnly()
        {
            //  Test case description:
            //  Have single branched if-else (just else)

            TestSequence sequence = new TestSequence("Sequence1");
            TestIf       ifAct    = new TestIf("MyIf", HintThenOrElse.Else)
            {
                Condition    = false,
                ElseActivity = new TestWriteLine("Else Branch", "Else Exeuting"),
            };

            sequence.Activities.Add(ifAct);

            TestRuntime.RunAndValidateWorkflow(sequence);
        }
コード例 #13
0
        public void BasicIfTest()
        {
            TestSequence     outerSequence = new TestSequence("sequence1");
            TestSequence     innerSequence = new TestSequence("innerseq");
            TestAssign <int> increment     = new TestAssign <int>("Increment Counter");
            Variable <int>   counter       = VariableHelper.CreateInitialized <int>("counter", 0);

            TestSequence ifSequence = new TestSequence("ifSequence");


            TestDoWhile whileAct = new TestDoWhile("dowhile")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                Body = ifSequence,
                HintIterationCount = 10,
            };

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

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

            TestIf ifAct = new TestIf("if act", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("NotExecuting Writeline", "Shouldnt appear on screen"),
                ElseActivity        = writeLine
            };

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

            ifSequence.Activities.Add(ifAct);
            ifSequence.Activities.Add(ifAct2);
            innerSequence.Activities.Add(increment);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(whileAct);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #14
0
        public void CompletionConditionCancelsRestOfBranches()
        {
            Variable <bool> cancelIt = new Variable <bool> {
                Name = "cancelIt", Default = false
            };
            DelegateInArgument <int> i = new DelegateInArgument <int>()
            {
                Name = "i"
            };

            TestWriteLine w1 = new TestWriteLine("w1", "write1")
            {
                HintMessageList = { "write1", "write1", "write1" }
            };
            TestAssign <bool> a1 = new TestAssign <bool>
            {
                Value      = true,
                ToVariable = cancelIt,
            };

            TestIf decide = new TestIf(HintThenOrElse.Else, HintThenOrElse.Else, HintThenOrElse.Then)
            {
                ConditionExpression = ((ctx) => i.Get(ctx) < 5),
                ThenActivity        = a1,
                ElseActivity        = w1,
            };

            TestParallelForEach <int> foreachAct = new TestParallelForEach <int>("foreach")
            {
                HintValues         = new int[] { 1, 2, 3, 4, 5, 6 },
                ValuesExpression   = (context => new int[] { 1, 2, 3, 4, 5, 6 }),
                CurrentVariable    = i,
                HintIterationCount = 3,
                Body = decide,
                CompletionConditionVariable = cancelIt,
            };

            TestSequence sequence = new TestSequence
            {
                Activities = { foreachAct },
                Variables  = { cancelIt },
            };

            TestRuntime.RunAndValidateWorkflow(sequence);
        }
コード例 #15
0
        public void SetIfConditionToNull()
        {
            //  Test case description:
            //  Set condition to null
            TestIf ifAct = new TestIf("if act", HintThenOrElse.Then)
            {
                ConditionVariable = null,
                ThenActivity      = new TestWriteLine("write hello", "Its a small world after all"),
            };
            TestSequence seq = new TestSequence();

            seq.Activities.Add(ifAct);

            string exceptionMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Condition");
            List <TestConstraintViolation> constraints = new List <TestConstraintViolation>();

            constraints.Add(new TestConstraintViolation(exceptionMessage, ifAct.ProductActivity, false));

            TestRuntime.ValidateWorkflowErrors(seq, constraints, exceptionMessage);
        }
コード例 #16
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")
            {
                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);
        }
コード例 #17
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);
        }
コード例 #18
0
        public void DifferentArguments()
        {
            //Testing Different argument types for DoWhile.Condition
            // DelegateInArgument
            // DelegateOutArgument
            // 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 Microsoft.CoreWf.Statements.Sequence
                    {
                        DisplayName = "sequence1",
                        Activities  =
                        {
                            new Microsoft.CoreWf.Statements.DoWhile
                            {
                                DisplayName = "DoWhile1",
                                Condition   = ExpressionServices.Convert <bool>(ctx => delegateInArgument.Get(ctx)),
                                Body        = new Microsoft.CoreWf.Statements.Assign <bool>
                                {
                                    DisplayName = "Assign1",
                                    To          = delegateInArgument,
                                    Value       = new Not <bool, bool> {
                                        DisplayName = "Not1", Operand = delegateInArgument
                                    }
                                },
                            },
                            new Microsoft.CoreWf.Statements.Assign <bool>
                            {
                                DisplayName = "Assign2",
                                To          = delegateOutArgument,
                                Value       = new Not <bool, bool> {
                                    DisplayName = "Not2", Operand = delegateInArgument
                                },
                            },
                            new Microsoft.CoreWf.Statements.DoWhile
                            {
                                DisplayName = "DoWhile2",
                                Condition   = ExpressionServices.Convert <bool>(ctx => !delegateOutArgument.Get(ctx)),
                                Body        = new Microsoft.CoreWf.Statements.Assign <bool>
                                {
                                    DisplayName = "Assign3",
                                    To          = delegateOutArgument,
                                    Value       = new Not <bool, bool> {
                                        DisplayName = "Not3", Operand = delegateInArgument
                                    }
                                },
                            },
                        },
                    }
                }
            }
                );

            TestSequence sequenceForTracing = new TestSequence
            {
                DisplayName = "sequence1",
                Activities  =
                {
                    new TestDoWhile
                    {
                        DisplayName            = "DoWhile1",
                        ActivitySpecificTraces =
                        {
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("Assign1",                        ActivityInstanceState.Executing),
                                    new ActivityTrace("Not1",                           ActivityInstanceState.Executing),
                                    new ActivityTrace("Not1",                           ActivityInstanceState.Closed),
                                    new ActivityTrace("Assign1",                        ActivityInstanceState.Closed),
                                    new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Executing),
                                    new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Closed),
                                }
                            },
                        }
                    },
                    new TestAssign <bool>
                    {
                        DisplayName   = "Assign2",
                        ValueActivity = new Test.Common.TestObjects.Activities.Expressions.TestNot <bool, bool>{
                            DisplayName = "Not2"
                        }
                    },
                    new TestDoWhile
                    {
                        DisplayName            = "DoWhile2",
                        ActivitySpecificTraces =
                        {
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("Assign3",              ActivityInstanceState.Executing),
                                    new ActivityTrace("Not3",                 ActivityInstanceState.Executing),
                                    new ActivityTrace("Not3",                 ActivityInstanceState.Closed),
                                    new ActivityTrace("Assign3",              ActivityInstanceState.Closed),
                                    new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Executing),
                                    new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Closed),
                                }
                            },
                        }
                    },
                }
            };

            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);
        }
コード例 #19
0
ファイル: WhileActivity.cs プロジェクト: sunxiaotianmg/CoreWF
        public void NestedWhilesAndOtherLoops()
        {
            //  Test case description:
            //  Nested whiles deep up to 3-5 levels. Set valid conditions trace the order to be likewhile1 loop1 while2
            //  loop 1 while 3 loop1 while1 loop1 while2 loop1 whle3 loop2while1 loop1 while2 loop2 while3 loop1whlie1
            //  loop1 while2 loop2 while3 loop2…while1 loop2 while2 loop2 while3 loop2

            TestSequence     outerSequence = new TestSequence("sequence1");
            TestSequence     innerSequence = new TestSequence("inner seq");
            TestAssign <int> increment     = new TestAssign <int>("increase count");

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

            TestAssign <int> loopCounterIncrement = new TestAssign <int>("increase loop counter")
            {
                ToVariable      = loopCounter,
                ValueExpression = ((env) => ((int)loopCounter.Get(env)) + 1)
            };

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

            TestForEach <string> foreachAct = new TestForEach <string>("ForEach")
            {
                Body               = innerSequence,
                ValuesExpression   = (context => new List <string>()
                {
                    "var1", "var2", "var3"
                }),
                HintIterationCount = 3,
            };

            TestDoWhile doWhile = new TestDoWhile("do while")
            {
                ConditionExpression = ((env) => ((int)doWhileCounter.Get(env)) < 9),
                Body = foreachAct,
                HintIterationCount = 3,
            };

            TestSequence     whileSequence   = new TestSequence("sequence1");
            TestSequence     innerIfSequence = new TestSequence("inner if sequence");
            TestAssign <int> whileIncrement  = new TestAssign <int>("increase count2");

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

            TestSequence ifSequence = new TestSequence("ifSequence");


            TestWhile whileAct = new TestWhile("while")
            {
                ConditionExpression = ((env) => ((int)whileCounter.Get(env)) < 10),
                Body = ifSequence,
                HintIterationCount = 10,
            };

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

            whileIncrement.ToVariable      = whileCounter;
            whileIncrement.ValueExpression = ((env) => ((int)whileCounter.Get(env)) + 1);

            TestIf ifAct = new TestIf("ifact 1", HintThenOrElse.Else)
            {
                ConditionExpression = ((env) => ((int)whileCounter.Get(env)) > 10),
                ThenActivity        = new TestWriteLine("w1", "I'm a non-executing funny writeLine"),
                ElseActivity        = writeLine2,
            };
            TestIf ifAct2 = new TestIf("if act 2", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)whileCounter.Get(env)) < 10),
                ThenActivity        = innerIfSequence,
            };

            TestIf checkLoopCount = new TestIf("check loop count", HintThenOrElse.Then)
            {
                ConditionExpression = ((env) => ((int)loopCounter.Get(env)) == 90),
                ThenActivity        = writeLine,
            };

            ifSequence.Activities.Add(ifAct);
            ifSequence.Activities.Add(ifAct2);
            innerIfSequence.Activities.Add(whileIncrement);
            innerIfSequence.Activities.Add(loopCounterIncrement);
            whileSequence.Variables.Add(whileCounter);
            whileSequence.Activities.Add(whileAct);

            innerSequence.Activities.Add(increment);
            innerSequence.Activities.Add(whileSequence);
            outerSequence.Activities.Add(doWhile);
            outerSequence.Activities.Add(checkLoopCount);
            outerSequence.Variables.Add(doWhileCounter);
            outerSequence.Variables.Add(loopCounter);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #20
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);
        }