示例#1
0
        public void FlowSwitchHavingCaseWithNullKeyEvaluateNull()
        {
            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), new TestWriteLine("Default", "Default Activity")) as TestFlowSwitch <object>;

            flowSwitch.AddNullCase(new TestWriteLine("Four", "Four"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
示例#2
0
        public void FlowSwitchInLoopDefaultEvaluation()
        {
            TestFlowchart flowchart = new TestFlowchart();

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

            counter.Name = "counter";
            flowchart.Variables.Add(counter);

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

            cases.Add(10, new TestWriteLine("Ten", "Ten"));
            cases.Add(11, new TestWriteLine("Eleven", "Eleven"));
            cases.Add(12, new TestWriteLine("Twelve", "Twelve"));
            cases.Add(13, new TestWriteLine("Thirteen", "Thirteen"));

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

            for (int i = 0; i < 10; i++)
            {
                hints.Add(-1);
            }
            hints.Add(0);

            TestIncrement incByOne = new TestIncrement {
                IncrementCount = 1, CounterVariable = counter
            };

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

            flowchart.AddLink(incByOne, flowSwitch);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
示例#3
0
        public void FlowSwitchHavingCaseWithNullKeyEvaluateNull()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <Complex> complexVar = VariableHelper.CreateInitialized <Complex>("complexVar", (Complex)null);

            flowchart.Variables.Add(complexVar);

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

            cases.Add(new Complex(0, 0), new TestWriteLine("One", "One"));
            cases.Add(new Complex(1, 0), new TestWriteLine("Two", "Two"));
            cases.Add(new Complex(2, 0), new TestWriteLine("Three", "Three"));

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

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

            ((FlowSwitch <Complex>)flowSwitch.GetProductElement()).Cases.Add(null, new FlowStep {
                Action = new BlockingActivity("Blocking")
            });

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(flowchart))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing);
                runtime.ResumeBookMark("Blocking", null);

                runtime.WaitForCompletion(false);
            }
        }
示例#4
0
        public void FlowSwitchInLoopSameCaseEvaluation()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <int> switchVariable = VariableHelper.CreateInitialized <int>("switchVar", 0);
            Variable <int> ifVariable     = VariableHelper.CreateInitialized <int>("ifVar", 0);

            flowchart.Variables.Add(switchVariable);
            flowchart.Variables.Add(ifVariable);

            TestIncrement incrementIfVariable = new TestIncrement("Inc", 1)
            {
                CounterVariable = ifVariable
            };

            TestIncrement incrementSwitchVariable = new TestIncrement("IncSwitch", 1)
            {
                CounterVariable = switchVariable
            };

            TestWriteLine writeBegin = new TestWriteLine("Loop", "Looping");

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

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

            TestFlowConditional conditional = new TestFlowConditional(hintsList.ToArray())
            {
                ConditionExpression = env => ifVariable.Get(env) < 5
            };

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

            cases.Add(0, writeBegin);

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

            for (int i = 0; i < 5; i++)
            {
                hints.Add(0);
            }
            hints.Add(-1);

            flowchart.AddLink(new TestWriteLine("Start", "Flowchart started"), writeBegin);
            flowchart.AddConditionalLink(writeBegin, conditional, incrementIfVariable, incrementSwitchVariable);
            TestFlowSwitch <object> flowSwitch = flowchart.AddSwitchLink <object>(incrementIfVariable, cases, hints, env => switchVariable.Get(env), new TestWriteLine("Default", "Default")) as TestFlowSwitch <object>;

            flowchart.AddLink(incrementSwitchVariable, flowSwitch);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
示例#5
0
        public void FlowSwitchWithExpressionNull()
        {
            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 wDefault   = new TestWriteLine("wDefault", "Executing wDefault");

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

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

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

            hints.Add(-1);

            TestFlowSwitch <object> fSwitch = (TestFlowSwitch <object>)flowchart1.AddSwitchLink <object>(start1, cases, hints, (object)null, wDefault);

            ((FlowSwitch <object>)fSwitch.GetProductElement()).Expression = null; // I had to use the product to set a null value to Expression

            TestRuntime.ValidateInstantiationException(flowchart1, string.Format(ErrorStrings.FlowSwitchRequiresExpression, flowchart1.DisplayName));
        }