コード例 #1
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);
        }
コード例 #2
0
        public void DoWhileWithWorkFlowInvoker()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);

            TestAssign <int> increment = new TestAssign <int>("Increment Counter");

            increment.ToVariable      = counter;
            increment.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");

            writeLine.Message = "Its a small world after all";

            TestRuntime.RunAndValidateUsingWorkflowInvoker(doWhile, null, null, null);
        }
コード例 #3
0
        public void ThrowExceptionFromSetterOfCustomTypeProperty()
        {
            //
            //  Test case description:
            //  Try setting a property which throws from setter.

            TheStruct valueType = new TheStruct();

            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Default = valueType, Name = "var"
            };
            TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>()
            {
                PropertyName            = "ThrowInSetterProperty",
                OperandLocationVariable = var,
            };

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation      = valueTypePropertyReference,
                Value           = value,
                ExpectedOutcome = Outcome.UncaughtException(typeof(System.Reflection.TargetInvocationException)),
            };

            TestSequence seq = new TestSequence()
            {
                Variables  = { var },
                Activities =
                {
                    testAssign,
                }
            };

            TestRuntime.RunAndValidateAbortedException(seq, typeof(System.Reflection.TargetInvocationException), null);
        }
コード例 #4
0
ファイル: Loops.cs プロジェクト: sunxiaotianmg/CoreWF
        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);
        }
コード例 #5
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");
        }
コード例 #6
0
        public void SetDelegateArgument()
        {
            // for using delegate argument

            TheStruct valueType             = new TheStruct();
            int       indiceValue           = 2;
            DelegateInArgument <int> indice = new DelegateInArgument <int>();
            Variable <TheStruct>     var    = VariableHelper.CreateInitialized <TheStruct>("var", valueType);
            TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>()
            {
                OperandLocationVariable = var,
            };

            valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, (env) => indice.Get(env)));

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx)[indiceValue].ToString())
                    }
                }
            };

            CoreWf.Statements.Sequence outerSeq = new CoreWf.Statements.Sequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new InvokeAction <int>()
                    {
                        Argument = indiceValue,
                        Action   = new ActivityAction <int>()
                        {
                            Argument = indice,
                            Handler  = seq.ProductActivity
                        }
                    }
                }
            };

            TestCustomActivity testActivity = TestCustomActivity <CoreWf.Statements.Sequence> .CreateFromProduct(outerSeq);

            UnorderedTraces traces = new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace(value.ToString())
                }
            };

            testActivity.ActivitySpecificTraces.Add(traces);
            ExpectedTrace expectedTrace = testActivity.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(ActivityTrace));

            TestRuntime.RunAndValidateWorkflow(testActivity, expectedTrace);
        }
コード例 #7
0
ファイル: Assign.cs プロジェクト: sunxiaotianmg/CoreWF
        public void EmptyAssignmentStandAlone()
        {
            TestAssign <string> assign = new TestAssign <string>();

            TestRuntime.ValidateInstantiationException(assign, typeof(System.ArgumentException), string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Value"));
        }
コード例 #8
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);
        }
コード例 #9
0
        public void ExecuteFiveLevelDeepNestedLoops()
        {
            TestFlowchart flowchart = new TestFlowchart("Flowchart1");

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

            flowchart.Variables.Add(loop1Counter);

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

            flowchart.Variables.Add(loop2Counter);

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

            flowchart.Variables.Add(loop3Counter);

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

            flowchart.Variables.Add(loop4Counter);

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

            flowchart.Variables.Add(loop5Counter);

            TestAssign <int> assign1 = new TestAssign <int>("Assign1");

            assign1.ValueExpression = ((env) => (int)loop1Counter.Get(env) + 1);
            assign1.ToVariable      = loop1Counter;

            TestAssign <int> assign2 = new TestAssign <int>("Assign2");

            assign2.ValueExpression = ((env) => (int)loop2Counter.Get(env) + 1);
            assign2.ToVariable      = loop2Counter;

            TestAssign <int> assign3 = new TestAssign <int>("Assign3");

            assign3.ValueExpression = ((env) => (int)loop3Counter.Get(env) + 1);
            assign3.ToVariable      = loop3Counter;

            TestAssign <int> assign4 = new TestAssign <int>("Assign4");

            assign4.ValueExpression = ((env) => (int)loop4Counter.Get(env) + 1);
            assign4.ToVariable      = loop4Counter;

            TestAssign <int> assign5 = new TestAssign <int>("Assign5");

            assign5.ValueExpression = ((env) => (int)loop5Counter.Get(env) + 1);
            assign5.ToVariable      = loop5Counter;

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

            for (int i = 0; i < 5; i++)
            {
                hintsList.Add(HintTrueFalse.True);
            }
            hintsList.Add(HintTrueFalse.False);

            HintTrueFalse[]     hints         = hintsList.ToArray();
            TestFlowConditional flowDecision1 = new TestFlowConditional(hints);

            flowDecision1.ConditionExpression = (env => loop1Counter.Get(env) <= 5);

            TestFlowConditional flowDecision2 = new TestFlowConditional(hints);

            flowDecision2.ConditionExpression = (env => loop2Counter.Get(env) <= 5);

            TestFlowConditional flowDecision3 = new TestFlowConditional(hints);

            flowDecision3.ConditionExpression = (env => loop3Counter.Get(env) <= 5);

            TestFlowConditional flowDecision4 = new TestFlowConditional(hints);

            flowDecision4.ConditionExpression = (env => loop4Counter.Get(env) <= 5);

            TestFlowConditional flowDecision5 = new TestFlowConditional(hints);

            flowDecision5.ConditionExpression = (env => loop5Counter.Get(env) <= 5);

            flowchart.AddLink(new TestWriteLine("Start", "Flowchart started"), assign1);

            flowchart.AddLink(assign1, assign2);
            flowchart.AddLink(assign2, assign3);
            flowchart.AddLink(assign3, assign4);
            flowchart.AddLink(assign4, assign5);

            flowchart.AddConditionalLink(assign5, flowDecision5, assign5, flowDecision4);

            flowchart.AddConditionalLink((TestActivity)null, flowDecision4, assign4, flowDecision3);

            flowchart.AddConditionalLink((TestActivity)null, flowDecision3, assign3, flowDecision2);

            flowchart.AddConditionalLink((TestActivity)null, flowDecision2, assign2, flowDecision1);

            flowchart.AddConditionalLink((TestActivity)null, flowDecision1, assign1, new TestWriteLine("End", "Flowchart ended"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
コード例 #10
0
        public void NestedLoopsExecution()
        {
            TestFlowchart flowchart = new TestFlowchart("Flow1");

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

            flowchart.Variables.Add(innerLoopcounter);

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

            flowchart.Variables.Add(outerLoopCounter);

            TestAssign <int> outerAssign = new TestAssign <int>("OuterAssign");

            outerAssign.ValueExpression = ((env) => ((int)outerLoopCounter.Get(env)) + 1);
            outerAssign.ToVariable      = outerLoopCounter;

            TestAssign <int> innerAssign = new TestAssign <int>("InnerAssign");

            innerAssign.ValueExpression = (env) => ((int)innerLoopcounter.Get(env)) + 1;
            innerAssign.ToVariable      = innerLoopcounter;

            TestAssign <int> resetInnerCounter = new TestAssign <int>("ResetInnerCounter");

            resetInnerCounter.Value      = 0;
            resetInnerCounter.ToVariable = innerLoopcounter;

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

            for (int i = 0; i < 9; i++)
            {
                outerHints.Add(HintTrueFalse.True);
            }
            outerHints.Add(HintTrueFalse.False);
            TestFlowConditional outerFlowDecision = new TestFlowConditional(outerHints.ToArray());

            outerFlowDecision.ConditionExpression = (context => outerLoopCounter.Get(context) < 10);

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

            for (int i = 0; i < 4; i++)
            {
                innerHints.Add(HintTrueFalse.True);
            }
            innerHints.Add(HintTrueFalse.False);
            TestFlowConditional innerFlowDecision = new TestFlowConditional(innerHints.ToArray());

            innerFlowDecision.ConditionExpression = (context => innerLoopcounter.Get(context) < 5);
            innerFlowDecision.ResetHints          = true;

            flowchart.AddLink(new TestWriteLine("Start", "Flowchart started"), outerAssign);

            flowchart.AddLink(outerAssign, resetInnerCounter);

            flowchart.AddLink(resetInnerCounter, innerAssign);

            flowchart.AddConditionalLink(innerAssign, innerFlowDecision, innerAssign, outerFlowDecision);

            flowchart.AddConditionalLink(null, outerFlowDecision, outerAssign, new TestWriteLine("End", "Flowchart completed"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
コード例 #11
0
ファイル: Loops.cs プロジェクト: sunxiaotianmg/CoreWF
        public void Flowchart_ForEach()
        {
            TestFlowchart flowchart = new TestFlowchart("Flow1");

            List <int> tenInts = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            Variable <List <int> > listOfInts = new Variable <List <int> >("listOfInts",
                                                                           (env) => new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            });

            flowchart.Variables.Add(listOfInts);

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

            flowchart.Variables.Add(counter);

            Variable <bool> boolVar = VariableHelper.CreateInitialized <bool>("boolVar", true);

            flowchart.Variables.Add(boolVar);

            Variable <IEnumerator <int> > intEnumerator = VariableHelper.Create <IEnumerator <int> >("intEnumerator");

            flowchart.Variables.Add(intEnumerator);

            TestAssign <IEnumerator <int> > assign1 = new TestAssign <IEnumerator <int> >("Assign1")
            {
                ValueExpression = ((env) => ((List <int>)listOfInts.Get(env)).GetEnumerator()),
                ToVariable      = intEnumerator
            };

            TestAssign <bool> assign2 = new TestAssign <bool>("Assign2")
            {
                ValueExpression = ((env) => ((IEnumerator <int>)intEnumerator.Get(env)).MoveNext()),
                ToVariable      = boolVar
            };

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

            for (int i = 0; i < 10; i++)
            {
                hints.Add(HintTrueFalse.True);
            }
            hints.Add(HintTrueFalse.False);
            TestFlowConditional flowDecision = new TestFlowConditional(hints.ToArray())
            {
                ConditionExpression = (context => boolVar.Get(context) == true)
            };

            flowchart.AddStartLink(assign1);

            flowchart.AddLink(assign1, assign2);

            flowchart.AddConditionalLink(assign2, flowDecision, assign2, new TestWriteLine("End", "Flowchart ended"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }