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

            TestFlowStep flowStep1 = new TestFlowStep(w1);

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

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

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

            hints.Add(1);

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

            flowchart1.Elements.Add(flowStep1);

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Example #2
0
        public void SwitchExpressionOnExistingVariable()
        {
            TestFlowchart flowchart = new TestFlowchart();

            const string      defaultValue = "Two";
            Variable <string> stringVar    = VariableHelper.CreateInitialized <string>("stringVar", defaultValue);

            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"));
            cases.Add("Four", new TestWriteLine("Four", "Four"));
            cases.Add("Five", new TestWriteLine("Five", "Five"));

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

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #3
0
        public void FlowDecisionConnectedToFlowSwitch()
        {
            TestFlowchart  flowchart = new TestFlowchart("Flow1");
            Variable <int> counter   = VariableHelper.CreateInitialized <int>("counter", 3);

            flowchart.Variables.Add(counter);

            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");
            TestWriteLine w1         = new TestWriteLine("WriteLine1", "Executing WriteLine1");
            TestWriteLine w2         = new TestWriteLine("WriteLine2", "Executing WriteLine2");
            TestWriteLine w3         = new TestWriteLine("WriteLine3", "Executing WriteLine3");
            TestWriteLine wDefault   = new TestWriteLine("wDefault", "Executing wDefault");

            TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.False)
            {
                ConditionExpression = (context => counter.Get(context) > 4)
            };

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

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

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

            hints.Add(1);

            TestFlowElement switchElement = flowchart.AddSwitchLink <string>(null, cases, hints, "Two", wDefault);

            flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, switchElement);
            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #4
0
        public void ThrowWhileEvaluatingExpression()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeHello = new TestWriteLine("Hello", "Hello");

            TestWriteLine writeStart = new TestWriteLine("Start", "Start");

            TestExpressionEvaluatorWithBody <string> expressionActivity = new TestExpressionEvaluatorWithBody <string>("One")
            {
                Body = new TestThrow <ArgumentOutOfRangeException>()
            };

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

            cases.Add("One", new TestWriteLine("One", "One will not execute"));
            cases.Add("Two", new TestWriteLine("Two", "Two will not execute"));

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

            flowchart.AddStartLink(writeStart);

            flowchart.AddSwitchLink <string>(writeStart, cases, hints, expressionActivity, new TestWriteLine("Default", "Will not execute"));

            TestRuntime.RunAndValidateAbortedException(flowchart, typeof(ArgumentOutOfRangeException), null);
        }
Example #5
0
        public void SimpleFlowSwitchWithThreeElements()
        {
            TestFlowchart  flowchart  = new TestFlowchart();
            Variable <int> expression = new Variable <int> {
                Name = "expression", Default = 2
            };

            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 <int, TestActivity> cases = new Dictionary <int, TestActivity>();

            cases.Add(1, w1);
            cases.Add(2, w2);
            cases.Add(3, w3);

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

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #6
0
        public void CasesWithAllKeysCustomType()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <object> expressionVariable = new Variable <object>("expression", context => new SwitchExpressionClass(1));

            flowchart.Variables.Add(expressionVariable);

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

            cases.Add(new SwitchExpressionClass(1), new TestWriteLine("ONE", "ONE"));
            cases.Add(new SwitchExpressionClass(2), new TestWriteLine("Two", "Two"));
            cases.Add(new SwitchExpressionClass(3), new TestWriteLine("Three", "Three"));

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

            flowchart.AddSwitchLink(new TestWriteLine("Start", "Flowchart started"),
                                    cases,
                                    hints,
                                    expressionVariable,
                                    new TestWriteLine("Default", "I am not gonna execute"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #7
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);
        }
Example #8
0
        public void FlowSwitchWithAllCasesHavingSameElement()
        {
            TestFlowchart flowchart = new TestFlowchart();

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

            flowchart.Variables.Add(counter);

            TestIncrement increment = new TestIncrement("Inc", 1)
            {
                CounterVariable = counter
            };

            TestWriteLine writeHello = new TestWriteLine("Hello", "Ola");
            Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>();

            cases.Add(1, writeHello);
            cases.Add(2, writeHello);
            cases.Add(3, writeHello);

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

            flowchart.AddLink(new TestWriteLine("Start", "Flowchart Started"), increment);
            flowchart.AddSwitchLink(increment, cases, hints, e => counter.Get(e));
            flowchart.AddLink(writeHello, increment);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #9
0
        public void FlowSwitchExpressionEvaluationNullExecuteDefault()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <string> expVariable = new Variable <string> {
                Name = "ExpVar"
            };

            flowchart.Variables.Add(expVariable);

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

            cases.Add("One", new TestWriteLine("Hello1", "Hello1"));
            cases.Add("Two", new TestWriteLine("Hello2", "Hello2"));
            cases.Add("Three", new TestWriteLine("Hello3", "Hello3"));
            cases.Add(string.Empty, new TestWriteLine("Hello4", "Hello4"));

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

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #10
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);
            }
        }
Example #11
0
        public void SwitchExpressionOnCustomtype()
        {
            TestFlowchart flow = new TestFlowchart();

            Complex defaultValue = new Complex(3, 3);

            Variable <Complex> complexVar = new Variable <Complex>("Complex", context => defaultValue);

            flow.Variables.Add(complexVar);

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

            cases.Add(new Complex(1, 3), new TestWriteLine("Hello1", "Hello1"));
            cases.Add(new Complex(2, 3), new TestWriteLine("Hello2", "Hello2"));
            cases.Add(defaultValue, new TestWriteLine("Hello3", "Hello3"));
            cases.Add(new Complex(4, 3), new TestWriteLine("Hello4", "Hello4"));

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

            flow.AddSwitchLink <Complex>(new TestWriteLine("Start", "Start"), cases, hints, complexVar, new TestWriteLine("Default", "Default"));

            TestRuntime.RunAndValidateWorkflow(flow);
        }
Example #12
0
        public void AccessVariableOnParentFromNestedFlowchart()
        {
            TestFlowchart parent = new TestFlowchart();
            TestFlowchart child  = new TestFlowchart();

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

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

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

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

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

            child.AddSwitchLink(new TestWriteLine("Child Started", "Child Started"), cases, hints, e => counter.Get(e), new TestWriteLine("Default", "Default"));

            parent.AddLink(new TestWriteLine("Start", "Parent started"), child);

            TestRuntime.RunAndValidateWorkflow(parent);
        }
Example #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);

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

            flowchart1.Elements.Add(tCond);

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Example #14
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);
        }
Example #15
0
        public void ThrowFromNode()
        {
            TestFlowchart  flowchart  = new TestFlowchart();
            Variable <int> expression = new Variable <int> {
                Name = "expression", Default = 3
            };

            flowchart.Variables.Add(expression);

            TestWriteLine         w1       = new TestWriteLine("One", "One wont execute");
            TestWriteLine         w2       = new TestWriteLine("Two", "Two will execute");
            TestThrow <Exception> throwAct = new TestThrow <Exception>();

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

            cases.Add(1, w1);
            cases.Add(2, w2);
            cases.Add(3, throwAct);

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

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

            TestRuntime.RunAndValidateAbortedException(flowchart, typeof(Exception), null);
        }
Example #16
0
        public void FlowSwitchDefaultExecutionWithMultipleCases()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <object> expressionVariable = new Variable <object>("expression", context => "Four");

            flowchart.Variables.Add(expressionVariable);

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

            cases.Add(1, new TestWriteLine("ONE", "ONE"));
            cases.Add(2, new TestWriteLine("Two", "Two"));
            cases.Add(3, new TestWriteLine("Three", "Three"));

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

            flowchart.AddSwitchLink(new TestWriteLine("Start", "Flowchart started"),
                                    cases,
                                    hints,
                                    expressionVariable,
                                    new TestWriteLine("Default", "I am gonna execute"));

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #17
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);
        }
Example #18
0
        public void FlowSwitchWithCasesAndDefaultNull()
        {
            // This is a valid testcase and we don't expect error.
            TestFlowchart flowchart1 = new TestFlowchart("flowChart1");

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

            hints.Add(-1); // It was needed to set it to -1, else testObjects would return error.

            flowchart1.AddSwitchLink <string>(null, (Dictionary <string, TestActivity>)null, hints, "Two", null);

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Example #19
0
        public void FlowSwitchWithOnlyDefaultElement()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine defaultWrite = new TestWriteLine("Default", "Default");

            Dictionary <string, TestActivity> cases = new Dictionary <string, TestActivity>();
            List <int> hints = new List <int>()
            {
                -1
            };

            flowchart.AddSwitchLink <string>(new TestWriteLine("Start", "Flowchart Started"), cases, hints, "Anything", defaultWrite);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #20
0
        public void UnloadFlowchartWhileExecutingFlowSwitchExpression()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeHello = new TestWriteLine("Hello", "Hello");

            TestWriteLine writeStart = new TestWriteLine("Start", "Start");

            TestExpressionEvaluatorWithBody <object> expressionActivity = new TestExpressionEvaluatorWithBody <object>
            {
                ExpressionResultExpression = context => "One",
                Body            = new TestBlockingActivity("Block"),
                WillBodyExecute = true
            };

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

            cases.Add("One", writeHello);
            cases.Add("Two", new TestWriteLine("Two", "Two will not execute"));

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

            flowchart.AddStartLink(writeStart);

            flowchart.AddSwitchLink(writeStart, cases, hints, expressionActivity, new TestWriteLine("Default", "Will not execute"));

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

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(expressionActivity.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();

                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Example #21
0
        public void CancelFlowchartWhileEvaluatingFlowSwitchExpression()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeHello = new TestWriteLine("Hello", "Hello");

            TestWriteLine writeStart = new TestWriteLine("Start", "Start");

            TestExpressionEvaluatorWithBody <object> expressionActivity = new TestExpressionEvaluatorWithBody <object>
            {
                ExpressionResultExpression = context => "One",
                Body = new TestBlockingActivity("B1", "Blocking")
                {
                    ExpectedOutcome = Outcome.Canceled
                },
                WillBodyExecute = true
            };

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

            cases.Add("One", writeHello);

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

            flowchart.AddStartLink(writeStart);

            flowchart.AddSwitchLink(writeStart, cases, hints, expressionActivity);

            flowchart.ExpectedOutcome          = Outcome.Canceled;
            expressionActivity.ExpectedOutcome = Outcome.Canceled;

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange("B1", TestActivityInstanceState.Executing);

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled(true);
            }
        }
Example #22
0
        public void FlowSwitchWithOneElement()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeHello = new TestWriteLine("Hello", "Hello");

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

            cases.Add("OnlyOne", writeHello);

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

            hints.Add(0);

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #23
0
        public void FlowStepConnectedToFlowSwitch()
        {
            TestFlowchart flowchart = new TestFlowchart();

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

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

            cases.Add("1", new TestWriteLine("Will execute", "Executing"));

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

            flowchart.AddSwitchLink <string>(w1, cases, hints, "1");

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #24
0
        public void FlowSwitchAsStartElement()
        {
            TestFlowchart flowchart1 = new TestFlowchart("flowChart1");
            TestWriteLine w1         = new TestWriteLine("W1", "Executing W1");
            TestWriteLine w2         = new TestWriteLine("W2", "Executing W2");
            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);
            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Example #25
0
        /// <summary>
        /// Exception thrown during expression evaluation of switch.
        /// Exception thrown during expression evaluation of switch
        /// </summary>
        /// This test is disabled in desktop and failing too.
        //[Fact]
        public void FaultWhileSwitchExpressionEvaluation()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestExpressionEvaluatorWithBody <object> faultExp = new TestExpressionEvaluatorWithBody <object>
            {
                Body = new TestThrow <InvalidProgramException>()
            };

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

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

            flowchart.AddSwitchLink(new TestWriteLine("Start", "Start"), cases, new List <int>()
            {
                -1
            }, faultExp, new TestWriteLine("Default", "Default"));

            TestRuntime.RunAndValidateAbortedException(flowchart, typeof(InvalidProgramException), null);
        }
Example #26
0
        public void FlowSwitchExpressionEvaluationNullExecuteDefault()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <int> expVariable = new Variable <int> {
                Name = "ExpVar"
            };

            flowchart.Variables.Add(expVariable);

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

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

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #27
0
        public void FlowSwitchWithNullFlowElement()
        {
            TestFlowchart flowchart = new TestFlowchart();

            Variable <object> expression = new Variable <object>("expression", context => 1);

            flowchart.Variables.Add(expression);

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

            cases.Add(1, null);

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

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

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #28
0
        public void FlowSwitchWithNodePointingToParentFlowSwitch()
        {
            TestFlowchart  flowchart = new TestFlowchart();
            Variable <int> counter   = VariableHelper.CreateInitialized <int>("counter", 0);

            flowchart.Variables.Add(counter);

            TestIncrement increment = new TestIncrement("Inc", 1)
            {
                CounterVariable = counter
            };

            TestWriteLine w1 = new TestWriteLine("One", "Will execute on first iteration");
            TestWriteLine w2 = new TestWriteLine("Two", "Will execute on second iteration");
            TestWriteLine w3 = new TestWriteLine("Three", "Will execute on third iteration");
            TestWriteLine w4 = new TestWriteLine("Four", "Will execute on final iteration");

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

            cases.Add(1, w1);
            cases.Add(2, w2);
            cases.Add(3, w3);

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

            hints.Add(0);
            hints.Add(1);
            hints.Add(2);
            hints.Add(-1);

            flowchart.AddLink(new TestWriteLine("Start", "Flowchart Started"), increment);

            flowchart.AddSwitchLink <int>(increment, cases, hints, env => counter.Get(env), w4);
            flowchart.AddLink(w1, increment);
            flowchart.AddLink(w2, increment);
            flowchart.AddLink(w3, increment);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
Example #29
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)
            {
                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);
        }
Example #30
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));
        }