Exemple #1
0
        public void PersistWithinBranch()
        {
            TestParallel parallel = new TestParallel("Parallel Act")
            {
                Branches =
                {
                    new TestSequence("seq1")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 1")
                        }
                    },

                    new TestSequence("seq2")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 2")
                        }
                    },
                    new TestSequence("seq3")
                    {
                        Activities =
                        {
                            new TestBlockingActivity("Blocking activity 3")
                        }
                    },

                    new TestWriteLine("writeline after seq3")
                    {
                        Message = "HI"
                    }
                }
            };

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

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel, null, jsonStore, PersistableIdleAction.None))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Blocking activity 1", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 1", null);

                runtime.WaitForActivityStatusChange("Blocking activity 2", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 2", null);

                runtime.WaitForActivityStatusChange("Blocking activity 3", TestActivityInstanceState.Executing);
                runtime.PersistWorkflow();
                runtime.ResumeBookMark("Blocking activity 3", null);

                runtime.WaitForCompletion();
            }
        }
        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();
            }
        }
        public void PersistenceToWriteLineActivity()
        {
            TestProductWriteline writeLine1 = new TestProductWriteline("writeLine1");

            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();
                }
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        public void CancelParallelForEach()
        {
            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>()
            {
                HintValues = new List <string>()
                {
                    "Hi", "There"
                },
                ValuesExpression = (context => new List <string>()
                {
                    "Hi", "There"
                }),
                Body             = new TestBlockingActivityUnique("Blocking activity")
                {
                    ExpectedOutcome = Outcome.Canceled
                }
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelForEach))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("Blocking activity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemple #6
0
        public void CancelElseDuringExecution()
        {
            TestIf testIf = new TestIf("MyIf", HintThenOrElse.Else)
            {
                Condition    = false,
                ThenActivity = new TestWriteLine("Then Branch", "The message would not be displayed"),
                ElseActivity = new TestSequence("Else Branch")
                {
                    Activities =
                    {
                        new TestCustomActivity <BlockingActivity>("BlockingActivity", null)
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },
                        new TestWriteLine("Test WriteLine",                           "The message would not be displayed"),
                    },
                },
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testIf))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemple #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();
            }
        }
Exemple #8
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();
            }
        }
Exemple #9
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();
            }
        }
Exemple #10
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();
            }
        }
Exemple #11
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();
            }
        }
Exemple #12
0
        public void DoWhileCancelled()
        {
            TestDoWhile doWhile = new TestDoWhile("Do while")
            {
                Condition = true,
                Body      = new TestSequence("Do While Body")
                {
                    Activities =
                    {
                        new TestBlockingActivity("BlockingActivity", "Bookmark")
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },

                        new TestWriteLine("Writeline")
                        {
                            Message = "Hello"
                        }
                    }
                },

                HintIterationCount = 1,
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(doWhile))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                // This test is not run on desktop and I don't think it would pass there if it did run.
                //testWorkflowRuntime.WaitForCompletion();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemple #13
0
        public void TestAbortLoad()
        {
            Variable <int> value    = VariableHelper.Create <int>("value");
            TestSequence   sequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestAssign <int>()
                    {
                        ToVariable = value,
                        Value      = 100
                    },
                    new TestPersist(),
                    new TestReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                    new TestWriteLine("AfterAbort")
                    {
                        MessageExpression = (env) => value.Get(env).ToString(),
                        HintMessage       = "9999"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence, null, jsonStore, PersistableIdleAction.Persist);

            runtime.ExecuteWorkflow();
            runtime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing);
            runtime.PersistWorkflow();
            runtime.AbortWorkflow("Abort Workflow");
            //Wait Sometime to Handle to free
            Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(4).TotalMilliseconds);
            //Load Workflow from Last Persistence Point
            runtime.LoadWorkflow();
            runtime.ResumeBookMark("Read", 9999);
            runtime.WaitForActivityStatusChange("AfterAbort", TestActivityInstanceState.Closed);

            //Wait for the second completion trace
            TestTraceManager.Instance.WaitForTrace(runtime.CurrentWorkflowInstanceId, new SynchronizeTrace(RemoteWorkflowRuntime.CompletedOrAbortedHandlerCalled), 1);

            //Call Abort on Completed Workflow, this should not throw exception
            runtime.AbortWorkflow("Abort on Completed Workflow");
        }
Exemple #14
0
        public void PersistAfterCatchBeforeRethrow()
        {
            TestTryCatch root = new TestTryCatch("parent TryCatch")
            {
                Try = new TestSequence
                {
                    Activities =
                    {
                        new TestProductWriteline("W1"),
                        new TestThrow <TAC.ApplicationException>
                        {
                            ExceptionExpression = (context => new TAC.ApplicationException("abcd")),
                            ExpectedOutcome     = Outcome.CaughtException(typeof(TAC.ApplicationException)),
                        }
                    }
                },
                Catches =
                {
                    new TestCatch <TAC.ApplicationException>
                    {
                        Body = new TestSequence
                        {
                            Activities =
                            {
                                new TestBlockingActivity("Blocking1", "B1"),
                                new TestRethrow
                                {
                                    ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)),
                                }
                            }
                        }
                    }
                }
            };

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

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root, null, jsonStore, CoreWf.PersistableIdleAction.None))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("Blocking1", TestActivityInstanceState.Executing);
                testWorkflowRuntime.PersistWorkflow();
                testWorkflowRuntime.ResumeBookMark("Blocking1", null);

                Exception resultedException;
                testWorkflowRuntime.WaitForAborted(out resultedException);

                if (!(resultedException is TAC.ApplicationException))
                {
                    throw resultedException;
                }
            }
        }
Exemple #15
0
        public void ThreeBranchsOneTriggered()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch1",
                        Trigger     = new TestBlockingActivity("Block1")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch",
                        Trigger     = new TestBlockingActivity("Block2"),
                        Action      = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestBlockingActivity("Block3")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action3")
                        {
                            Message = "Action3",
                        },
                    },
                }
            };

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(pick))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Block2", TestActivityInstanceState.Executing);
                System.Threading.Thread.Sleep(1000);
                runtime.ResumeBookMark("Block2", null);
                ExpectedTrace trace = pick.GetExpectedTrace();
                runtime.WaitForCompletion(trace);
            }
        }
Exemple #16
0
        public void ChangePropertyNameAfterOpened()
        {
            Variable <TheStruct> var = new Variable <TheStruct>()
            {
                Name    = "var",
                Default = new TheStruct()
            };

            TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>()
            {
                PropertyName            = "PublicProperty",
                OperandLocationVariable = var
            };

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

            TestSequence sequence = new TestSequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new TestWriteLine("Start",            "Start"),
                    new TestBlockingActivity("Blocking"),
                    testAssign,
                },
            };

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

                valueTypePropertyReference.PropertyName = "PublicProperty1";

                runtime.ResumeBookMark("Blocking", null);

                runtime.WaitForCompletion(true);
            }
        }
Exemple #17
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();
            }
        }
Exemple #18
0
        public void CancelOnAction()
        {
            TestPick pick = new TestPick
            {
                DisplayName     = "PickActivity",
                ExpectedOutcome = Outcome.Canceled,
                Branches        =
                {
                    new TestPickBranch
                    {
                        DisplayName = "Branch1",
                        Trigger     = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 3),
                        },
                        Action = new TestBlockingActivity("Block1")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        }
                    },
                    new TestPickBranch
                    {
                        DisplayName = "Branch2",
                        Trigger     = new TestBlockingActivity("Block2")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        }
                    }
                }
            };

            using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(pick))
            {
                runtime.ExecuteWorkflow();
                runtime.WaitForActivityStatusChange("Block1", TestActivityInstanceState.Executing);
                System.Threading.Thread.Sleep(1000);
                runtime.CancelWorkflow();
                ExpectedTrace trace = pick.GetExpectedTrace();
                runtime.WaitForCanceled(trace);
            }
        }
Exemple #19
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);
            }
        }
Exemple #20
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();
            }
        }
Exemple #21
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();
            }
        }
Exemple #22
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();
            }
        }
Exemple #23
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();
            }
        }
Exemple #24
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);
            }
        }
Exemple #25
0
        public void WhileCancelledDuringConditionExecution()
        {
            TestWhile whileActivity = new TestWhile("While")
            {
                HintIterationCount = 0,
                ExpectedOutcome    = Outcome.Canceled,
                ConditionActivity  = new TestBlockingActivity <bool>("Blocking")
                {
                    ExpectedOutcome = Outcome.Canceled,
                },
                Body = new TestWriteLine("WriteLine", "WriteLine - Body"),
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(whileActivity))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }
Exemple #26
0
        public void UnloadFlowchartWhileExecutingFlowConditionalCondition()
        {
            TestFlowchart flowchart = new TestFlowchart();

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

            TestFlowConditional conditional = new TestFlowConditional(HintTrueFalse.True)
            {
                ConditionValueExpression = expression
            };

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


            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(System.Environment.CurrentDirectory);

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

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

                //testWorkflowRuntime.PersistWorkflow();
                testWorkflowRuntime.UnloadWorkflow();

                testWorkflowRuntime.LoadWorkflow();

                testWorkflowRuntime.ResumeBookMark("Block", null);

                testWorkflowRuntime.WaitForCompletion(true);
            }
        }
Exemple #27
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();
            }
        }
Exemple #28
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);
            }
        }
Exemple #29
0
        public static void TestOperationsResumeBookmarkCallback(int operationId)
        {
            Variable <int> value        = VariableHelper.Create <int>("value");
            const string   WaitMessage  = "WaitActivity will wait for this trace";
            TestSequence   testSequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitForTrace()
                    {
                        DisplayName = "WaitActivity",
                        TraceToWait = WaitMessage
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                    new TestReadLine <int>("Read1", "Read1")
                    {
                        BookmarkValue = value
                    },
                    new TestWriteLine()
                    {
                        Message = "Workflow Completed"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing);

            TestWorkflowRuntimeAsyncResult asyncResult = workflowRuntime.BeginResumeBookMark("Read", 10, new AsyncCallback(ResumeBookmarkCallback), operationId);

            //Continue the WaitActivity
            TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage));
            SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage);
            workflowRuntime.EndResumeBookMark(asyncResult);
            workflowRuntime.WaitForTrace(new UserTrace("After ResumeBookmarkCallback"));

            if (operationId == 2)
            {
                //Do nothing
            }
            else if (operationId == 3)
            {
                workflowRuntime.UnloadWorkflow();
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }
            else if (operationId == 4)
            {
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }

            ExpectedTrace expectedTrace = testSequence.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            workflowRuntime.WaitForCompletion(expectedTrace);
        }
Exemple #30
0
        public static void TestPersistDuringResumeBookmark()
        {
            bool              isSync      = true;
            Variable <int>    value       = VariableHelper.Create <int>("value");
            Variable <string> persist     = VariableHelper.Create <string>("persist");
            const string      WaitMessage = "Continue the WaitActivity";

            TestSequence testSequence = new TestSequence()
            {
                Variables  = { value, persist },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitForTrace()
                    {
                        DisplayName   = "WaitActivity",
                        TraceToWait   = WaitMessage,
                        DelayDuration = TimeSpan.FromMilliseconds(10)
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value,
                        WaitTime      = TimeSpan.FromSeconds(1)
                    },
                    new TestReadLine <string>("PersistBookmark", "PersistBookmark")
                    {
                        BookmarkValue = persist
                    },
                    new TestWriteLine()
                    {
                        MessageExpression = ((env) => value.Get(env).ToString()),
                        HintMessage       = "9999"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing);
            TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage));
            SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage);

            if (isSync)
            {
                workflowRuntime.ResumeBookMark("Read", 9999);
                workflowRuntime.PersistWorkflow();
            }
            else
            {
                TestWorkflowRuntimeAsyncResult asyncResultResume  = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null);
                TestWorkflowRuntimeAsyncResult asyncResultPersist = workflowRuntime.BeginPersistWorkflow(null, null);

                workflowRuntime.EndResumeBookMark(asyncResultResume);
                workflowRuntime.EndPersistWorkflow(asyncResultPersist);
            }

            workflowRuntime.WaitForActivityStatusChange("PersistBookmark", TestActivityInstanceState.Executing);
            workflowRuntime.WaitForUnloaded(1);
            workflowRuntime.LoadWorkflow();
            workflowRuntime.ResumeBookMark("PersistBookmark", "Yes");
            workflowRuntime.WaitForCompletion(false);
        }