Example #1
0
        public void BasicDoWhileExecuteOnce()
        {
            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);

            TestDoWhile doWhile = new TestDoWhile("dowhile")
            {
                ConditionExpression = (env) => ((int)counter.Get(env)) < 0,
                Body = innerSequence,
                HintIterationCount = 1,
            };

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

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


            innerSequence.Activities.Add(writeLine);
            innerSequence.Activities.Add(increment);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(doWhile);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Example #2
0
        public void DoWhileCancelled()
        {
            TestDoWhile doWhile = new TestDoWhile("Do while")
            {
                Condition = true,
                Body      = new TestSequence("Do While Body")
                {
                    Activities =
                    {
                        new TestBlockingActivity("BlockingActivity", "Bookmark")
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },

                        new TestWriteLine("Writeline")
                        {
                            Message = "Hello"
                        }
                    }
                },

                HintIterationCount = 1,
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(doWhile))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                // This test is not run on desktop and I don't think it would pass there if it did run.
                //testWorkflowRuntime.WaitForCompletion();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Example #3
0
        public void SimpleDoWhileConditionFalseSetToTrue()
        {
            //  Test case description:
            //  Set condition to a valid rule and run with an activity in it. Condition is false initially, then set to
            //  true in the do part.

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

            TestDoWhile doWhile = new TestDoWhile("do while")
            {
                ConditionExpression = ((env) => (counter.Get(env) == 1)),
                Body = innerSequence,
                HintIterationCount = 2,
            };

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

            writeLine.Message = "set the counter to be 1";
            o1o.ToVariable    = counter;
            // Use the mod make it as Zero-One-Zero.
            o1o.ValueExpression = ((env) => (counter.Get(env) + 1) % 2);

            innerSequence.Activities.Add(writeLine);
            innerSequence.Activities.Add(o1o);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(doWhile);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Example #4
0
        public void SimpleDoWhileConditionTrueSetToFalse()
        {
            TestSequence     outerSequence = new TestSequence("sequence1");
            TestSequence     innerSequence = new TestSequence("inner seq");
            TestAssign <int> o1o           = new TestAssign <int>("Hong");
            Variable <int>   counter       = VariableHelper.CreateInitialized <int>("counter", 0);

            TestDoWhile doWhile = new TestDoWhile("do while")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) == 0),
                Body = innerSequence,
                HintIterationCount = 1,
            };

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

            writeLine.Message = "The world is changing all the time";
            o1o.ToVariable    = counter;
            // Use the mod make it as Zero-One-Zero.
            o1o.ValueExpression = ((env) => ((((int)counter.Get(env))) + 1) % 2);

            innerSequence.Activities.Add(writeLine);
            innerSequence.Activities.Add(o1o);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(doWhile);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Example #5
0
        public void DoWhileWithWorkFlowInvoker()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

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

            TestDoWhile doWhile = new TestDoWhile("dowhile")
            {
                ConditionExpression = (env) => ((int)counter.Get(env)) < 2,
                Body = increment,
                HintIterationCount = 2,
                Variables          = { counter }
            };

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

            TestRuntime.RunAndValidateUsingWorkflowInvoker(doWhile, null, null, null);
        }
Example #6
0
        public void GetChildrenModifyChildrenExecute()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);
            TestDoWhile    doWhile = new TestDoWhile("dowhile act")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                Body = new TestSequence("test sequence act")
                {
                    Activities =
                    {
                        new TestWriteLine("wrong activity", "Its a big world after all"),
                        new TestAssign <int>("Increment Counter")
                        {
                            ToVariable      = counter,
                            ValueExpression = ((env) => (((int)counter.Get(env))) + 1),
                        },
                    },
                },
                HintIterationCount = 5,
            };
            TestSequence outerSequence = new TestSequence("sequence1")
            {
                Variables =
                {
                    counter
                },
                Activities =
                {
                    doWhile,
                }
            };

            WorkflowInspectionServices.GetActivities(doWhile.ProductActivity);

            doWhile.ConditionExpression = (env) => ((int)counter.Get(env)) < 5;
            doWhile.Body = new TestSequence("test sequence act")
            {
                Activities =
                {
                    new TestWriteLine("write hello", "Its a small world after all"),
                    new TestAssign <int>("Increment Counter")
                    {
                        ToVariable      = counter,
                        ValueExpression = ((env) => (((int)counter.Get(env))) + 1),
                    },
                },
            };

            // We need to recache the metadata now that we've changed the tree
            WorkflowInspectionServices.CacheMetadata(outerSequence.ProductActivity);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
Example #7
0
        public void DoWhileConditionInConstructor()
        {
            TestExpressionEvaluator <bool> condition = new TestExpressionEvaluator <bool>
            {
                ExpressionResult = false
            };

            TestDoWhile doWhile = new TestDoWhile(condition)
            {
                Body = new TestWriteLine("Hello", "Hello"),
                HintIterationCount = 1
            };

            TestRuntime.RunAndValidateWorkflow(doWhile);
        }
Example #8
0
        public void DoWhileConditionNull()
        {
            //  Test case description:
            //  Set condition to null
            TestDoWhile doWhile = new TestDoWhile("dowhile")
            {
                Condition          = true,
                Body               = new TestSequence("inner seq"),
                HintIterationCount = 0,
            };

            Microsoft.CoreWf.Statements.DoWhile productDoWhile = (Microsoft.CoreWf.Statements.DoWhile)doWhile.ProductActivity;
            productDoWhile.Condition = null;

            TestRuntime.ValidateInstantiationException(doWhile, String.Format("Condition must be set before DoWhile activity '{0}' can be used.", doWhile.DisplayName));
        }
Example #9
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);
        }
Example #10
0
        public void SimpleEmptyDoWhile()
        {
            //  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);

            TestDoWhile doWhile = new TestDoWhile("dowhile")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 0),
                Body = new TestSequence("inner seq"),
                HintIterationCount = 1,
                Variables          = { counter }
            };

            doWhile.Body = null;
            TestRuntime.RunAndValidateWorkflow(doWhile);
        }
Example #11
0
        public void DoWhileInfiniteLoopFaultAfterHundredLoops()
        {
            //  Test case description:
            //  Set condition to be an infinite loop (i.e. always true, or directly to true) and put an activity in it
            //  that will have fault

            Variable <int>        counter = new Variable <int>("Counter", 0);
            List <HintThenOrElse> hints   = new List <HintThenOrElse>();

            for (int i = 0; i < 100; i++)
            {
                hints.Add(HintThenOrElse.Else);
            }
            hints.Add(HintThenOrElse.Then);

            TestDoWhile doWhile = new TestDoWhile
            {
                Variables           = { counter },
                ConditionExpression = (e) => counter.Get(e) >= 0,
                Body = new TestSequence
                {
                    Activities =
                    {
                        new TestIf(hints.ToArray())
                        {
                            ConditionExpression = (e) => counter.Get(e) == 100,
                            ThenActivity        = new TestThrow <Exception>()
                        },
                        new TestIncrement
                        {
                            CounterVariable = counter,
                            IncrementCount  = 1
                        }
                    }
                },
                HintIterationCount = 101
            };

            TestRuntime.RunAndValidateAbortedException(doWhile, typeof(Exception), null);
        }
Example #12
0
        public void DoWhilePersisted()
        {
            Variable <int>       counter  = new Variable <int>("Counter", 0);
            TestBlockingActivity blocking = new TestBlockingActivity("B");

            TestDoWhile doWhile = new TestDoWhile
            {
                Variables           = { counter },
                ConditionExpression = (env) => counter.Get(env) < 1,
                Body = new TestSequence
                {
                    Activities =
                    {
                        blocking,
                        new TestIncrement
                        {
                            IncrementCount  = 1,
                            CounterVariable = counter
                        }
                    }
                },
                HintIterationCount = 1
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(doWhile, null, jsonStore, PersistableIdleAction.None))
            {
                runtime.ExecuteWorkflow();

                runtime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                runtime.PersistWorkflow();

                runtime.ResumeBookMark("B", null);

                runtime.WaitForCompletion();
            }
        }
Example #13
0
        public void DoWhileConditionThrowsException()
        {
            Variable <int> intVar = VariableHelper.CreateInitialized <int>("intVar", 3);

            TestDoWhile doWhile = new TestDoWhile("Do While")
            {
                ConditionOutcome = Outcome.UncaughtException(typeof(DivideByZeroException)),
                Variables        =
                {
                    intVar
                },

                ConditionExpression = ((env) => (1 / ((int)(intVar.Get(env)) - 3) == 0)),
                Body = new TestWriteLine("Writeline")
                {
                    Message = "This will be displayed once"
                },

                HintIterationCount = 1
            };

            TestRuntime.RunAndValidateAbortedException(doWhile, typeof(DivideByZeroException), new Dictionary <string, string>());
        }
Example #14
0
        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);
        }