public void ParallelForEachWithWorkflowInvoker() { TestSequence innerSequence = new TestSequence("innerSeq"); DelegateInArgument <string> i = new DelegateInArgument <string>() { Name = "i" }; string[] strArray = new string[] { "var1", "var2", "var3" }; TestParallelForEach <string> foreachAct = new TestParallelForEach <string>("foreach") { HintValues = strArray, ValuesExpression = (context => new string[] { "var1", "var2", "var3" }), CurrentVariable = i, HintIterationCount = 3 }; TestWriteLine writeLine = new TestWriteLine("write hello") { MessageExpression = ((env) => string.Format("WriteLine Argument: {0}", i.Get(env))) }; for (int counter = strArray.Length - 1; counter > -1; counter--) { writeLine.HintMessageList.Add("WriteLine Argument: " + strArray[counter]); } foreachAct.Body = innerSequence; innerSequence.Activities.Add(writeLine); TestRuntime.RunAndValidateUsingWorkflowInvoker(foreachAct, null, null, null); }
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(); } }
public void CheckForDispose() { //TestCase.Current.Parameters.Add("DisableXamlRoundTrip", "true"); MyRange range = new MyRange(5); DelegateInArgument <int> x = new DelegateInArgument <int>("x"); TestParallelForEach <int> foreachAct = new TestParallelForEach <int> { CurrentVariable = x, ValuesExpression = context => range, HintValues = new int[] { 0, 1, 2, 3, 4 }, Body = new TestWriteLine() { MessageExpression = (env) => x.Get(env).ToString(), HintMessageList = { "0", "1", "2", "3", "4" } }, HintIterationCount = 5 }; TestRuntime.RunAndValidateWorkflow(foreachAct); // the below code will dispose it int c = Enumerable.Count(new MyRange(2)); if (!range.disposeIsCalled) { throw new TestCaseException("dispose is not called on Range!"); } }
public void VariableScopingTest() { DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>() { Name = "_currentVariable" }; TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("ParallelForEach") { CurrentVariable = _currentVariable, HintValues = new string[] { "Hello", "How", "Are", "You" }, ValuesExpression = (context => new string[] { "Hello", "How", "Are", "You" }), Body = new TestParallelForEach <string>("Inner Parallel For Each") { HintValues = new string[] { "Take" }, ValuesExpression = (context => new string[] { "Take" }), Body = new TestWriteLine("Writeline") { MessageExpression = (env) => (string)_currentVariable.Get(env), HintMessageList = { "You", "Are", "How", "Hello" } } } }; ExpectedTrace tr = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, tr); }
public void ParallelForEachWithAChildThatThrowsInCancelWhileCompletionConditionIsTrue() { Variable <bool> cancelIt = new Variable <bool> { Name = "cancelIt", Default = false }; DelegateInArgument <bool> arg = new DelegateInArgument <bool>("arg"); TestParallelForEach <bool> pfeAct = new TestParallelForEach <bool> { HintIterationCount = 2, HintValues = new bool[] { true, false }, ValuesExpression = (e => new bool[] { true, false }), CurrentVariable = arg, CompletionConditionVariable = cancelIt, Body = new TestIf(HintThenOrElse.Then, HintThenOrElse.Else) { ConditionExpression = e => arg.Get(e), ThenActivity = new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Faulted) { ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException)), }, ElseActivity = new TestSequence { Activities = { new TestDelay("d1", new TimeSpan(1)), new TestAssign <bool> { Value = true, ToVariable = cancelIt } } } } }; TestSequence root = new TestSequence { Activities = { pfeAct }, Variables = { cancelIt }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root)) { testWorkflowRuntime.ExecuteWorkflow(); Exception outException = null; testWorkflowRuntime.WaitForAborted(out outException, false); if (outException == null || outException.InnerException == null || !outException.InnerException.GetType().Equals(typeof(TestCaseException))) { throw new TestCaseException(String.Format("Workflow was suuposed to Abort with a TestCaseException, but this is the exception: {0}", outException.ToString())); } else { //Log.Info("Workflow aborted as excpected"); } } }
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); }
public void BodyHandlerIsNull() { TestParallelForEach <int> foreachAct = new TestParallelForEach <int>("foreach") { ValuesExpression = context => new int[] { 1, 2, 3 }, HintIterationCount = 3 }; foreachAct.ProductParallelForEach.Body = new ActivityAction <int>(); TestRuntime.RunAndValidateWorkflow(foreachAct); }
//[HostWorkflowAsWebService] public void DelayDoesNotBlockOtherExecution() { // In this scenario, I use "delayed" variable to make sure the Delay activity was not a blocking one // This is verified, by setting the "delayed" variable after Delay activity is done. DelegateInArgument <string> currentVariable = new DelegateInArgument <string>() { Name = "currentVariable" }; Variable <bool> delayed = VariableHelper.CreateInitialized <bool>("delayed", false); TimeSpan sec = new TimeSpan(0, 0, 0, 0, 1); TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("PFE") { CurrentVariable = currentVariable, Body = new TestSequence("BodyOfParallel") { Variables = { delayed }, Activities = { new TestIf("If condition", HintThenOrElse.Then, HintThenOrElse.Then) { ConditionExpression = ((env) => !delayed.Get(env)), ThenActivity = new TestSequence("Body of If") { Activities = { new TestDelay() { Duration = sec }, new TestAssign <bool> { Value = true, ToVariable = delayed } }, }, }, } }, HintValues = new string[] { "a", "b" }, ValuesExpression = (context => new string[] { "a", "b" }), HintIterationCount = 2 }; ExpectedTrace trace = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, trace); }
public void ThrowExceptionInValues() { UnorderedTraces ordered = new UnorderedTraces() { Steps = { new OrderedTraces() { Steps = { new ActivityTrace("w1", ActivityInstanceState.Executing), new ActivityTrace("w1", ActivityInstanceState.Faulted), } }, new OrderedTraces() { Steps = { new ActivityTrace("w1", ActivityInstanceState.Executing), new ActivityTrace("w1", ActivityInstanceState.Faulted), } }, new OrderedTraces() { Steps = { new ActivityTrace("w1", ActivityInstanceState.Executing), new ActivityTrace("w1", ActivityInstanceState.Faulted), } } } }; TestParallelForEach <int> foreachAct = new TestParallelForEach <int>("foreach") { ValuesExpression = context => new IEnumerableWithException { NumberOfIterations = 3 }, Body = new TestWriteLine("w1") { Message = "w1" }, ExpectedOutcome = Outcome.Faulted, ActivitySpecificTraces = { ordered, } }; TestRuntime.RunAndValidateAbortedException(foreachAct, typeof(TestCaseException), new Dictionary <string, string>()); }
public void CompletionConditionCancelsRestOfBranches() { Variable <bool> cancelIt = new Variable <bool> { Name = "cancelIt", Default = false }; DelegateInArgument <int> i = new DelegateInArgument <int>() { Name = "i" }; TestWriteLine w1 = new TestWriteLine("w1", "write1") { HintMessageList = { "write1", "write1", "write1" } }; TestAssign <bool> a1 = new TestAssign <bool> { Value = true, ToVariable = cancelIt, }; TestIf decide = new TestIf(HintThenOrElse.Else, HintThenOrElse.Else, HintThenOrElse.Then) { ConditionExpression = ((ctx) => i.Get(ctx) < 5), ThenActivity = a1, ElseActivity = w1, }; TestParallelForEach <int> foreachAct = new TestParallelForEach <int>("foreach") { HintValues = new int[] { 1, 2, 3, 4, 5, 6 }, ValuesExpression = (context => new int[] { 1, 2, 3, 4, 5, 6 }), CurrentVariable = i, HintIterationCount = 3, Body = decide, CompletionConditionVariable = cancelIt, }; TestSequence sequence = new TestSequence { Activities = { foreachAct }, Variables = { cancelIt }, }; TestRuntime.RunAndValidateWorkflow(sequence); }
public void BodyNullAndCompletionConditionNotNull() { Variable <bool> temp = new Variable <bool>("temp"); Variable <string> strVar = new Variable <string>("strVar", "HI"); TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel For Each") { HintIterationCount = 3, ProductParallelForEach = { Body = null, CompletionCondition = true, Values = new InArgument <IEnumerable <string> >(context => new string[] { "Hi","There", "Why" }), } }; TestRuntime.RunAndValidateWorkflow(parallelForEach); }
public void ChangeElementValueInBody() { DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>() { Name = "_currentVariable" }; TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel for each") { Body = new TestSequence() { Activities = { new TestAssign <string>("Assign activity") { ToExpression = context => _currentVariable.Get(context), Value = "New changed variable" }, new TestWriteLine("Writeline") { MessageExpression = context => _currentVariable.Get(context), HintMessage = "New changed variable" } } }, HintValues = new List <string>() { "str1", "str2", "str3" }, ValuesExpression = (context => new List <string>() { "str1", "str2", "str3" }), HintIterationCount = 3, CurrentVariable = _currentVariable }; ExpectedTrace tr = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, tr); }
public void CompletionConditionTrue() { TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel For Each") { HintValues = new string[] { "Hi", "There", "Why" }, ValuesExpression = (context => new string[] { "Hi", "There", "Why" }), Body = new TestSequence("Sequence") { Activities = { new TestWriteLine("Writeline", "Hello") }, }, CompletionCondition = true, HintIterationCount = 1 }; ExpectedTrace tr = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, tr); }
public void NullAsValueOfElements() { TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel For Each") { Body = new TestWriteLine("Writeline") { Message = "I will be displayed" }, HintValues = new List <string>() { null }, ValuesExpression = (context => new List <string>() { null }), HintIterationCount = 1, }; ExpectedTrace tr = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, tr); }
public void BasicParallelForEachTest() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("innerSeq"); DelegateInArgument <string> i = new DelegateInArgument <string>() { Name = "i" }; string[] strArray = new string[] { "var1", "var2", "var3" }; TestParallelForEach <string> foreachAct = new TestParallelForEach <string>("foreach"); foreachAct.HintValues = new string[] { "var1", "var2", "var3" }; foreachAct.ValuesExpression = (context => new string[] { "var1", "var2", "var3" }); foreachAct.CurrentVariable = i; foreachAct.HintIterationCount = 3; TestWriteLine writeLine = new TestWriteLine("write hello"); writeLine.MessageExpression = ((env) => string.Format("WriteLine Argument: {0}", i.Get(env))); for (int counter = strArray.Length - 1; counter > -1; counter--) { writeLine.HintMessageList.Add("WriteLine Argument: " + strArray[counter]); } foreachAct.Body = innerSequence; innerSequence.Activities.Add(writeLine); outerSequence.Activities.Add(foreachAct); ExpectedTrace tr = outerSequence.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(outerSequence, tr); }
public void ParallelForEachWithAChildThatOverridesCancelAndCompletionConditionIsTrue() { Variable <bool> cancelIt = new Variable <bool> { Name = "cancelIt", Default = false }; DelegateInArgument <bool> arg = new DelegateInArgument <bool>("arg"); TestParallelForEach <bool> pfeAct = new TestParallelForEach <bool> { DisplayName = "ParallelForEach1", HintIterationCount = 2, HintValues = new bool[] { true, false }, ValuesExpression = (e => new bool[] { true, false }), CurrentVariable = arg, CompletionConditionVariable = cancelIt, Body = new TestIf(HintThenOrElse.Then, HintThenOrElse.Else) { DisplayName = "If1", ConditionExpression = e => arg.Get(e), ThenActivity = new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Completed) { ExpectedOutcome = new Outcome(OutcomeState.Completed, OutcomeState.Canceled), }, ElseActivity = new TestSequence { DisplayName = "Sequence2", Activities = { new TestDelay("d1", new TimeSpan(1)), new TestAssign <bool> { DisplayName = "Assign1",Value = true, ToVariable = cancelIt } } } }, }; TestSequence root = new TestSequence { DisplayName = "Sequence1", Activities = { pfeAct }, Variables = { cancelIt }, }; OrderedTraces ordered = new OrderedTraces() { Steps = { new ActivityTrace("Sequence1", ActivityInstanceState.Executing), new ActivityTrace("ParallelForEach1", ActivityInstanceState.Executing), new UnorderedTraces { Steps = { new OrderedTraces() { Steps = { new ActivityTrace("If1", ActivityInstanceState.Executing), new ActivityTrace("writeLineInCancel", ActivityInstanceState.Executing), new ActivityTrace("w1", ActivityInstanceState.Executing), new ActivityTrace("w1", ActivityInstanceState.Closed), new ActivityTrace("writeLineInCancel", ActivityInstanceState.Closed), new ActivityTrace("If1", ActivityInstanceState.Closed), } }, new OrderedTraces() { Steps = { new ActivityTrace("If1", ActivityInstanceState.Executing), new ActivityTrace("Sequence2", ActivityInstanceState.Executing), new ActivityTrace("d1", ActivityInstanceState.Executing), new ActivityTrace("d1", ActivityInstanceState.Closed), new ActivityTrace("Assign1", ActivityInstanceState.Executing), new ActivityTrace("Assign1", ActivityInstanceState.Closed), new ActivityTrace("Sequence2", ActivityInstanceState.Closed), new ActivityTrace("If1", ActivityInstanceState.Closed), new ActivityTrace("VariableValue<Boolean>", ActivityInstanceState.Executing), new ActivityTrace("VariableValue<Boolean>", ActivityInstanceState.Closed), } } } }, new ActivityTrace("ParallelForEach1", ActivityInstanceState.Closed), new ActivityTrace("Sequence1", ActivityInstanceState.Closed), } }; ExpectedTrace trace = new ExpectedTrace(ordered); trace.AddIgnoreTypes(typeof(SynchronizeTrace)); trace.AddIgnoreTypes(typeof(BookmarkResumptionTrace)); TestRuntime.RunAndValidateWorkflow(root, trace); }
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(); } }
public void PersistParallelForEach() { DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>() { Name = "_currentVariable" }; TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel for each") { HintValues = new string[] { "Hi", "There" }, ValuesExpression = (context => new string[] { "Hi", "There" }), CurrentVariable = _currentVariable, Body = new TestSequence("Sequence") { Activities = { new TestWriteLine("Writeline") { Message = "Hi" }, new TestSequence("inner seq") { Activities = { new TestIf(HintThenOrElse.Else, HintThenOrElse.Then) { DisplayName = "Test if", ConditionExpression = (env) => (bool)(_currentVariable.Get(env).Equals("Hi")), ThenActivity = new TestBlockingActivity("Block Hi"), ElseActivity = new TestBlockingActivity("Block There") } } }, new TestWriteLine("Writeline act") { Message = "After blocking activty" }, } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelForEach, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("Block Hi", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.ResumeBookMark("Block Hi", null); testWorkflowRuntime.WaitForActivityStatusChange("Block There", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.ResumeBookMark("Block There", null); testWorkflowRuntime.WaitForCompletion(); } }