public void SameVariableNameNest() { //TestParameters.DisableXamlRoundTrip = true; Variable <string> var1 = VariableHelper.CreateInitialized <string>("var1", "Variable in Pick"); Variable <string> var2 = VariableHelper.CreateInitialized <string>("var1", "Variable in Branch1"); TestSequence seq = new TestSequence("TestSeq") { Variables = { var1 }, Activities = { new TestPick() { DisplayName = "Pick", Branches = { new TestPickBranch() { DisplayName = "Branch1", Variables = { var2 }, Trigger = new TestDelay() { Duration = new TimeSpan(0, 0, 3) }, Action = new TestWriteLine("Action1") { HintMessage = "Variable in Branch1", MessageExpression = (env) => var2.Get(env) } }, new TestPickBranch() { DisplayName = "Branch2", Trigger = new TestBlockingActivity("Block2") { ExpectedOutcome = Outcome.Canceled }, Action = new TestWriteLine("Action2") { Message = "Action2" } }, } } } }; ExpectedTrace trace = seq.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(seq, trace); }
public void ParallelForEachInLoop() { //TestParameters.DisableXamlRoundTrip = true; List <string> list1 = new List <string>() { "Item11", "Item12", "Item13" }; List <string> list2 = new List <string>() { "Item21", "Item22", "Item23" }; List <List <string> > lists = new List <List <string> >(); lists.Add(list1); lists.Add(list2); DelegateInArgument <List <string> > listVar = new DelegateInArgument <List <string> >() { Name = "listVar" }; DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>() { Name = "_currentVariable" }; TestSequence seq = new TestSequence("Outer Seq") { Activities = { new TestForEach <List <string> >("For Each in Outer Seq") { ValuesExpression = (context => lists), CurrentVariable = listVar, Body = new TestParallelForEach <string>("Parallel For Each") { CurrentVariable = _currentVariable, Body = new TestWriteLine("Writeline in for each") { MessageExpression = (env) => (string)_currentVariable.Get(env), HintMessageList = { "Item13", "Item12", "Item11", "Item23", "Item22", "Item21" } }, HintValues = list1, // This is a hack to let the tracing know about the number of values inside ValuesExpression. ValuesExpression = context => listVar.Get(context), HintIterationCount = 3 }, HintIterationCount = 2 } } }; ExpectedTrace tr = seq.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(seq, tr); }
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); }
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") { HintValues = new string[] { "var1", "var2", "var3" }, 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); outerSequence.Activities.Add(foreachAct); ExpectedTrace tr = outerSequence.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(outerSequence, tr); }
public void DifferentArguments() { //Testing Different argument types for Switch.Expression // DelegateInArgument // DelegateOutArgument // Activity<T> // Variable<T> , Activity<T> and Expression is already implemented. DelegateInArgument <string> delegateInArgument = new DelegateInArgument <string>("Input"); DelegateOutArgument <string> delegateOutArgument = new DelegateOutArgument <string>("Output"); TestCustomActivity <InvokeFunc <string, string> > invokeFunc = TestCustomActivity <InvokeFunc <string, string> > .CreateFromProduct( new InvokeFunc <string, string> { Argument = "PassedInValue", Func = new ActivityFunc <string, string> { Argument = delegateInArgument, Result = delegateOutArgument, Handler = new CoreWf.Statements.Sequence { DisplayName = "Sequence1", Activities = { new CoreWf.Statements.Switch <string> { DisplayName = "Switch1", Expression = delegateInArgument, Cases = { { "PassedInValue", new CoreWf.Statements.Assign <string> { DisplayName = "Assign1", To = delegateOutArgument, Value = "OutValue", } }, }, Default = new Test.Common.TestObjects.CustomActivities.WriteLine{ DisplayName = "W1", Message = "This should not be printed" }, }, new CoreWf.Statements.Switch <string> { DisplayName = "Switch2", Expression = delegateOutArgument, Cases = { { "OutValue", new Test.Common.TestObjects.CustomActivities.WriteLine { DisplayName = "W2", Message = delegateOutArgument } } }, Default = new Test.Common.TestObjects.CustomActivities.WriteLine{ DisplayName = "W3", Message = "This should not be printed" }, } } } } } ); TestSwitch <string> switch1 = new TestSwitch <string> { DisplayName = "Switch1", Hints = { 0 } }; switch1.AddCase("PassedInValue", new TestAssign <string> { DisplayName = "Assign1" }); switch1.Default = new TestWriteLine { DisplayName = "W1" }; TestSwitch <string> switch2 = new TestSwitch <string> { DisplayName = "Switch2", Hints = { 0 } }; switch2.AddCase("OutValue", new TestWriteLine { DisplayName = "W2", HintMessage = "OutValue" }); switch2.Default = new TestWriteLine { DisplayName = "W3" }; TestSequence sequenceForTracing = new TestSequence { DisplayName = "Sequence1", Activities = { switch1, switch2, } }; invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace); TestRuntime.RunAndValidateWorkflow(invokeFunc); }
public void DifferentArguments() { //Testing Different argument types for If.Condition // DelegateInArgument // DelegateOutArgument // Activity<T> // Variable<T> , Activity<T> and Expression is already implemented. DelegateInArgument <bool> delegateInArgument = new DelegateInArgument <bool>("Condition"); DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output"); TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct( new InvokeFunc <bool, bool> { Argument = true, Func = new ActivityFunc <bool, bool> { Argument = delegateInArgument, Result = delegateOutArgument, Handler = new System.Activities.Statements.Sequence { DisplayName = "Sequence1", Activities = { new System.Activities.Statements.If { DisplayName = "If1", Condition = delegateInArgument, Then = new System.Activities.Statements.Sequence { DisplayName = "Sequence2", Activities = { new System.Activities.Statements.Assign <bool> { DisplayName = "Assign1", Value = delegateInArgument, To = delegateOutArgument, }, new System.Activities.Statements.If { DisplayName = "If2", Condition = delegateOutArgument, Then = new System.Activities.Statements.WriteLine { DisplayName = "W1", Text = "Tested DelegateIn and DelegateOut arguments in If condition" }, } } } } }, } } } ); TestSequence sequenceForTracing = new TestSequence { DisplayName = "Sequence1", Activities = { new TestIf(HintThenOrElse.Then) { DisplayName = "If1", ThenActivity = new TestSequence { DisplayName = "Sequence2", Activities = { new TestAssign <bool> { DisplayName = "Assign1" }, new TestIf(HintThenOrElse.Then) { DisplayName = "If2", ThenActivity = new TestSequence("W1"), } } } } } }; invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace); TestIf root = new TestIf(HintThenOrElse.Then) { ConditionActivity = invokeFunc, ThenActivity = new TestWriteLine { Message = "True", HintMessage = "True" }, ElseActivity = new TestWriteLine { Message = "False", HintMessage = "This is not expected" }, }; TestRuntime.RunAndValidateWorkflow(root); }
public static void TestOperationsResumeBookmarkCallback(int operationId) { var value = VariableHelper.Create <int>("value"); const string WaitMessage = "WaitActivity will wait for this trace"; var testSequence = new TestSequence() { Variables = { value }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitForTrace() { DisplayName = "WaitActivity", TraceToWait = WaitMessage }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value }, new TestReadLine <int>("Read1", "Read1") { BookmarkValue = value }, new TestWriteLine() { Message = "Workflow Completed" } } }; var jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); var workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing); var asyncResult = workflowRuntime.BeginResumeBookMark("Read", 10, new AsyncCallback(ResumeBookmarkCallback), operationId); //Continue the WaitActivity TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage)); SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage); workflowRuntime.EndResumeBookMark(asyncResult); workflowRuntime.WaitForTrace(new UserTrace("After ResumeBookmarkCallback")); if (operationId == 2) { //Do nothing } else if (operationId == 3) { workflowRuntime.UnloadWorkflow(); workflowRuntime.LoadWorkflow(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.ResumeBookMark("Read1", 99); } else if (operationId == 4) { workflowRuntime.LoadWorkflow(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.ResumeBookMark("Read1", 99); } var expectedTrace = testSequence.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); workflowRuntime.WaitForCompletion(expectedTrace); }
private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync) { var shouldNotExecuteMsg = "Should not see this message"; var value = VariableHelper.Create <int>("value"); var writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg) { }; var 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; } var 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; var message = ""; //Execute Workflow var 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. var 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: { workflowRuntime.WaitForTerminated(1, out var 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"); } } }
public void DifferentArguments() { //Testing Different argument types for DoWhile.Condition // DelegateInArgument // DelegateOutArgument // Variable<T> , Activity<T> and Expression is already implemented. DelegateInArgument <bool> delegateInArgument = new DelegateInArgument <bool>("Condition"); DelegateOutArgument <bool> delegateOutArgument = new DelegateOutArgument <bool>("Output"); TestCustomActivity <InvokeFunc <bool, bool> > invokeFunc = TestCustomActivity <InvokeFunc <bool, bool> > .CreateFromProduct( new InvokeFunc <bool, bool> { Argument = true, Func = new ActivityFunc <bool, bool> { Argument = delegateInArgument, Result = delegateOutArgument, Handler = new Microsoft.CoreWf.Statements.Sequence { DisplayName = "sequence1", Activities = { new Microsoft.CoreWf.Statements.DoWhile { DisplayName = "DoWhile1", Condition = ExpressionServices.Convert <bool>(ctx => delegateInArgument.Get(ctx)), Body = new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign1", To = delegateInArgument, Value = new Not <bool, bool> { DisplayName = "Not1", Operand = delegateInArgument } }, }, new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign2", To = delegateOutArgument, Value = new Not <bool, bool> { DisplayName = "Not2", Operand = delegateInArgument }, }, new Microsoft.CoreWf.Statements.DoWhile { DisplayName = "DoWhile2", Condition = ExpressionServices.Convert <bool>(ctx => !delegateOutArgument.Get(ctx)), Body = new Microsoft.CoreWf.Statements.Assign <bool> { DisplayName = "Assign3", To = delegateOutArgument, Value = new Not <bool, bool> { DisplayName = "Not3", Operand = delegateInArgument } }, }, }, } } } ); TestSequence sequenceForTracing = new TestSequence { DisplayName = "sequence1", Activities = { new TestDoWhile { DisplayName = "DoWhile1", ActivitySpecificTraces = { new OrderedTraces() { Steps = { new ActivityTrace("Assign1", ActivityInstanceState.Executing), new ActivityTrace("Not1", ActivityInstanceState.Executing), new ActivityTrace("Not1", ActivityInstanceState.Closed), new ActivityTrace("Assign1", ActivityInstanceState.Closed), new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Executing), new ActivityTrace("DelegateArgumentValue<Boolean>", ActivityInstanceState.Closed), } }, } }, new TestAssign <bool> { DisplayName = "Assign2", ValueActivity = new Test.Common.TestObjects.Activities.Expressions.TestNot <bool, bool>{ DisplayName = "Not2" } }, new TestDoWhile { DisplayName = "DoWhile2", ActivitySpecificTraces = { new OrderedTraces() { Steps = { new ActivityTrace("Assign3", ActivityInstanceState.Executing), new ActivityTrace("Not3", ActivityInstanceState.Executing), new ActivityTrace("Not3", ActivityInstanceState.Closed), new ActivityTrace("Assign3", ActivityInstanceState.Closed), new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Executing), new ActivityTrace("Not<Boolean,Boolean>", ActivityInstanceState.Closed), } }, } }, } }; invokeFunc.CustomActivityTraces.Add(sequenceForTracing.GetExpectedTrace().Trace); TestIf root = new TestIf(HintThenOrElse.Then) { ConditionActivity = invokeFunc, ThenActivity = new TestWriteLine { Message = "True", HintMessage = "True" }, ElseActivity = new TestWriteLine { Message = "False", HintMessage = "This is not expected" }, }; TestRuntime.RunAndValidateWorkflow(root); }