コード例 #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);
        }
コード例 #2
0
        public void ExecuteParallel()
        {
            TestPick pick = new TestPick()
            {
                DisplayName = "PickActivity",
                Branches    =
                {
                    new TestPickBranch()
                    {
                        DisplayName = "TriggeredBranch1",
                        Trigger     = new TestDelay()
                        {
                            Duration = new TimeSpan(0, 0, 1)
                        },
                        Action = new TestWriteLine("Action1")
                        {
                            Message = "Action1",
                        },
                    },
                    new TestPickBranch()
                    {
                        DisplayName = "NoTriggeredBranch2",
                        Trigger     = new TestDelay()
                        {
                            ExpectedOutcome = Outcome.Canceled,
                            Duration        = new TimeSpan(0, 0, 2)
                        },
                        Action = new TestWriteLine("Action2")
                        {
                            Message = "Action2",
                        },
                    }
                }
            };

            List <string> values = new List <string> {
                "a", "b"
            };
            TestParallelForEach <string> testPFE = new TestParallelForEach <string>()
            {
                Body                = pick,
                HintValues          = values,
                ValuesExpression    = (context => new List <string> {
                    "a", "b"
                }),
                CompletionCondition = false,
            };

            ExpectedTrace expected = testPFE.GetExpectedTrace();

            expected.AddVerifyTypes(typeof(UserTrace));

            TestRuntime.RunAndValidateWorkflow(testPFE, expected);
        }
コード例 #3
0
        public void NestedParallelForEach()
        {
            DelegateInArgument <string> _currentVariable_1 = new DelegateInArgument <string>()
            {
                Name = "_currentVariable_1"
            };
            DelegateInArgument <string> _currentVariable_2 = new DelegateInArgument <string>()
            {
                Name = "_currentVariable_2"
            };

            TestSequence sequ = new TestSequence("Sequence")
            {
                Activities =
                {
                    new TestParallelForEach <string>("Outer Parallel")
                    {
                        CurrentVariable = _currentVariable_1,
                        Body            = new TestParallelForEach <string>("Inner parallel")
                        {
                            CurrentVariable = _currentVariable_2,
                            Body            = new TestWriteLine("Writeline")
                            {
                                MessageExpression = (env) => (string)_currentVariable_2.Get(env),
                                HintMessageList   = { "iuu", "M", "iuu", "M" },
                            },

                            HintValues       = new string[] { "M", "iuu" },
                            ValuesExpression = (context => new string[]{ "M",                           "iuu" }),
                        },

                        HintValues       = new string[] { "M", "iuu" },
                        ValuesExpression = (context => new string[]{ "M",                           "iuu" }),
                    }
                }
            };

            // Using user traces to validate this test as by validating against expected trace
            // test is going into infinite loop during tracing.
            ExpectedTrace expected = sequ.GetExpectedTrace();

            expected.AddVerifyTypes(typeof(UserTrace));
            TestRuntime.RunAndValidateWorkflow(sequ, expected);
        }
コード例 #4
0
        public void TestResumeBookmarkCallback()
        {
            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 sequence   = new TestSequence()
                {
                    Activities =
                    {
                        new TestWaitReadLine <int>(branchName, branchName)
                        {
                            BookmarkValue = value,
                            WaitTime      = TimeSpan.FromSeconds(10),
                        }
                    },
                    ExpectedOutcome = Outcome.Faulted,
                };

                if (i > 0)
                {
                    (sequence.Activities[0] as TestWaitReadLine <int>).ExpectedOutcome = Outcome.Faulted;
                }

                parallel.Branches.Add(sequence);
            }

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

            runtime.ExecuteWorkflow();

            runtime.WaitForIdle();

            for (int i = 0; i < noBranches; i++)
            {
                string branchName = "Branch" + i.ToString();
                runtime.BeginResumeBookMark(branchName, i, null, null);
            }

            runtime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait));

            runtime.AbortWorkflow("Aborting Workflow");

            ExpectedTrace expectTrace = parallel.GetExpectedTrace();

            expectTrace.Trace.Steps.Clear();
            expectTrace.Trace.Steps.Add(new UserTrace(WaitReadLine <int> .BeforeWait));
            expectTrace.Trace.Steps.Add(new UserTrace(WaitReadLine <int> .AfterWait));
            expectTrace.AddVerifyTypes(typeof(UserTrace));

            Exception exception;

            runtime.WaitForAborted(out exception, expectTrace);
        }
コード例 #5
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);
        }