Exemplo n.º 1
0
        /// <summary>
        /// Five level deep nested flowchart with blocking activity
        /// </summary>
        /// Disabled and failed in desktop
        //[Fact]
        public void FiveLevelDeepNestedFlowchartWithBlockingActivity()
        {
            TestFlowchart        parent   = new TestFlowchart();
            TestFlowchart        child1   = new TestFlowchart();
            TestFlowchart        child2   = new TestFlowchart();
            TestFlowchart        child3   = new TestFlowchart();
            TestFlowchart        child4   = new TestFlowchart();
            TestBlockingActivity blocking = new TestBlockingActivity("Blocked");

            parent.AddStartLink(child1);
            child1.AddStartLink(child2);
            child2.AddStartLink(child3);
            child3.AddStartLink(child4);
            child4.AddStartLink(blocking);

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

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

                testWorkflowRuntime.ResumeBookMark("Blocked", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 2
0
        public void UnloadFlowchartWhileExecutingFlowStep()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking = new TestBlockingActivity("Block");

            flowchart.AddStartLink(blocking);

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

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

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

                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();


                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 3
0
        public void PersistFlowchart()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");

            TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity");

            flowchart.AddStartLink(writeLine1);
            flowchart.AddLink(writeLine1, blocking);
            flowchart.AddLink(blocking, writeLine2);

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

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.None))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.PersistWorkflow();
                System.Threading.Thread.Sleep(2000);
                testWorkflowRuntime.ResumeBookMark("BlockingActivity", null);
                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 4
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.º 5
0
        public void PersistenceToWriteLineActivity()
        {
            TestProductWriteline writeLine1 = new TestProductWriteline("writeLine1")
            {
                TextExpressionActivity = new TestExpressionEvaluatorWithBody <string>()
                {
                    Body             = (new TestBlockingActivity("BlockingActivity")),
                    ExpressionResult = "This should be displayed after the bookmark"
                }
            };

            using (StreamWriter writer = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write)))
            {
                Console.SetOut(writer);

                TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity");

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

                using (TestWorkflowRuntime workflow = TestRuntime.CreateTestWorkflowRuntime(writeLine1, null, jsonStore, PersistableIdleAction.None))
                {
                    workflow.ExecuteWorkflow();
                    workflow.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                    workflow.PersistWorkflow();
                    workflow.ResumeBookMark("BlockingActivity", null);
                    workflow.WaitForCompletion();
                }
            }
        }
Exemplo n.º 6
0
        public void WhileCancelled()
        {
            Variable <int> count = new Variable <int> {
                Name = "Counter", Default = 0
            };
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark")
            {
                ExpectedOutcome = Outcome.Canceled
            };
            TestWhile whileAct = new TestWhile

            {
                Variables           = { count },
                Body                = blocking,
                ConditionExpression = (e => count.Get(e) < 5),
                HintIterationCount  = 1,
                ExpectedOutcome     = Outcome.Canceled
            };

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

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

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemplo n.º 7
0
        public void PersistInCatch()
        {
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark");
            TestTryCatch         tcf      = new TestTryCatch
            {
                Try = new TestThrow <Exception>()
                {
                    ExpectedOutcome = Outcome.CaughtException()
                },
                Catches = { { new TestCatch <Exception> {
                                  Body = blocking
                              } } }
            };

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

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

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

                testWorkflowRuntime.PersistWorkflow();

                testWorkflowRuntime.ResumeBookMark("Bookmark", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Have blocking activity (Receive) in flowchart and raise the event unblocking it.
        /// </summary>
        /// /// Disabled and failed in desktop
        //[Fact]
        public void BlockingActivityInFlowchart()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking = new TestBlockingActivity("Block");

            flowchart.AddLink(new TestWriteLine("Start", "Start"), blocking);

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

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

                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 9
0
        public void PersistInTry()
        {
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark");

            TestTryCatch tryCatch = new TestTryCatch("TryCatchTest")
            {
                Try = new TestSequence("TrySeq")
                {
                    Activities =
                    {
                        blocking,
                        new TestThrow <ArgumentException>("TryException")
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                    },
                },

                Catches =
                {
                    new TestCatch <ArgumentException>()
                    {
                        Body = new TestWriteLine("Caught", "Caught")
                    }
                },
                Finally = new TestWriteLine("Finally", "Finally")
            };

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

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

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

                testWorkflowRuntime.PersistWorkflow();

                testWorkflowRuntime.ResumeBookMark("Bookmark", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 10
0
        public void Flowchart_Listen()
        {
            TestFlowchart flowchart = new TestFlowchart("Flow1");

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

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

            TestBlockingActivity blocking1 = new TestBlockingActivity("Block1");
            TestBlockingActivity blocking2 = new TestBlockingActivity("Block2");
            TestBlockingActivity blocking3 = new TestBlockingActivity("Block3");
            TestBlockingActivity blocking4 = new TestBlockingActivity("Block4");

            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    blocking1,
                    new TestIncrement {
                        CounterVariable = counter,IncrementCount                      = 1
                    }
                }
            };

            TestParallel parallel = new TestParallel {
                Branches = { seq, blocking2, blocking3, blocking4 }, CompletionConditionExpression = env => counter.Get(env) == 1, HintNumberOfBranchesExecution = 1
            };

            flowchart.AddLink(parallel, new TestWriteLine("End", "The End"));

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

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

                testWorkflowRuntime.ResumeBookMark("Block1", null);

                testWorkflowRuntime.WaitForCompletion();
            }
        }
Exemplo n.º 11
0
        public void CancelInTryBlock()
        {
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark")
            {
                ExpectedOutcome = Outcome.Canceled
            };

            TestTryCatch tryCatch = new TestTryCatch("TryCatchTest")
            {
                Try = new TestSequence("TrySeq")
                {
                    Activities =
                    {
                        blocking,
                        new TestThrow <ArgumentException>("TryException")
                        {
                            ExpectedOutcome = Outcome.None
                        },
                    },
                },

                Catches =
                {
                    new TestCatch <ArgumentException>()
                    {
                        Body            = new TestWriteLine("Caught", "Caught"),
                        ExpectedOutcome = Outcome.None
                    }
                }
            };

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

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

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemplo n.º 12
0
        public void CancelFlowchart()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking1 = new TestBlockingActivity("B1", "B1");

            blocking1.ExpectedOutcome = Outcome.Canceled;

            flowchart.AddStartLink(blocking1);
            flowchart.ExpectedOutcome = Outcome.Canceled;

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange(blocking1.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled(true);
            }
        }
Exemplo n.º 13
0
        public void CancelFlowchartWhileEvaluatingFlowConditionalCondition()
        {
            TestFlowchart flowchart = new TestFlowchart();

            TestBlockingActivity blocking = new TestBlockingActivity("Block", "Blocked")
            {
                ExpectedOutcome = Outcome.Canceled
            };

            TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true)
            {
                Body            = blocking,
                WillBodyExecute = true
            };

            TestFlowConditional conditional = new TestFlowConditional
            {
                ConditionValueExpression = expression
            };

            flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"),
                                         conditional,
                                         new TestWriteLine("True", "True Action"),
                                         new TestWriteLine("False", "False Action"));

            expression.ExpectedOutcome = Outcome.Canceled;
            flowchart.ExpectedOutcome  = Outcome.Canceled;

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

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

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled(true);
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
0
        public void DelayPersisted()
        {
            Variable <int>       counter  = new Variable <int>("Counter", 0);
            TestBlockingActivity blocking = new TestBlockingActivity("B");

            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };

            TestSequence seq2 = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("Before")
                    {
                        Message = "Before"
                    },
                    new TestDelay()
                    {
                        Duration = TimeSpan.FromSeconds(1)
                    },
                    new TestWriteLine("After")
                    {
                        Message = "After"
                    }
                }
            };


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

            var instanceHandle = jsonStore.CreateInstanceHandle();
            var instanceView   = jsonStore.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.MaxValue);
            var instanceOwner  = instanceView.InstanceOwner;

            jsonStore.DefaultInstanceOwner = instanceOwner;

            //Guid id;
            using (TestWorkflowRuntime runtime =
                       TestRuntime.CreateTestWorkflowRuntime(seq, null, jsonStore, PersistableIdleAction.Unload))
            {
                runtime.ExecuteWorkflow();

                runtime.WaitForUnloaded();

                //id = runtime.CurrentWorkflowInstanceId;

                Thread.Sleep(TimeSpan.FromSeconds(2));

                //runtime.InitiateWorkflowForLoad();
                //runtime.LoadRunnableInitiatedWorkflowForInstance(/*TimeSpan.Zero, id*/);
                runtime.LoadRunnableWorkflow();

                runtime.ResumeWorkflow();

                runtime.WaitForCompletion();
            }
        }