コード例 #1
0
        /// <summary>
        /// Simple tcf scenario in a parallel. Where the branches have mismatching exceptions
        /// </summary>
        /// Disabled and failed in desktop
        //[Fact]
        public void TryCatchInParallelWithMissMatchingExceptions()
        {
            TestParallel parallel = new TestParallel("ParallelCatch")
            {
                CompletionCondition = true,
                Branches            =
                {
                    new TestTryCatch("TryCatchBranch1")
                    {
                        Try = new TestThrow <ArgumentException>("ThrowingArgumentException")
                        {
                            ExpectedOutcome = Outcome.UncaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <ArithmeticException>()
                            {
                                Body = new TestWriteLine("CatchingArithmeticException", "Catching ArithmeticException")
                            }
                        },
                    },
                    new TestTryCatch("TryCatchBranch2")
                    {
                        Try = new TestThrow <ArithmeticException>("ThrowingArithmeticException")
                        {
                            ExpectedOutcome = Outcome.None,
                        },
                        Catches =
                        {
                            new TestCatch <ArgumentException>()
                            {
                                ExpectedOutcome = Outcome.None,
                                Body            = new TestWriteLine("CatchingArgumentException", "Catching ArgumentException")
                                {
                                    ExpectedOutcome = Outcome.None,
                                }
                            }
                        },
                    }
                },
            };

            TestRuntime.RunAndValidateAbortedException(parallel, typeof(ArgumentException), null);
        }
コード例 #2
0
        public void ParallelWithWorkFlowInvoker()
        {
            TestWriteLine writeLine1 = new TestWriteLine();

            writeLine1.Message     = "writeLine1";
            writeLine1.DisplayName = "writeLine1";

            TestWriteLine writeLine2 = new TestWriteLine();

            writeLine2.Message     = "writeLine2";
            writeLine2.DisplayName = "writeLine2";

            TestParallel parallelActivity = new TestParallel("Parallel Activity");

            parallelActivity.Branches.Add(writeLine1);
            parallelActivity.Branches.Add(writeLine2);

            TestRuntime.RunAndValidateUsingWorkflowInvoker(parallelActivity, null, null, null);
        }
コード例 #3
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();
            }
        }
コード例 #4
0
        public void Flowchart_Parallel()
        {
            TestFlowchart flowchart = new TestFlowchart("Flow1");

            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");
            TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3");
            TestWriteLine writeLine4 = new TestWriteLine("hello4", "Hello4");
            TestWriteLine writeLine5 = new TestWriteLine("hello5", "Hello5");

            TestParallel parallel = new TestParallel
            {
                Branches = { writeLine2, writeLine3, writeLine4 }
            };


            flowchart.AddLink(writeLine1, parallel);
            flowchart.AddLink(parallel, writeLine5);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
コード例 #5
0
        public void SimpleParallel()
        {
            TestWriteLine writeLine1 = new TestWriteLine();

            writeLine1.Message     = "writeLine1";
            writeLine1.DisplayName = "writeLine1";

            TestWriteLine writeLine2 = new TestWriteLine();

            writeLine2.Message     = "writeLine2";
            writeLine2.DisplayName = "writeLine2";

            TestParallel parallelActivity = new TestParallel("Parallel Activity");

            parallelActivity.Branches.Add(writeLine1);
            parallelActivity.Branches.Add(writeLine2);

            ExpectedTrace trace = parallelActivity.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallelActivity, trace);
        }
コード例 #6
0
        public void ThreeActivitiesInAndJoin()
        {
            TestFlowchart flowchart = new TestFlowchart("Flow1");

            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");
            TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3");
            TestWriteLine writeLine4 = new TestWriteLine("hello4", "Hello4");

            TestParallel parallel = new TestParallel()
            {
                Branches =
                {
                    writeLine1, writeLine2, writeLine3
                }
            };

            flowchart.AddLink(parallel, writeLine4);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
コード例 #7
0
        /// <summary>
        /// Simple tcf scenario in a parallel.
        /// Try catch in parlallel branch handles exception
        /// </summary>
        /// Disabled and failed in desktop
        //[Fact]
        public void TryCatchInParallel()
        {
            TestParallel parallel = new TestParallel("ParallelCatch")
            {
                Branches =
                {
                    new TestTryCatch("TryCatchBranch1")
                    {
                        Try = new TestThrow <ArgumentException>("Throwing ArgumentException")
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <ArgumentException>()
                            {
                                Body = new TestWriteLine("Catching TestCaseException", "Catching TestCaseException")
                            }
                        },
                    },
                    new TestTryCatch("TryCatchBranch2")
                    {
                        Try = new TestThrow <ArithmeticException>("Throwing ArithmeticException")
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <ArithmeticException>()
                            {
                                Body = new TestWriteLine("Catching ArithmeticException", "Catching ArithmeticException")
                            }
                        },
                    }
                },
            };

            TestRuntime.RunAndValidateWorkflow(parallel);
        }
コード例 #8
0
        public void ParallelWithAChildThatOverridesCancelAndCompletionConditionIsTrue()
        {
            Variable <bool> cancelIt = new Variable <bool> {
                Name = "cancelIt", Default = false
            };

            TestParallel parallelActivity = new TestParallel("Parallel Activity")
            {
                ExpectedOutcome = new Outcome(OutcomeState.Completed)
                {
                    IsOverrideable = false
                },
                HintNumberOfBranchesExecution = 2,
                Variables = { cancelIt },
                CompletionConditionVariable = cancelIt,
                Branches =
                {
                    new TestSequence
                    {
                        Activities =
                        {
                            new TestDelay         {
                                Duration = new TimeSpan(1)
                            },
                            new TestAssign <bool> {
                                ToVariable = cancelIt, Value = true
                            },
                        }
                    },
                    new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Completed)
                    {
                        ExpectedOutcome = new Outcome(OutcomeState.Completed, OutcomeState.Canceled),
                    },
                },
            };

            TestRuntime.RunAndValidateWorkflow(parallelActivity);
        }
コード例 #9
0
        public void DoJob()
        {
            var dataArray  = Enumerable.Range(1, 20).ToArray();
            var arrayCount = dataArray.Length;
            var sum        = 0;
            var i          = 0;
            var watch      = new Stopwatch();

            watch.Start();

            foreach (var data in dataArray)
            {
                var thread = new Thread(() =>
                {
                    var result = TestParallel.TestOperation(data);

                    lock (Lock)
                    {
                        sum += result;
                        i   += 1;
                    }
                });

                thread.Start();
            }

            while (true)
            {
                if (i >= arrayCount)
                {
                    break;
                }
            }

            watch.Stop();

            Console.WriteLine($"Sync operation: Result: {sum}, Time: {watch.ElapsedMilliseconds}.");
        }
コード例 #10
0
        public void MultipleBranchesMultipleChildren()
        {
            TimeSpan time = new TimeSpan(0, 0, 2);

            DelegateInArgument <string> currentVariable = new DelegateInArgument <string>()
            {
                Name = "currentVariable"
            };
            DelegateInArgument <string> currentVariable1 = new DelegateInArgument <string>()
            {
                Name = "currentVariable1"
            };
            DelegateInArgument <string> currentVariable2 = new DelegateInArgument <string>()
            {
                Name = "currentVariable2"
            };
            DelegateInArgument <string> currentVariable3 = new DelegateInArgument <string>()
            {
                Name = "currentVariable3"
            };


            #region Sequence
            TestSequence sequence = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("WritelineAct1", "Hello"),
                    new TestIf("If act1",              HintThenOrElse.Then)
                    {
                        Condition    = true,
                        ThenActivity = new TestWriteLine("Writeline in then1")
                        {
                            Message = "I am writeline in if activity"
                        }
                    },

                    new TestDelay("Delay act1",        time),

                    new TestParallelForEach <string>("Parallel For Each In sequence")
                    {
                        HintValues = new List <string>()
                        {
                            "Element1",                "Element2"
                        },
                        ValuesExpression = (context => new List <string>()
                        {
                            "Element1",                "Element2"
                        }),
                        CurrentVariable  = currentVariable,
                        Body             = new TestWriteLine()
                        {
                            MessageExpression = (env) => (string)currentVariable.Get(env),
                            HintMessageList   = { "Element2", "Element1" }
                        },

                        HintIterationCount = 2
                    },

                    new TestTryCatch()
                    {
                        Try = new TestThrow <NullReferenceException>()
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <NullReferenceException>()
                        }
                    }
                }
            };
            #endregion // Sequence

            #region Sequence1
            TestSequence sequence1 = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("WritelineAct2", "Hello"),
                    new TestIf("If act2",              HintThenOrElse.Then)
                    {
                        Condition    = true,
                        ThenActivity = new TestWriteLine("Writeline in then","I am writeline in if activity")
                    },

                    new TestDelay("Delay act2",        time),

                    new TestParallelForEach <string>("Parallel For Each In sequence1")
                    {
                        HintValues = new List <string>()
                        {
                            "Element1",                "Element2"
                        },
                        ValuesExpression = (context => new List <string>()
                        {
                            "Element1",                "Element2"
                        }),
                        CurrentVariable  = currentVariable1,
                        Body             = new TestWriteLine("Writeline in PFE")
                        {
                            MessageExpression = (env) => (string)currentVariable1.Get(env),
                            HintMessageList   = { "Element2", "Element1" }
                        },

                        HintIterationCount = 2
                    },

                    new TestTryCatch()
                    {
                        Try = new TestThrow <NullReferenceException>()
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <NullReferenceException>()
                        }
                    }
                }
            };

            #endregion // Sequence1

            #region Sequence2
            TestSequence sequence2 = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("WritelineAct3", "Hello"),
                    new TestIf("If act3",              HintThenOrElse.Then)
                    {
                        Condition    = true,
                        ThenActivity = new TestWriteLine("Writeline in then","I am writeline in if activity")
                    },

                    new TestDelay("Delay act3",        time),

                    new TestParallelForEach <string>("Parallel For Each In sequence2")
                    {
                        HintValues = new List <string>()
                        {
                            "Element1",                "Element2"
                        },
                        ValuesExpression = (context => new List <string>()
                        {
                            "Element1",                "Element2"
                        }),
                        CurrentVariable  = currentVariable2,
                        Body             = new TestWriteLine("Writeline in PFE")
                        {
                            MessageExpression = (env) => (string)currentVariable2.Get(env),
                            HintMessageList   = { "Element2", "Element1" }
                        },

                        HintIterationCount = 2
                    },

                    new TestTryCatch()
                    {
                        Try = new TestThrow <NullReferenceException>()
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },
                        Catches =
                        {
                            new TestCatch <NullReferenceException>()
                        }
                    }
                }
            };
            #endregion // Sequence2

            #region Sequence3

            TestSequence sequence3 = new TestSequence()
            {
                Activities =
                {
                    new TestWriteLine("WritelineAct4", "Hello"),
                    new TestIf("If act4",              HintThenOrElse.Then)
                    {
                        Condition    = true,
                        ThenActivity = new TestWriteLine("Writeline in then","I am writeline in if activity")
                    },

                    new TestDelay("Delay act4",        time),

                    new TestParallelForEach <string>("Parallel For Each In sequence3")
                    {
                        HintValues = new List <string>()
                        {
                            "Element1",                "Element2"
                        },
                        ValuesExpression = (context => new List <string>()
                        {
                            "Element1",                "Element2"
                        }),
                        CurrentVariable  = currentVariable3,
                        Body             = new TestWriteLine("Writeline in PFE")
                        {
                            MessageExpression = (env) => (string)currentVariable3.Get(env),
                            HintMessageList   = { "Element2", "Element1" }
                        },

                        HintIterationCount = 2
                    },

                    new TestTryCatch()
                    {
                        Try = new TestThrow <NullReferenceException>()
                        {
                            ExpectedOutcome = Outcome.CaughtException()
                        },

                        Catches =
                        {
                            new TestCatch <NullReferenceException>()
                        }
                    }
                }
            };
            #endregion Sequence2

            TestParallel parallelAct = new TestParallel("ParallelActivity")
            {
                Branches =
                {
                    new TestSequence("First Sequence")
                    {
                        Activities ={ sequence                  }
                    },

                    // Second sequence
                    new TestSequence("Second sequence")
                    {
                        Activities ={ sequence1                 }
                    },

                    // Third sequence
                    new TestSequence("Third sequence")
                    {
                        Activities ={ sequence2                 }
                    },

                    // Fourth Sequence
                    new TestSequence("Fourth Sequence")
                    {
                        Activities ={ sequence3                 }
                    }
                },

                HintNumberOfBranchesExecution = 4
            };

            ExpectedTrace trace = parallelAct.GetExpectedTrace();
            TestRuntime.RunAndValidateWorkflow(parallelAct, trace);
        }
コード例 #11
0
        public void NoBranches()
        {
            TestParallel parallelActivity = new TestParallel("Parallel Activity");

            TestRuntime.RunAndValidateWorkflow(parallelActivity);
        }
コード例 #12
0
        //[HostWorkflowAsWebService]
        public void ParallelWithinParallel()
        {
            Variable <int> counter  = VariableHelper.CreateInitialized <int>("counter", 0);
            TestParallel   parallel = new TestParallel("ParallelActivity")
            {
                Branches =
                {
                    new TestParallelForEach <string>("Parallel For Each in Parallel")
                    {
                        Body = new TestSequence("Seq in Parallel For Each")
                        {
                            Activities =
                            {
                                new TestWhile("While Act")
                                {
                                    Variables           = { counter             },
                                    ConditionExpression = (env) => (bool)(counter.Get(env) < 3),
                                    Body = new TestSequence("Seq in While")
                                    {
                                        Activities =
                                        {
                                            new TestAssign <int>("Assign activity")
                                            {
                                                ToVariable      = counter,
                                                ValueExpression = (env) => (int)counter.Get(env) + 1
                                            },

                                            new TestWriteLine("Writeline in While")
                                            {
                                                Message = "I am a message in while body"
                                            }
                                        }
                                    },

                                    HintIterationCount = 3
                                }
                            }
                        },

                        HintValues = new List <string>()
                        {
                            "Hello", "How", "Are", "You"
                        },
                        ValuesExpression = (context => new List <string>()
                        {
                            "Hello", "How", "Are", "You"
                        }),
                    },

                    new TestParallel("Parallel in Parallel")
                    {
                        Branches =
                        {
                            new TestWriteLine("Writeline",  "Hello"),
                            new TestWriteLine("Writeline2", "World")
                        },

                        CompletionCondition           = true,
                        HintNumberOfBranchesExecution = 1,
                    }
                },
                HintNumberOfBranchesExecution = 2
            };

            ExpectedTrace trace = parallel.GetExpectedTrace();

            TestRuntime.RunAndValidateWorkflow(parallel, trace);
        }
コード例 #13
0
        public void TerminateInParallelBranch()
        {
            s_exceptionType     = typeof(TAC.ApplicationException);
            s_exceptionMsg      = "I am throwing this Exception";
            s_terminationReason = "Just cus!";

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

            TestParallel parallel = new TestParallel("TerminatePar")
            {
                Branches =
                {
                    new TestSequence("ActiveBranch1")
                    {
                        Activities =
                        {
                            new TestWriteLine("ActiveBranch1WL")
                            {
                                Message     = "I should be Executed",
                                HintMessage = "I should be Executed"
                            },
                            new TestDelay()
                            {
                                Duration        = new TimeSpan(0, 0, 5),
                                ExpectedOutcome = Outcome.Faulted
                            }
                        }
                    },

                    new TestSequence("ActiveBranch2")
                    {
                        Activities =
                        {
                            new TestWriteLine("ActiveBranch2WL")
                            {
                                Message     = "I should also be Executed",
                                HintMessage = "I should also be Executed"
                            },
                            new TestDelay()
                            {
                                Duration        = new TimeSpan(0, 0, 5),
                                ExpectedOutcome = Outcome.Faulted
                            }
                        }
                    },

                    new TestTerminateWorkflow("TerminatingBranch")
                    {
                        ExceptionExpression = ((env) => new TAC.ApplicationException("I am throwing this Exception")),
                        Reason = s_terminationReason,
                    },

                    new TestWriteLine("TerminatedBranch!!") // branch is not executed
                    {
                        Message     = "I should be Terminated",
                        HintMessage = "I should be Terminated",

                        ExpectedOutcome = Outcome.Faulted
                    }
                },
            };

            RunTestWithWorkflowRuntime(parallel);
        }
コード例 #14
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);
        }
コード例 #15
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);
        }