/// <summary> /// Five level deep nested flowchart with blocking activity /// </summary> /// Disabled and failed in desktop //[Fact] public void FiveLevelDeepNestedFlowchartWithBlockingActivity() { TestFlowchart parent = new TestFlowchart(); TestFlowchart child1 = new TestFlowchart(); TestFlowchart child2 = new TestFlowchart(); TestFlowchart child3 = new TestFlowchart(); TestFlowchart child4 = new TestFlowchart(); TestBlockingActivity blocking = new TestBlockingActivity("Blocked"); parent.AddStartLink(child1); child1.AddStartLink(child2); child2.AddStartLink(child3); child3.AddStartLink(child4); child4.AddStartLink(blocking); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parent)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.ResumeBookMark("Blocked", null); testWorkflowRuntime.WaitForCompletion(); } }
public void UnloadFlowchartWhileExecutingFlowStep() { TestFlowchart flowchart = new TestFlowchart(); TestBlockingActivity blocking = new TestBlockingActivity("Block"); flowchart.AddStartLink(blocking); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(); } }
public void PersistInCatch() { TestBlockingActivity blocking = new TestBlockingActivity("Bookmark"); TestTryCatch tcf = new TestTryCatch { Try = new TestThrow <Exception>() { ExpectedOutcome = Outcome.CaughtException() }, Catches = { { new TestCatch <Exception> { Body = blocking } } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tcf, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Bookmark", null); testWorkflowRuntime.WaitForCompletion(); } }
public void AddTextWriterExtensionToRuntimeAndUseWriteLineWithTextWriter() { string stringToWrite = "Writing text to a file with StreamWriter object"; using (StreamWriter streamWriter1 = new StreamWriter(new MemoryStream())) { using (StreamWriter streamWriter2 = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write))) { TestProductWriteline writeline = new TestProductWriteline("Write with StreamWriter") { Text = stringToWrite, TextWriterExpression = context => streamWriter2, }; using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(writeline)) { runtime.CreateWorkflow(); runtime.Extensions.Add(streamWriter1); runtime.ResumeWorkflow(); runtime.WaitForCompletion(); } } } VerifyTextOfWriteLine(_tempFilePath, stringToWrite); }
public void PersistenceToWriteLineActivity() { TestProductWriteline writeLine1 = new TestProductWriteline("writeLine1"); writeLine1.TextExpressionActivity = new TestExpressionEvaluatorWithBody <string>() { Body = (new TestBlockingActivity("BlockingActivity")), ExpressionResult = "This should be displayed after the bookmark" }; using (StreamWriter writer = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write))) { Console.SetOut(writer); TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity"); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime workflow = TestRuntime.CreateTestWorkflowRuntime(writeLine1, null, jsonStore, PersistableIdleAction.None)) { workflow.ExecuteWorkflow(); workflow.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing); workflow.PersistWorkflow(); workflow.ResumeBookMark("BlockingActivity", null); workflow.WaitForCompletion(); } } }
public void OnAbortedThrowException() { TestSequence sequence = new TestSequence() { Activities = { new TestReadLine <string>("Read1", "Read1") { } } }; TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence); runtime.OnWorkflowAborted += new EventHandler <TestWorkflowAbortedEventArgs>(OnWorkflowInstanceAborted_ThrowException); runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.AbortWorkflow("Abort Workflow"); TestTraceManager.Instance.WaitForTrace(runtime.CurrentWorkflowInstanceId, new SynchronizeTrace(TraceMessage_ThrowExceptionFromAborted), 1); //Verify that the product can continue to function runtime = TestRuntime.CreateTestWorkflowRuntime(sequence); runtime.ExecuteWorkflow(); runtime.ResumeBookMark("Read1", "Continue workflow"); runtime.WaitForCompletion(); }
public void PersistFlowchart() { TestFlowchart flowchart = new TestFlowchart(); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity"); flowchart.AddStartLink(writeLine1); flowchart.AddLink(writeLine1, blocking); flowchart.AddLink(blocking, writeLine2); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.ResumeBookMark("BlockingActivity", null); testWorkflowRuntime.WaitForCompletion(); } }
private static string ExecuteWorkflowAndGetResult(Activity we, out Exception ex) { ex = null; using (StreamWriter streamWriter = ConsoleSetOut()) { using (TestWorkflowRuntime twr = new TestWorkflowRuntime(new TestWrapActivity(we))) { twr.ExecuteWorkflow(); try { twr.WaitForCompletion(false); } // Capture ApplicationException only, which is thrown by TestWorkflowRuntime catch (Exception e) // jasonv - approved; specific, commented, returns exception { ex = e.InnerException; } } } if (!File.Exists(s_path)) { throw new FileNotFoundException(); } string[] texts = File.ReadAllLines(s_path); return(string.Concat(texts)); }
public void FlowSwitchHavingCaseWithNullKeyEvaluateNull() { TestFlowchart flowchart = new TestFlowchart(); Variable <Complex> complexVar = VariableHelper.CreateInitialized <Complex>("complexVar", (Complex)null); flowchart.Variables.Add(complexVar); Dictionary <Complex, TestActivity> cases = new Dictionary <Complex, TestActivity>(); cases.Add(new Complex(0, 0), new TestWriteLine("One", "One")); cases.Add(new Complex(1, 0), new TestWriteLine("Two", "Two")); cases.Add(new Complex(2, 0), new TestWriteLine("Three", "Three")); List <int> hints = new List <int>() { -1 }; TestFlowSwitch <Complex> flowSwitch = flowchart.AddSwitchLink <Complex>(new TestWriteLine("Start", "Flowchart started"), cases, hints, e => complexVar.Get(e)) as TestFlowSwitch <Complex>; ((FlowSwitch <Complex>)flowSwitch.GetProductElement()).Cases.Add(null, new FlowStep { Action = new BlockingActivity("Blocking") }); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(flowchart)) { runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing); runtime.ResumeBookMark("Blocking", null); runtime.WaitForCompletion(false); } }
private static void RunAndValidateWorkflow(TestActivity testActivity, ExpectedTrace expectedTrace, List <TestConstraintViolation> constraints, ValidationSettings validatorSettings, bool runValidations, WorkflowIdentity definitionIdentity = null) { using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(testActivity, definitionIdentity)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForCompletion(expectedTrace); } }
public void PersistWithinBranch() { TestParallel parallel = new TestParallel("Parallel Act") { Branches = { new TestSequence("seq1") { Activities = { new TestBlockingActivity("Blocking activity 1") } }, new TestSequence("seq2") { Activities = { new TestBlockingActivity("Blocking activity 2") } }, new TestSequence("seq3") { Activities = { new TestBlockingActivity("Blocking activity 3") } }, new TestWriteLine("writeline after seq3") { Message = "HI" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange("Blocking activity 1", TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.ResumeBookMark("Blocking activity 1", null); runtime.WaitForActivityStatusChange("Blocking activity 2", TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.ResumeBookMark("Blocking activity 2", null); runtime.WaitForActivityStatusChange("Blocking activity 3", TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.ResumeBookMark("Blocking activity 3", null); runtime.WaitForCompletion(); } }
public void TryTerminatingActivityAfterThrowInTryCatch() { s_exceptionType = typeof(InvalidCastException); s_terminationReason = "I like home!"; TestTryCatch tryCatch = new TestTryCatch("TryCatch") { Try = new TestSequence("TryingSeq") { Activities = { new TestWriteLine() { Message = "I'm Trying here", HintMessage = "I'm Trying here" }, new TestThrow <ArgumentException>("TryException") { ExpectedOutcome = Outcome.CaughtException(), }, new TestTerminateWorkflow() { ExceptionExpression = context => new InvalidCastException("I want to go home now!"), Reason = s_terminationReason } } }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("CaughtException") { Message = "aha I caught you!", HintMessage = "aha I caught you!" } } }, Finally = new TestWriteLine("Finally") { Message = "Ha! Now you have to stay", HintMessage = "Ha! Now you have to stay" } }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tryCatch)) { testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowCompletedNoExceptions); testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForCompletion(); } }
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); } }
public void CheckWorkflowProperties() { TestActivity workflow = new TestWriteLine("Write1", "Write a line"); TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow); runtime.CreateWorkflow(); runtime.Extensions.Add(new CheckWorkflowPropertiesExtension(runtime.CurrentWorkflowInstanceId, workflow.ProductActivity)); runtime.ResumeWorkflow(); ExpectedTrace expectedTrace = workflow.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); runtime.WaitForCompletion(expectedTrace); }
public void ChangePropertyNameAfterOpened() { Variable <TheStruct> var = new Variable <TheStruct>() { Name = "var", Default = new TheStruct() }; TestValueTypePropertyReference <TheStruct, int> valueTypePropertyReference = new TestValueTypePropertyReference <TheStruct, int>() { PropertyName = "PublicProperty", OperandLocationVariable = var }; int value = 321; TestAssign <int> testAssign = new TestAssign <int>() { ToLocation = valueTypePropertyReference, Value = value, }; TestSequence sequence = new TestSequence() { Variables = { var }, Activities = { new TestWriteLine("Start", "Start"), new TestBlockingActivity("Blocking"), testAssign, }, }; using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence)) { runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange("Blocking", TestActivityInstanceState.Executing); valueTypePropertyReference.PropertyName = "PublicProperty1"; runtime.ResumeBookMark("Blocking", null); runtime.WaitForCompletion(true); } }
public void UnloadFlowchartWhileExecutingFlowSwitchExpression() { TestFlowchart flowchart = new TestFlowchart(); TestWriteLine writeHello = new TestWriteLine("Hello", "Hello"); TestWriteLine writeStart = new TestWriteLine("Start", "Start"); TestExpressionEvaluatorWithBody <object> expressionActivity = new TestExpressionEvaluatorWithBody <object> { ExpressionResultExpression = context => "One", Body = new TestBlockingActivity("Block"), WillBodyExecute = true }; Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>(); cases.Add("One", writeHello); cases.Add("Two", new TestWriteLine("Two", "Two will not execute")); List <int> hints = new List <int>() { 0 }; flowchart.AddStartLink(writeStart); flowchart.AddSwitchLink(writeStart, cases, hints, expressionActivity, new TestWriteLine("Default", "Will not execute")); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(expressionActivity.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(); } }
/// <summary> /// Have blocking activity (Receive) in flowchart and raise the event unblocking it. /// </summary> /// /// Disabled and failed in desktop //[Fact] public void BlockingActivityInFlowchart() { TestFlowchart flowchart = new TestFlowchart(); TestBlockingActivity blocking = new TestBlockingActivity("Block"); flowchart.AddLink(new TestWriteLine("Start", "Start"), blocking); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(); } }
public void PersistInTry() { TestBlockingActivity blocking = new TestBlockingActivity("Bookmark"); TestTryCatch tryCatch = new TestTryCatch("TryCatchTest") { Try = new TestSequence("TrySeq") { Activities = { blocking, new TestThrow <ArgumentException>("TryException") { ExpectedOutcome = Outcome.CaughtException() }, }, }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Caught", "Caught") } }, Finally = new TestWriteLine("Finally", "Finally") }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tryCatch, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Bookmark", null); testWorkflowRuntime.WaitForCompletion(); } }
public void IfInWhileWithPersistence() { // Test case description: // Above scenario with persistence to see if there will be any change in the behavior and if we are able // tp preserve the state and the rules fine. Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestIf(HintThenOrElse.Then) { Condition = true, ThenActivity = new TestBlockingActivity("Bookmark"), }, new TestIncrement { CounterVariable = count, IncrementCount = 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
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(); } }
public void DoWhilePersisted() { Variable <int> counter = new Variable <int>("Counter", 0); TestBlockingActivity blocking = new TestBlockingActivity("B"); TestDoWhile doWhile = new TestDoWhile { Variables = { counter }, ConditionExpression = (env) => counter.Get(env) < 1, Body = new TestSequence { Activities = { blocking, new TestIncrement { IncrementCount = 1, CounterVariable = counter } } }, HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(doWhile, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.ResumeBookMark("B", null); runtime.WaitForCompletion(); } }
public void UnloadFlowchartWhileExecutingFlowConditionalCondition() { TestFlowchart flowchart = new TestFlowchart(); TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true) { Body = new TestBlockingActivity("Block"), WillBodyExecute = true }; TestFlowConditional conditional = new TestFlowConditional(HintTrueFalse.True) { ConditionValueExpression = expression }; flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"), conditional, new TestWriteLine("True", "True Action"), new TestWriteLine("False", "False Action")); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(System.Environment.CurrentDirectory); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(expression.DisplayName, TestActivityInstanceState.Executing); //testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(true); } }
public void WhilePersisted() { Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestBlockingActivity("Bookmark"), new TestIncrement { CounterVariable = count, IncrementCount= 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
public static void TestResumeWithDelay() { var testSequence = new TestSequence() { Activities = { new TestDelay() { Duration = TimeSpan.FromMilliseconds(100) }, } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.PersistWorkflow(); workflowRuntime.WaitForUnloaded(); workflowRuntime.LoadWorkflow(); workflowRuntime.ResumeWorkflow(); workflowRuntime.WaitForCompletion(false); }
public void ThrowFromInterfaceMethods() { TestActivity workflow = new TestWriteLine("Write1", "Write a line"); TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow); runtime.PersistenceProviderFactoryType = null; runtime.CreateWorkflow(); ThrowFromAdditionalExtensions throwFromAdditionalExtensions = new ThrowFromAdditionalExtensions(); CheckExceptionPropagated(throwFromAdditionalExtensions, "Throw from AdditionalExtensionsAdded", runtime); ThrowFromSetInstance throwFromSetInstance = new ThrowFromSetInstance(); CheckExceptionPropagated(throwFromSetInstance, "Throw from SetInstance", runtime); runtime.ResumeWorkflow(); ExpectedTrace expectedTrace = workflow.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); runtime.WaitForCompletion(expectedTrace); }
public void VerifyAdditionalExtensionsAdded() { TestActivity workflow = new TestReadLine <int>("Read1", "Read1"); TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow); runtime.OnWorkflowUnloaded += WorkflowInstanceHelper.wfRuntime_OnUnload; runtime.CreateWorkflow(); runtime.Extensions.Add(new AdditionalExtensionsAdded(new Collection <object>() { new OperationOrderTracePersistExtension(runtime.CurrentWorkflowInstanceId) })); runtime.ResumeWorkflow(); runtime.WaitForIdle(); runtime.ResumeBookMark("Read1", 1); ExpectedTrace expectedTrace = workflow.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); runtime.WaitForCompletion(expectedTrace); runtime.WaitForTrace(new UserTrace(WorkflowInstanceHelper.UnloadMessage)); runtime.WaitForTrace(new UserTrace(OperationOrderTracePersistExtension.TraceSave)); }
public void SetTextWriterToNullAndUseATextWriterExtension() { string stringToWrite = "Writing text to a file with StreamWriter object"; using (StreamWriter streamWriter = new StreamWriter(new FileStream(_tempFilePath, FileMode.Create, FileAccess.Write))) { TestProductWriteline writeline = new TestProductWriteline("Write with StreamWriter") { Text = stringToWrite, }; writeline.ProductWriteLine.TextWriter = null; using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(writeline)) { runtime.CreateWorkflow(); runtime.Extensions.Add(streamWriter); runtime.ResumeWorkflow(); runtime.WaitForCompletion(); } } VerifyTextOfWriteLine(_tempFilePath, stringToWrite); }
public void DelayPersisted() { Variable <int> counter = new Variable <int>("Counter", 0); TestBlockingActivity blocking = new TestBlockingActivity("B"); TestSequence seq = new TestSequence { Activities = { new TestWriteLine("Before") { Message = "Before" }, new TestDelay() { Duration = TimeSpan.FromSeconds(1) }, new TestWriteLine("After") { Message = "After" } } }; TestSequence seq2 = new TestSequence { Activities = { new TestWriteLine("Before") { Message = "Before" }, new TestDelay() { Duration = TimeSpan.FromSeconds(1) }, new TestWriteLine("After") { Message = "After" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); var instanceHandle = jsonStore.CreateInstanceHandle(); var instanceView = jsonStore.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.MaxValue); var instanceOwner = instanceView.InstanceOwner; jsonStore.DefaultInstanceOwner = instanceOwner; //Guid id; using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(seq, null, jsonStore, PersistableIdleAction.Unload)) { runtime.ExecuteWorkflow(); runtime.WaitForUnloaded(); //id = runtime.CurrentWorkflowInstanceId; Thread.Sleep(TimeSpan.FromSeconds(2)); //runtime.InitiateWorkflowForLoad(); //runtime.LoadRunnableInitiatedWorkflowForInstance(/*TimeSpan.Zero, id*/); runtime.LoadRunnableWorkflow(); runtime.ResumeWorkflow(); runtime.WaitForCompletion(); } }
public static void TestOperationsResumeBookmarkCallback(int operationId) { Variable <int> value = VariableHelper.Create <int>("value"); const string WaitMessage = "WaitActivity will wait for this trace"; TestSequence 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" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing); TestWorkflowRuntimeAsyncResult 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); } ExpectedTrace expectedTrace = testSequence.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); workflowRuntime.WaitForCompletion(expectedTrace); }
public static void TestPersistDuringResumeBookmark() { bool isSync = true; Variable <int> value = VariableHelper.Create <int>("value"); Variable <string> persist = VariableHelper.Create <string>("persist"); const string WaitMessage = "Continue the WaitActivity"; TestSequence testSequence = new TestSequence() { Variables = { value, persist }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitForTrace() { DisplayName = "WaitActivity", TraceToWait = WaitMessage, DelayDuration = TimeSpan.FromMilliseconds(10) }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value, WaitTime = TimeSpan.FromSeconds(1) }, new TestReadLine <string>("PersistBookmark", "PersistBookmark") { BookmarkValue = persist }, new TestWriteLine() { MessageExpression = ((env) => value.Get(env).ToString()), HintMessage = "9999" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing); TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage)); SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage); if (isSync) { workflowRuntime.ResumeBookMark("Read", 9999); workflowRuntime.PersistWorkflow(); } else { TestWorkflowRuntimeAsyncResult asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null); TestWorkflowRuntimeAsyncResult asyncResultPersist = workflowRuntime.BeginPersistWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndPersistWorkflow(asyncResultPersist); } workflowRuntime.WaitForActivityStatusChange("PersistBookmark", TestActivityInstanceState.Executing); workflowRuntime.WaitForUnloaded(1); workflowRuntime.LoadWorkflow(); workflowRuntime.ResumeBookMark("PersistBookmark", "Yes"); workflowRuntime.WaitForCompletion(false); }