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 TerminateActivityWithExceptionWithoutReason() { s_exceptionType = typeof(TAC.ApplicationException); s_exceptionMsg = "I am throwing this Exception"; s_terminationReason = null; TestSequence seq = new TestSequence("TerminateSeq") { Activities = { new TestTerminateWorkflow("Terminating") { ExceptionExpression = ((env) => new TAC.ApplicationException("I am throwing this Exception")) } }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(seq)) { testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(VerifyUnsetValue); testWorkflowRuntime.ExecuteWorkflow(); WaitForTerminationHelper(testWorkflowRuntime); } }
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); } }
public void WhileCancelled() { Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestBlockingActivity blocking = new TestBlockingActivity("Bookmark") { ExpectedOutcome = Outcome.Canceled }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = blocking, ConditionExpression = (e => count.Get(e) < 5), HintIterationCount = 1, ExpectedOutcome = Outcome.Canceled }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(whileAct)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); testWorkflowRuntime.WaitForCanceled(); } }
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 CancelElseDuringExecution() { TestIf testIf = new TestIf("MyIf", HintThenOrElse.Else) { Condition = false, ThenActivity = new TestWriteLine("Then Branch", "The message would not be displayed"), ElseActivity = new TestSequence("Else Branch") { Activities = { new TestCustomActivity <BlockingActivity>("BlockingActivity", null) { ExpectedOutcome = Outcome.Canceled }, new TestWriteLine("Test WriteLine", "The message would not be displayed"), }, }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testIf)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); testWorkflowRuntime.WaitForCanceled(); } }
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 DoWhileCancelled() { TestDoWhile doWhile = new TestDoWhile("Do while") { Condition = true, Body = new TestSequence("Do While Body") { Activities = { new TestBlockingActivity("BlockingActivity", "Bookmark") { ExpectedOutcome = Outcome.Canceled }, new TestWriteLine("Writeline") { Message = "Hello" } } }, HintIterationCount = 1, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(doWhile)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); // This test is not run on desktop and I don't think it would pass there if it did run. //testWorkflowRuntime.WaitForCompletion(); testWorkflowRuntime.WaitForCanceled(); } }
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 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(); } }
public void CancelExecutingChildActivities() { TestFlowchart parent = new TestFlowchart("Parent"); TestBlockingActivity blocking = new TestBlockingActivity("BlockingActivity", "B1"); TestWriteLine writeLine1 = new TestWriteLine("w1", "w1"); TestWriteLine writeLine2 = new TestWriteLine("w2", "w2"); parent.AddLink(writeLine1, blocking); TestFlowElement element = parent.AddLink(blocking, writeLine2); element.IsCancelling = true; blocking.ExpectedOutcome = Outcome.Canceled; parent.ExpectedOutcome = Outcome.Canceled; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parent)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("BlockingActivity", TestActivityInstanceState.Executing); testWorkflowRuntime.CancelWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.WaitForCanceled(); } }
/// <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 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 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 RethrowExceptionFromInvokeMethodWithAllExceptionPropertiesSet() { TestInvokeMethod im = new TestInvokeMethod { TargetObject = new TestArgument <CustomClassForRethrow>(Direction.In, "TargetObject", (context => new CustomClassForRethrow())), MethodName = "M1", ExpectedOutcome = Outcome.CaughtException(typeof(TestCaseException)), }; TestTryCatch tc = new TestTryCatch(); TestCatch <TestCaseException> tcCatch = new TestCatch <TestCaseException> { Body = new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException)) } }; tc.Try = im; tc.Catches.Add(tcCatch); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tc)) { testWorkflowRuntime.ExecuteWorkflow(); Exception outEx; testWorkflowRuntime.WaitForAborted(out outEx); Dictionary <string, string> errorProperty = new Dictionary <string, string>(); errorProperty.Add("Message", "this should be caught"); ExceptionHelpers.ValidateException(outEx, typeof(TestCaseException), errorProperty); } }
public void TerminateActivityWithReasonWithoutException() { s_exceptionType = null; s_exceptionMsg = null; s_terminationReason = "Just cus!"; TestSequence seq = new TestSequence("TerminateSeq") { Activities = { new TestSequence("Second") { Activities = { new TestTerminateWorkflow("Terminating") { Reason = s_terminationReason, } } } }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(seq)) { testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(VerifyUnsetValue); testWorkflowRuntime.ExecuteWorkflow(); WaitForTerminationHelper(testWorkflowRuntime); } }
private void RunTestWithWorkflowRuntime(TestActivity activity) { using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(activity)) { testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowInstance_Completed); testWorkflowRuntime.ExecuteWorkflow(); WorkflowTrackingWatcher watcher = testWorkflowRuntime.GetWatcher(); OrderedTraces orderedExpectedTrace = new OrderedTraces { Steps = { new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Started), new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Terminated), new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Deleted) { Optional = true } } }; ExpectedTrace expectedWorkflowInstacneTrace = new ExpectedTrace(orderedExpectedTrace); Exception exp = new Exception(); testWorkflowRuntime.WaitForTerminated(1, out exp, watcher.ExpectedTraces, expectedWorkflowInstacneTrace); } }
private static WorkflowApplicationInstance GetADummyWorkflowApplicationInstance() { WorkflowIdentity wfIdentity = new WorkflowIdentity("GetAWorkflowApplicationInstanceParameter", new Version(1, 0), null); TestSequence wfDefinition = new TestSequence() { Activities = { new TestWriteLine("testWriteLine1", "In TestWriteLine1"), new TestReadLine <string>("ReadLine1", "testReadLine1"), new TestWriteLine("testWriteLine2", "In TestWriteLine2") }, }; WorkflowApplicationInstance waInstance; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(wfDefinition, null, jsonStore, PersistableIdleAction.Unload)) { //PersistenceProviderHelper pphelper = new PersistenceProviderHelper(workflowRuntime.PersistenceProviderFactoryType); //InstanceStore store = pphelper.CreateWorkflowInstanceStore(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForIdle(); workflowRuntime.UnloadWorkflow(); workflowRuntime.WaitForUnloaded(); Guid worklfowInstanceId = workflowRuntime.CurrentWorkflowInstanceId; waInstance = WorkflowApplication.GetInstance(worklfowInstanceId, jsonStore); waInstance.Abandon(); } return(waInstance); }
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 CustomActivityOverridesBranchCancelStateWithThrow() { const string triggerMessage = "Trigger branch's trigger is executing."; TestPick pick = new TestPick() { DisplayName = "PickActivity", Branches = { new TestPickBranch() { DisplayName = "TriggeredBranch_Branch", Trigger = new TestWriteLine("TriggeredBranch_Trigger") { Message = triggerMessage, HintMessage = triggerMessage, }, }, new TestPickBranch() { DisplayName = "FaultedCustomActivity_Branch", Trigger = new TestBlockingActivityWithWriteLineInCancel("FaultedCustomActivity_Trigger", OutcomeState.Faulted) { ExpectedOutcome = Outcome.UncaughtException(), }, Action = new TestWriteLine("FaultedCustomActivity_Action") { Message = "FaultedCustomActivity_Action - not supposed to show", }, }, } }; // wrapping the custom activity with a try-catch doesn't work here // try-catch doesn't catch an exception that comes from a Cancel // by design in Beta2, any exception thrown from Cancel will Abort the workflow immediately // Note: for this test case (and similar ones e.g. Parallel), we can only compare the Exception type // because this is a special case, we cannot validate the traces as exception is thrown from // Cancel and by design runtime doesn't catch it. As a result, there is no chance to validate. using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(pick)) { testWorkflowRuntime.ExecuteWorkflow(); Exception outException = null; testWorkflowRuntime.WaitForAborted(out outException, false); // Due to how we get the tracking information, the exception is not the original exception and // we cannot check the InnerException property. Assert.NotNull(outException); //if (outException == null || outException.InnerException == null || !outException.InnerException.GetType().Equals(typeof(TestCaseException))) //{ // throw new TestCaseException(String.Format("Workflow was supposed to Abort with a TestCaseException, but this is the exception: {0}", outException.ToString())); //} //else //{ // //Log.Info("Workflow aborted as excpected"); //} } }
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 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 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 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 static void RunAndValidateAbortedException(TestActivity activity, Type exceptionType, Dictionary <string, string> exceptionProperties) { using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(activity)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForAborted(out Exception exception, true); ExceptionHelpers.ValidateException(exception, exceptionType, exceptionProperties); } }
public void PersistAfterCatchBeforeRethrow() { TestTryCatch root = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TAC.ApplicationException> { ExceptionExpression = (context => new TAC.ApplicationException("abcd")), ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } }, Catches = { new TestCatch <TAC.ApplicationException> { Body = new TestSequence { Activities = { new TestBlockingActivity("Blocking1", "B1"), new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)), } } } } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root, null, jsonStore, CoreWf.PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("Blocking1", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Blocking1", null); Exception resultedException; testWorkflowRuntime.WaitForAborted(out resultedException); if (!(resultedException is TAC.ApplicationException)) { throw resultedException; } } }
public void ResumeBookmarkWhileTerminating() { s_exceptionType = typeof(TAC.ApplicationException); s_exceptionMsg = "I am throwing this Exception"; s_terminationReason = "Just cus!"; TestParallel parallel = new TestParallel("ParallelTest") { Branches = { new TestSequence("BlockingBranch") { Activities = { new TestWriteLine("BeforeBlocking") { Message = "I should be Executed", HintMessage = "I should be Executed" }, new TestBlockingActivity("Blocking", "BlockBranch") { ExpectedOutcome = Outcome.Faulted } } }, new TestTerminateWorkflow("TerminatingBranch") { ExceptionExpression = ((env) => new TAC.ApplicationException("I am throwing this Exception")), Reason = s_terminationReason, }, }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallel)) { testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowInstance_Completed); testWorkflowRuntime.ExecuteWorkflow(); WaitForTerminationHelper(testWorkflowRuntime); // Try resuming the bookmark BookmarkResumptionResult result = testWorkflowRuntime.ResumeBookMark("Blocking", null); if (result != BookmarkResumptionResult.NotFound) { throw new TestCaseFailedException("Bookmark should be cancelled"); } } }
public void ParallelWithAChildThatThrowsInCancelAndCompletionConditionIsTrue() { Variable <bool> cancelIt = new Variable <bool> { Name = "cancelIt", Default = false }; TestParallel parallelActivity = new TestParallel("Parallel Activity") { 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.Faulted) { ExpectedOutcome = Outcome.UncaughtException() }, }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelActivity)) { 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 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(); } }