コード例 #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();
            }
        }
コード例 #2
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();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
ファイル: WhileActivity.cs プロジェクト: sunxiaotianmg/CoreWF
        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();
            }
        }
コード例 #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();
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
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();
            }
        }
コード例 #9
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);
            }
        }
コード例 #10
0
ファイル: WhileActivity.cs プロジェクト: sunxiaotianmg/CoreWF
        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();
            }
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        public void CancelSequenceInTheMiddle()
        {
            TestSequence seq = new TestSequence
            {
                Activities =
                {
                    new TestWriteLine("W1", "I should be printed"),
                    new TestBlockingActivity("BookMark1")
                    {
                        ExpectedOutcome = Outcome.Canceled
                    },
                    new TestWriteLine("W2", "I should not be printed")
                    {
                        ExpectedOutcome = Outcome.Canceled
                    },
                    new TestWriteLine("W3", "I should not be printed")
                    {
                        ExpectedOutcome = Outcome.Canceled
                    },
                }
            };

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

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

                runtime.WaitForIdle();

                runtime.PersistWorkflow();

                runtime.CancelWorkflow();

                runtime.WaitForCanceled();
            }
        }
コード例 #13
0
        private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync)
        {
            string         shouldNotExecuteMsg = "Should not see this message";
            Variable <int> value           = VariableHelper.Create <int>("value");
            TestWriteLine  writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg)
            {
            };
            TestSequence testSequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                }
            };

            //Get Expected Trace without TestWriteLine()
            if (operationsId == 2)
            {
                testSequence.ExpectedOutcome = Outcome.Canceled;
            }

            ExpectedTrace expectedTrace = testSequence.GetExpectedTrace();

            if (operationsId == 4)
            {
                expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1);
            }
            else if (operationsId == 3)
            {
                expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1);
                expectedTrace.Trace.Steps.Add(new ActivityTrace(testSequence.DisplayName, ActivityInstanceState.Faulted));
            }


            //Now Add TestWriteLine to workflow
            testSequence.Activities.Add(writeLineNotRun);

            TestWorkflowRuntimeAsyncResult asyncResultResume    = null;
            TestWorkflowRuntimeAsyncResult asyncResultOperation = null;
            string message = "";

            //Execute Workflow
            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            // using PersistableIdleAction.None here because the idle unload was racing with the resume bookmark after the wait for the BeforeWait trace.
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.None);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing);
            if (isSync)
            {
                //Log.Info("Resuming Bookmark");
                if (isSync)
                {
                    workflowRuntime.ResumeBookMark("Read", 9999);
                }
                else
                {
                    asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null);
                }

                workflowRuntime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait));
                switch (operationsId)
                {
                case 2:
                    //Cancel Workflow during OnResumeBookmark is executing
                    //Log.Info("CancelWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.CancelWorkflow();
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginCancelWorkflow(null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndCancelWorkflow(asyncResultOperation);
                    }
                    //Trace.WriteLine should not execute
                    break;

                case 3:
                    //Terminate Workflow during OnResumeBookmark is executing
                    //Log.Info("TerminateWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.TerminateWorkflow("Terminate Exception");
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginTerminateWorkflow("Terminate Exception", null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndTerminateWorkflow(asyncResultOperation);
                    }
                    //Trace.WriteLine should not execute.
                    break;

                case 4:
                    //Unload Workflow during OnResumeBookmark is executing
                    //This should wait till ResumeMark finishes the work
                    //Log.Info("UnloadWorkflow during OnResumeBookmark executing");
                    if (isSync)
                    {
                        workflowRuntime.UnloadWorkflow();
                    }
                    else
                    {
                        asyncResultOperation = workflowRuntime.BeginUnloadWorkflow(null, null);

                        workflowRuntime.EndResumeBookMark(asyncResultResume);
                        workflowRuntime.EndUnloadWorkflow(asyncResultOperation);
                    }

                    //message = String.Format(ExceptionStrings.WorkflowInstanceUnloaded, workflowRuntime.CurrentWorkflowInstanceId);
                    ExceptionHelpers.CheckForException(typeof(WorkflowApplicationUnloadedException), message, new ExceptionHelpers.MethodDelegate(
                                                           delegate
                    {
                        workflowRuntime.ResumeWorkflow();
                    }));

                    break;
                }
            }

            if (isSync)
            {
                switch (operationsId)
                {
                case 2:
                {
                    workflowRuntime.WaitForCanceled(expectedTrace);
                    break;
                }

                case 3:
                {
                    Exception terminationException;
                    workflowRuntime.WaitForTerminated(1, out terminationException, expectedTrace);
                    break;
                }

                case 4:
                {
                    // We tried to do a ResumeWorkflow without loading it after an unload, so we expected
                    // to get a WorkflowApplicationUnloadedException. The workflow will never complete,
                    // so don't wait for it to complete.
                    break;
                }
                }
            }
            else
            {
                //Give some time for Workflow to execute
                Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(1).TotalMilliseconds);
            }

            if (isSync)
            {
                expectedTrace.AddIgnoreTypes(typeof(WorkflowInstanceTrace));
                workflowRuntime.ActualTrace.Validate(expectedTrace);
            }
            else
            {
                //The traces are vary in the async situations, thus we can not do a full trace valdation
                //validate the writeline after read activity is not executed is sufficient
                if (workflowRuntime.ActualTrace.ToString().Contains(shouldNotExecuteMsg))
                {
                    throw new Exception("The NotExecuted WriteLine activity has been executed, the expectation is it does not");
                }
            }
        }
コード例 #14
0
        private         // Abort with Cancel failing in desktop too. so disabling test
                        //[InlineData(true)]
        void AbortParallel(bool isTestCancel)
        {
            const int      noBranches = 10;
            Variable <int> value      = VariableHelper.Create <int>("value");

            TestParallel parallel = new TestParallel()
            {
                Variables       = { value },
                ExpectedOutcome = Outcome.Faulted
            };

            for (int i = 0; i < noBranches; i++)
            {
                string branchName = "Branch" + i.ToString();

                TestSequence branchSequence = new TestSequence("Seq" + branchName)
                {
                    Activities =
                    {
                        new TestWriteLine()
                        {
                            Message = branchName + " Started"
                        },
                        new TestReadLine <int>(branchName, branchName)
                        {
                            BookmarkValue   = value,
                            ExpectedOutcome = Outcome.Faulted
                        },
                        new TestWriteLine()
                        {
                            Message         = branchName + " Completed",
                            ExpectedOutcome = Outcome.Faulted
                        },
                    },
                    ExpectedOutcome = Outcome.Faulted
                };

                if (isTestCancel)
                {
                    if (i == 0)
                    {
                        branchSequence.Activities[1].ExpectedOutcome = Outcome.Canceled;
                    }
                }

                parallel.Branches.Add(branchSequence);
            }

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel);

            runtime.ExecuteWorkflow();

            runtime.WaitForIdle();

            //Cancel Workflow
            if (isTestCancel)
            {
                //Log.Info("Cancelling Workflow");
                runtime.CancelWorkflow();
                runtime.WaitForCanceled();
            }

            //Abort Workflow
            runtime.AbortWorkflow("Aborting for Test");
            ExpectedTrace expectedTrace = parallel.GetExpectedTrace();

            //Only verify User trace since activity traces will not be available once abort is called
            expectedTrace.AddVerifyTypes(typeof(UserTrace));
            Exception excepion;

            runtime.WaitForAborted(out excepion, expectedTrace);
        }
コード例 #15
0
        public void CancelChildOfParallelForEach()
        {
            DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>()
            {
                Name = "_currentVariable"
            };

            TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel For Each Activity")
            {
                HintValues = new List <string>()
                {
                    "Hi", "There"
                },
                ValuesExpression = (context => new List <string>()
                {
                    "Hi", "There"
                }),
                CurrentVariable  = _currentVariable,
                Body             = new TestSequence("Body of parallel for each")
                {
                    Activities =
                    {
                        new TestWriteLine("Writeline in parallel for each")
                        {
                            MessageExpression = (env) => (string)_currentVariable.Get(env),
                            HintMessageList   = { "There",     "Hi" }
                        },

                        new TestIf("Test If", HintThenOrElse.Else, HintThenOrElse.Then)
                        {
                            ConditionExpression = (env) => (bool)(_currentVariable.Get(env).Equals("Hi")),

                            ThenActivity = new TestBlockingActivityUnique("BlockingActivity", "Bookmark")
                            {
                                ExpectedOutcome = Outcome.Canceled
                            },

                            ElseActivity = new TestWriteLine("Writeline in Else")
                            {
                                MessageExpression = (env) => (string)_currentVariable.Get(env),
                                HintMessage       = "There"
                            }
                        },

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

                HintIterationCount = 2
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelForEach))
            {
                testWorkflowRuntime.ExecuteWorkflow();
                testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing);
                testWorkflowRuntime.CancelWorkflow();
                testWorkflowRuntime.WaitForCanceled();
            }
        }