Exemplo n.º 1
0
        public void CancelExecutingChildActivities()
        {
            TestFlowchart parent = new TestFlowchart("Parent");

            TestBlockingActivity blocking   = new TestBlockingActivity("BlockingActivity", "B1");
            TestWriteLine        writeLine1 = new TestWriteLine("w1", "w1");
            TestWriteLine        writeLine2 = new TestWriteLine("w2", "w2");

            parent.AddLink(writeLine1, blocking);
            TestFlowElement element = parent.AddLink(blocking, writeLine2);

            element.IsCancelling = true;

            blocking.ExpectedOutcome = Outcome.Canceled;
            parent.ExpectedOutcome   = Outcome.Canceled;

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parent))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                System.Threading.Thread.Sleep(2000);
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void FlowDecisionAsStartElement()
        {
            TestFlowchart flowchart1 = new TestFlowchart("flowChart1");

            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);

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Exemplo n.º 6
0
        public void AddSameElementToParentAndChild()
        {
            TestFlowchart   flowchart1 = new TestFlowchart("flowChart1");
            TestFlowchart   flowchart2 = new TestFlowchart("flowChart2");
            TestWriteLine   w1         = new TestWriteLine("W1", "Executing W1");
            TestFlowElement fStep      = new TestFlowStep(w1);

            flowchart2.Elements.Add(fStep);

            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, fStep, flowchart2);

            TestRuntime.ValidateInstantiationException(flowchart1, string.Format(ErrorStrings.FlowNodeCannotBeShared, flowchart1.DisplayName, flowchart2.DisplayName));
        }
Exemplo n.º 7
0
        public void FlowDecisionWithTrueElementNullEvaluationTrue()
        {
            // This is a valid testcase and we don't expect error.
            TestFlowchart flowchart1 = new TestFlowchart("flowChart1");

            TestWriteLine w2True  = new TestWriteLine("True", "True will execute");
            TestWriteLine w2False = new TestWriteLine("False", "False wont execute");

            Variable <int> margin = new Variable <int> {
                Name = "margin", Default = 10
            };

            flowchart1.Variables.Add(margin);
            TestFlowConditional flowDecision = new TestFlowConditional((HintTrueFalse[])null); // null here means neither True or False will happen as the action is null

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

            TestRuntime.RunAndValidateWorkflow(flowchart1);
        }
Exemplo n.º 8
0
        public void Flowchart_FaultNotHandled()
        {
            Variable <Exception> exception = new Variable <Exception>();
            TestFlowchart        flowchart = new TestFlowchart("Flow1");

            flowchart.Variables.Add(exception);

            TestSequence faultySequence = new TestSequence
            {
                Activities =
                {
                    new TestThrow <InvalidOperationException>("Faulty Little Sequence")
                    {
                        ExceptionExpression = (context => new InvalidOperationException("I am a faulty little sequence's exception"))
                    }
                }
            };
            TestWriteLine   writeLine1 = new TestWriteLine("WriteStatus", "I wont execute");
            TestFlowElement step       = flowchart.AddLink(faultySequence, writeLine1);

            step.IsFaulting = true;

            TestRuntime.RunAndValidateAbortedException(flowchart, typeof(InvalidOperationException), new Dictionary <string, string>());
        }