Exemplo n.º 1
0
        public void CancellationScopeInPick()
        {
            // CancellationScope does not have test OM
            CancellationScope cancel = new CancellationScope()
            {
                DisplayName = "TestCancellationScope",
                Body        = new TestSequence()
                {
                    Activities =
                    {
                        new TestDelay("LongDelay", new TimeSpan(0, 0, 5))
                    }
                }.ProductActivity,
                              CancellationHandler = new TestSequence()
                {
                    Activities =
                    {
                        new TestWriteLine()
                        {
                            Message = "Cancelled"
                        }
                    }
                }.ProductActivity
            };

            TestCustomActivity testCancel = TestCustomActivity <CancellationScope> .CreateFromProduct(cancel);

            testCancel.ActivitySpecificTraces.Add(
                new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace("Cancelled"),
                }
            });

            TestPick pick = new TestPick()
            {
                Branches =
                {
                    new TestPickBranch()
                    {
                        Trigger = new TestDelay("ShortDelay", new TimeSpan(0, 0, 1))
                    },
                    new TestPickBranch()
                    {
                        Trigger = testCancel
                    }
                }
            };

            ExpectedTrace expectedTrace = pick.GetExpectedTrace();

            expectedTrace.AddVerifyTypes(typeof(UserTrace));

            TestRuntime.RunAndValidateWorkflow(pick, expectedTrace);
        }
Exemplo n.º 2
0
        public void ExecuteTogether()
        {
            Variable <int> var1 = VariableHelper.CreateInitialized <int>("var1", 1);

            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        Variables =
                        {
                            var1
                        },
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestSequence
                        {
                            Activities =
                            {
                                new TestDelay()
                                {
                                    Duration = new TimeSpan(0, 0, 1)
                                },
                                new TestAssign <int>()
                                {
                                    ToVariable      = var1,
                                    ValueExpression = (env) => (var1.Get(env) + 1),
                                }
                            }
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            HintMessage       = "2",
                            MessageExpression = ((env) => (var1.Get(env).ToString()))
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestBlockingActivity("Block")
                        {
                            ExpectedOutcome = Outcome.Canceled,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    }
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Exemplo n.º 3
0
        public void ImmediatelyCompleteTriggers()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestWriteLine("Trigger1")
                        {
                            Message = "Trigger1 Executing",
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "NoTriggeredBranch2",
                        ExpectedOutcome = Outcome.Canceled,
                        Trigger         = new TestWriteLine("Trigger2")
                        {
                            Message         = "Trigger2 Executing",
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "NoTriggeredBranch3",
                        ExpectedOutcome = Outcome.Canceled,
                        Trigger         = new TestWriteLine("Trigger3")
                        {
                            Message         = "Trigger3 Executing",
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("Action3")
                        {
                            Message = "Action3",
                        },
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public void SameVariableName()
        {
            Variable <string> var1 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch1");
            Variable <string> var2 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch2");

            TestPick pick = new TestPick()
            {
                DisplayName = "Pick",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "Branch1",
                        Variables   =
                        {
                            var1
                        },
                        Trigger = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 3)
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            HintMessage       = "Variable in Branch1",
                            MessageExpression = (env) => var1.Get(env)
                        }
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "Branch2",
                        Variables   =
                        {
                            var2
                        },
                        Trigger = new TestBlockingActivity("Block2")
                        {
                            ExpectedOutcome = Outcome.Canceled
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2"
                        }
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Exemplo n.º 6
0
        public void CustomActivityOverridesBranchCancelStateWithCompletedState()
        {
            const string triggerMessage = "Trigger branch's trigger is executing.";
            const string actionMessage  = "Trigger branch's action is executing.";

            TestPick pick = new TestPick()
            {
                DisplayName     = "PickActivity",
                ExpectedOutcome = new Outcome(OutcomeState.Completed)
                {
                    IsOverrideable = false
                },
                Branches =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch_Branch",
                        Trigger     = new TestWriteLine("TriggeredBranch_Trigger")
                        {
                            Message     = triggerMessage,
                            HintMessage = triggerMessage,
                        },
                        Action = new TestWriteLine("TriggeredBranch_Action")
                        {
                            Message     = actionMessage,
                            HintMessage = actionMessage,
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName     = "ClosedCustomActivity_Branch",
                        ExpectedOutcome = Outcome.Completed,  // custom activity's outcome is Closed, therefore this branch is also Closed
                        Trigger         = new TestBlockingActivityWithWriteLineInCancel("ClosedCustomActivity_Trigger", OutcomeState.Completed)
                        {
                            ExpectedOutcome = Outcome.Completed,
                        },
                        Action = new TestWriteLine("ClosedCustomActivity_Action")
                        {
                            Message = "ClosedCustomActivity_Action - not supposed to show",
                        },
                    },
                }
            };

            ExpectedTrace trace = pick.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(pick, trace);
        }
Exemplo n.º 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);
            }
        }