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 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 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 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 static void RunAndValidateAbortedException(TestActivity activity, Type exceptionType, Dictionary <string, string> exceptionProperties) { using (TestWorkflowRuntime testWorkflowRuntime = new TestWorkflowRuntime(activity)) { testWorkflowRuntime.ExecuteWorkflow(); Exception exception; testWorkflowRuntime.WaitForAborted(out exception, true); ExceptionHelpers.ValidateException(exception, exceptionType, exceptionProperties); } }
public void WhileWithExceptionFromCondition() { // Test case description: // Throw exception in while and in while condition TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestAssign <int> increment = new TestAssign <int>("Increment Counter"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { Body = innerSequence, HintIterationCount = 10, }; ExceptionThrowingActivitiy <bool> throwFromCondition = new ExceptionThrowingActivitiy <bool>(); ((Microsoft.CoreWf.Statements.While)whileAct.ProductActivity).Condition = throwFromCondition; increment.ToVariable = counter; increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); OrderedTraces trace = new OrderedTraces(); trace.Steps.Add(new ActivityTrace(outerSequence.DisplayName, ActivityInstanceState.Executing)); trace.Steps.Add(new ActivityTrace(whileAct.DisplayName, ActivityInstanceState.Executing)); OrderedTraces ordered = new OrderedTraces(); UnorderedTraces unordered = new UnorderedTraces(); unordered.Steps.Add(ordered); unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Executing)); unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Faulted)); trace.Steps.Add(unordered); ExpectedTrace expected = new ExpectedTrace(trace); expected.AddIgnoreTypes(typeof(WorkflowAbortedTrace)); expected.AddIgnoreTypes(typeof(SynchronizeTrace)); Exception exc; TestWorkflowRuntime tr = TestRuntime.CreateTestWorkflowRuntime(outerSequence); tr.CreateWorkflow(); tr.ResumeWorkflow(); tr.WaitForAborted(out exc, expected); Assert.True((exc.GetType() == typeof(DataMisalignedException)) && exc.Message == "I am Miss.Aligned!"); }
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 TestResumeBookmarkCallback() { const int noBranches = 10; Variable <int> value = VariableHelper.Create <int>("value"); TestParallel parallel = new TestParallel() { Variables = { value }, ExpectedOutcome = Outcome.Faulted }; for (int i = 0; i < noBranches; i++) { string branchName = "Branch" + i.ToString(); TestSequence sequence = new TestSequence() { Activities = { new TestWaitReadLine <int>(branchName, branchName) { BookmarkValue = value, WaitTime = TimeSpan.FromSeconds(10), } }, ExpectedOutcome = Outcome.Faulted, }; if (i > 0) { (sequence.Activities[0] as TestWaitReadLine <int>).ExpectedOutcome = Outcome.Faulted; } parallel.Branches.Add(sequence); } JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel, null, jsonStore, PersistableIdleAction.Persist); runtime.ExecuteWorkflow(); runtime.WaitForIdle(); for (int i = 0; i < noBranches; i++) { string branchName = "Branch" + i.ToString(); runtime.BeginResumeBookMark(branchName, i, null, null); } runtime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait)); runtime.AbortWorkflow("Aborting Workflow"); ExpectedTrace expectTrace = parallel.GetExpectedTrace(); expectTrace.Trace.Steps.Clear(); expectTrace.Trace.Steps.Add(new UserTrace(WaitReadLine <int> .BeforeWait)); expectTrace.Trace.Steps.Add(new UserTrace(WaitReadLine <int> .AfterWait)); expectTrace.AddVerifyTypes(typeof(UserTrace)); Exception exception; runtime.WaitForAborted(out exception, expectTrace); }
private // Abort with Cancel failing in desktop too. so disabling test //[InlineData(true)] void AbortParallel(bool isTestCancel) { const int noBranches = 10; Variable <int> value = VariableHelper.Create <int>("value"); TestParallel parallel = new TestParallel() { Variables = { value }, ExpectedOutcome = Outcome.Faulted }; for (int i = 0; i < noBranches; i++) { string branchName = "Branch" + i.ToString(); TestSequence branchSequence = new TestSequence("Seq" + branchName) { Activities = { new TestWriteLine() { Message = branchName + " Started" }, new TestReadLine <int>(branchName, branchName) { BookmarkValue = value, ExpectedOutcome = Outcome.Faulted }, new TestWriteLine() { Message = branchName + " Completed", ExpectedOutcome = Outcome.Faulted }, }, ExpectedOutcome = Outcome.Faulted }; if (isTestCancel) { if (i == 0) { branchSequence.Activities[1].ExpectedOutcome = Outcome.Canceled; } } parallel.Branches.Add(branchSequence); } TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(parallel); runtime.ExecuteWorkflow(); runtime.WaitForIdle(); //Cancel Workflow if (isTestCancel) { //Log.Info("Cancelling Workflow"); runtime.CancelWorkflow(); runtime.WaitForCanceled(); } //Abort Workflow runtime.AbortWorkflow("Aborting for Test"); ExpectedTrace expectedTrace = parallel.GetExpectedTrace(); //Only verify User trace since activity traces will not be available once abort is called expectedTrace.AddVerifyTypes(typeof(UserTrace)); Exception excepion; runtime.WaitForAborted(out excepion, expectedTrace); }