public void ParallelForEachInTryCatchFinally() { TestTryCatch tcf = new TestTryCatch("TCF") { Try = new TestParallelForEach <string>("Parallel for each") { Body = new TestThrow <InvalidCastException> { ExpectedOutcome = Outcome.CaughtException(typeof(InvalidCastException)) }, HintValues = new List <string>() { "str1", "STR2", "str3" }, ValuesExpression = (context => new List <string>() { "str1", "STR2", "str3" }), CompletionCondition = true, HintIterationCount = 1, }, Catches = { new TestCatch <InvalidCastException>() { HintHandleException = true } } }; ExpectedTrace tr = tcf.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(tcf, tr); }
public void TryCatchFinallyWithExceptionInCatchingCatch() { TestTryCatch tryCatch = new TestTryCatch("TryCatchTest") { Try = new TestSequence("TrySeq") { Activities = { new TestThrow <ArgumentException>("TryException") { ExpectedOutcome = Outcome.CaughtException() }, }, }, Catches = { new TestCatch <ArgumentException>() { Body = new TestThrow <ArithmeticException>("Throw from catch") { ExceptionExpression = (context => new ArithmeticException()) } }, }, Finally = new TestWriteLine("Finally", "Finally") }; // Run test TestRuntime.RunAndValidateAbortedException(tryCatch, typeof(ArithmeticException), null); }
public void TryCatchFinallyActivityOnly() { TestTryCatch tcf = new TestTryCatch { // try Try = new TestThrow <ArgumentException>() { ExpectedOutcome = Outcome.CaughtException() } }; // catch TestCatch <ArgumentException> tc = new TestCatch <ArgumentException> { Body = new TestWriteLine("Hello world!", "Hello world!") }; tcf.Catches.Add(tc); // finally tcf.Finally = new TestWriteLine("Finally", "Finally"); // Run test TestRuntime.RunAndValidateWorkflow(tcf); }
/// <summary> /// Parallel in TryCatch and handled by trycatch. Any executing branch will be cancelled. ( parallel within parallel and all branches are blocking at the same time so that you see the cancel behavior) /// Parallel in TryCatch and handled by trycatch . Any executing branch will be cancelled. ( parallel within parallel and all branches are blocking at the same time so that you see the cancel behavior) /// </summary> /// Disabled and failed in desktop //[Fact] public void ParallelInTryCatch() { TestTryCatch tryCatch = new TestTryCatch("TryCatch") { Try = new TestParallel("TryCatchParallel") { Branches = { new TestWriteLine("WritingFirst", "WritingFirst"), new TestThrow <ArgumentException>("Throwing") { ExpectedOutcome = Outcome.CaughtException() }, new TestWriteLine("AfterThrow", "AfterThrow") { ExpectedOutcome = Outcome.Canceled } } }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Catching ArgumentException", "Catching ArgumentException") } } }; TestRuntime.RunAndValidateWorkflow(tryCatch); }
public void TryCatchWithWorkflowInvoker() { TestTryCatch tcf = new TestTryCatch { // try Try = new TestThrow <ArgumentException>() { ExpectedOutcome = Outcome.CaughtException() } }; // catch TestCatch <ArgumentException> tc = new TestCatch <ArgumentException> { Body = new TestWriteLine("Hello world!", "Hello world!") }; tcf.Catches.Add(tc); // finally tcf.Finally = new TestWriteLine("Finally", "Finally"); // Run test TestRuntime.RunAndValidateUsingWorkflowInvoker(tcf, null, null, null); }
public void TryCatchFinallyWithCaughtExceptionInFinally() { TestTryCatch outer = new TestTryCatch("Outer TCF") { Try = new TestTryCatch("Inner TCF") { Finally = new TestSequence("Finally") { Activities = { new TestThrow <Exception>() { ExpectedOutcome = Outcome.CaughtException() }, new TestWriteLine("Not called", "Not printed"), } } }, Catches = { new TestCatch <Exception>() { Body = new TestWriteLine("Catch", "Catch"), } } }; // run the workflow TestRuntime.RunAndValidateWorkflow(outer); }
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(); } }
/// <summary> /// Exception thrown from 5 level deep nested flowchart and handled at the top level. /// </summary> //[Fact] public void FaultFromFiveLevelDeepNestedFlowchart_Handled() { TestFlowchart parent = new TestFlowchart(); TestFlowchart child1 = new TestFlowchart(); TestFlowchart child2 = new TestFlowchart(); TestFlowchart child3 = new TestFlowchart(); TestFlowchart child4 = new TestFlowchart(); child4.AddStartLink(new TestThrow <WorkflowApplicationAbortedException>() { ExpectedOutcome = Outcome.CaughtException() }); child1.AddStartLink(child2); child2.AddStartLink(child3); child3.AddStartLink(child4); TestTryCatch tryCatchFinally = new TestTryCatch(); tryCatchFinally.Try = child1; tryCatchFinally.Catches.Add(new TestCatch <WorkflowApplicationAbortedException>()); parent.AddStartLink(tryCatchFinally); TestRuntime.RunAndValidateWorkflow(parent); }
public void ThrowCatchRethrow() { TestTryCatch ttc = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TAC.ApplicationException> { ExceptionExpression = (context => new TAC.ApplicationException("this is expected uncaught exception")), ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } }, Catches = { new TestCatch <TAC.ApplicationException> { Body = new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)), } } } }; Dictionary <string, string> exceptionProperties = new Dictionary <string, string>(); TestRuntime.RunAndValidateAbortedException(ttc, typeof(TAC.ApplicationException), exceptionProperties); }
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 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 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 ThrowInNestedTryCatchRethrowInTheTopTryCatch() { TestTryCatch root = new TestTryCatch("parentTryCatch"); root.Catches.Add( new TestCatch <TAC.ApplicationException> { Body = new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)), } }); TestTryCatch level1 = new TestTryCatch("level1"); level1.Catches.Add(new TestCatch <ArithmeticException> { Body = new TestProductWriteline("don't write this 1") }); root.Try = level1; TestTryCatch level2 = new TestTryCatch("level2"); level2.Catches.Add(new TestCatch <ArithmeticException> { Body = new TestProductWriteline("don't write this 2") }); level1.Try = level2; TestTryCatch level3 = new TestTryCatch("level3"); level3.Catches.Add(new TestCatch <ArithmeticException> { Body = new TestProductWriteline("don't write this 3") }); level2.Try = level3; level3.Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TAC.ApplicationException> { ExceptionExpression = (context => new TAC.ApplicationException("this is expected uncaught exception")), ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } }; Dictionary <string, string> exceptionProperties = new Dictionary <string, string>(); TestRuntime.RunAndValidateAbortedException(root, typeof(TAC.ApplicationException), exceptionProperties); }
public void TerminateActivityInCatch() { s_exceptionType = typeof(InvalidCastException); s_exceptionMsg = "I want to go home now!"; 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(), }, } }, Catches = { new TestCatch <ArgumentException>() { Body = new TestSequence("CatchingSeq") { Activities = { new TestTerminateWorkflow() { ExceptionExpression = ((env) => new InvalidCastException("I want to go home now!")), Reason = s_terminationReason }, new TestWriteLine("CaughtException") { Message = "Should not execute", HintMessage = "A Bug if executed", ExpectedOutcome = Outcome.None } } } } }, }; RunTestWithWorkflowRuntime(tryCatch); }
public void ThrowWithInnerException() { // Initializing variable which we will use to catch the exception object DelegateInArgument <MemberAccessException> accExc = new DelegateInArgument <MemberAccessException>(); //TestParameters.DisableXamlRoundTrip = true; TestSequence seq = new TestSequence("Outer Seq") { Activities = { new TestTryCatch("Try catch finally") { Try = new TestSequence("Try Activity") { Activities = { new TestThrow <MemberAccessException>("Throw Operation exception") { ExceptionExpression = (context => new MemberAccessException("Throw Exception", new IndexOutOfRangeException())), //InnerException = new IndexOutOfRangeException(), ExpectedOutcome = Outcome.CaughtException(), } } }, Catches = { new TestCatch <MemberAccessException>() { ExceptionVariable = accExc, Body = new TestSequence("Body of Catch") { Activities = { // Rethrowing inner exception so we can verify correct exception is thrown new TestThrow <IndexOutOfRangeException>("Throw inner exception") { ExceptionExpression = (env) => (IndexOutOfRangeException)accExc.Get(env).InnerException, ExpectedOutcome = Outcome.UncaughtException(typeof(IndexOutOfRangeException)) } } }, } } } } }; TestRuntime.RunAndValidateAbortedException(seq, typeof(IndexOutOfRangeException), new Dictionary <string, string>()); }
public void NullMessageInException() { // Initializing variable which we will use to catch the exception object DelegateInArgument <DataMisalignedException> objDisp = new DelegateInArgument <DataMisalignedException> { Name = "objDisp" }; DataMisalignedException ex = new DataMisalignedException(null); TestSequence outerSeq = new TestSequence() { Activities = { new TestTryCatch("Try Catch finally") { Try = new TestSequence() { Activities = { new TestThrow <DataMisalignedException>("throw1") { ExceptionExpression = (context => new DataMisalignedException(null)), ExpectedOutcome = Outcome.CaughtException(), } } }, Catches = { new TestCatch <DataMisalignedException>() { ExceptionVariable = objDisp, Body = new TestSequence() { Activities = { new TestWriteLine() { MessageExpression = (env) => (string)objDisp.Get(env).Message, HintMessage = ex.Message, } } }, } } } } }; TestRuntime.RunAndValidateWorkflow(outerSeq); }
public void ThrowExceptionWithMessage() { // Initializing variable which we will use to catch the exception object DelegateInArgument <OperationCanceledException> op = new DelegateInArgument <OperationCanceledException>(); //TestParameters.DisableXamlRoundTrip = true; TestSequence seq = new TestSequence("Outer Seq") { Activities = { new TestTryCatch("Try catch finally") { Try = new TestSequence("Try Activity") { Activities = { new TestThrow <OperationCanceledException>("Throw Operation exception") { ExceptionExpression = (context => new OperationCanceledException("We have set the message to overwrite exception message")), ExpectedOutcome = Outcome.CaughtException(), } } }, Catches = { new TestCatch <OperationCanceledException>() { ExceptionVariable = op, Body = new TestSequence("Body of Catch") { Activities = { new TestWriteLine("Writeline for exception message") { MessageExpression = (env) => op.Get(env).Message, HintMessage = "We have set the message to overwrite exception message" } } }, } } } } }; TestRuntime.RunAndValidateWorkflow(seq); }
public void CatchWithEmptyHandler() { TestTryCatch tcf = new TestTryCatch(); // try tcf.Try = new TestThrow <IOException>() { ExpectedOutcome = Outcome.CaughtException() }; // catch TestCatch <IOException> tc = new TestCatch <IOException>(); // do not add to tc.Body, want empty Action.Handler tcf.Catches.Add(tc); // Run test TestRuntime.RunAndValidateWorkflow(tcf); }
public void RethrowAndCatch() { TestTryCatch root = new TestTryCatch("parent TryCatch") { Try = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TAC.ApplicationException> { ExceptionExpression = (context => new TAC.ApplicationException("this is expected uncaught exception")), ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } }, Catches = { new TestCatch <TAC.ApplicationException> { Body = new TestRethrow { ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } } }, Catches = { new TestCatch <TAC.ApplicationException> { Body = new TestWriteLine { Message = "You catched the exception :)" } } } }; TestRuntime.RunAndValidateWorkflow(root); }
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 ThrowExceptionInOneCatchAndCatchItInOtherCatch() { TestTryCatch tryCatch = new TestTryCatch("TryCatchTestParent") { Try = new TestTryCatch("TryCatchTestChild") { Try = new TestSequence("TrySeq") { Activities = { new TestThrow <ArgumentException>("TryException") { ExpectedOutcome = Outcome.CaughtException() }, }, }, Catches = { new TestCatch <ArgumentException>() { Body = new TestThrow <ArithmeticException>("Throw from catch") { ExceptionExpression = (context => new ArithmeticException()), ExpectedOutcome = Outcome.CaughtException() } }, }, Finally = new TestWriteLine("Finally", "Finally") }, Catches = { new TestCatch <ArithmeticException>() { Body = new TestWriteLine("CaughtIt", "I caught you") }, } }; // Run test TestRuntime.RunAndValidateWorkflow(tryCatch); }
public void TryCatchFinallyCustomException() { // try TestThrow <CustomException> custromTry = new TestThrow <CustomException>("custom exception") { ExceptionExpression = (context => new CustomException("Invalid department")), ExpectedOutcome = Outcome.CaughtException() }; // catch TestCatch[] catches = new TestCatch[] { new TestCatch <CustomException>() }; // finally TestWriteLine finallyWrite = new TestWriteLine("FinallyCatchingCustomException", "FinallyCatchingCustomException"); // create and run TestActivity act = CreateTryCatchFinally(custromTry, catches, finallyWrite, WFType.SEQ, true); TestRuntime.RunAndValidateWorkflow(act); }
public void RethrowFromCatchHandlerOfPrivateActivity() { string message = "this is expected uncaught exception"; TestCustomActivity <TestRethrowInPrivateChildren> rethrowAct = new TestCustomActivity <TestRethrowInPrivateChildren>() { ExpectedOutcome = Outcome.UncaughtException(), }; rethrowAct.CustomActivityTraces.Add(new ActivityTrace("Rethrow", CoreWf.ActivityInstanceState.Executing)); rethrowAct.CustomActivityTraces.Add(new ActivityTrace("Rethrow", CoreWf.ActivityInstanceState.Faulted)); TestTryCatch ttc = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TestCaseException> { ExceptionExpression = (context => new TestCaseException(message)), ExpectedOutcome = Outcome.CaughtException(typeof(TestCaseException)), } } }, Catches = { new TestCatch <TestCaseException> { Body = rethrowAct } } }; //The validation error has a prefix: string validationError = string.Format(ErrorStrings.ValidationErrorPrefixForHiddenActivity, "2: " + rethrowAct.DisplayName) + string.Format(ErrorStrings.RethrowMustBeAPublicChild, "Rethrow"); TestRuntime.ValidateInstantiationException(ttc, validationError); }
/// <summary> /// Simple tcf scenario in a parallel. /// Try catch in parlallel branch handles exception /// </summary> /// Disabled and failed in desktop //[Fact] public void TryCatchInParallel() { TestParallel parallel = new TestParallel("ParallelCatch") { Branches = { new TestTryCatch("TryCatchBranch1") { Try = new TestThrow <ArgumentException>("Throwing ArgumentException") { ExpectedOutcome = Outcome.CaughtException() }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Catching TestCaseException", "Catching TestCaseException") } }, }, new TestTryCatch("TryCatchBranch2") { Try = new TestThrow <ArithmeticException>("Throwing ArithmeticException") { ExpectedOutcome = Outcome.CaughtException() }, Catches = { new TestCatch <ArithmeticException>() { Body = new TestWriteLine("Catching ArithmeticException", "Catching ArithmeticException") } }, } }, }; TestRuntime.RunAndValidateWorkflow(parallel); }
public void RethrowInFinally() { TestRethrow tr = new TestRethrow(); 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>() }, Finally = new TestSequence { Activities = { new TestSequence { Activities = { tr } } } } }; TestRuntime.ValidateInstantiationException(root, string.Format(ErrorStrings.RethrowNotInATryCatch, tr.DisplayName)); }
/// <summary> /// Fault handled from flowchart in a try catch block. /// </summary> /// Disabled in desktop and failing. //[Fact] public void FlowchartInTryCatchBlock_FaultHandled() { TestFlowchart flowchart = new TestFlowchart(); flowchart.AddStartLink(new TestThrow <Exception>() { ExpectedOutcome = Outcome.CaughtException() }); TestTryCatch tryCatchFinally = new TestTryCatch { Try = flowchart, Catches = { new TestCatch <Exception> { Body = new TestWriteLine("ExceptionHandler", "Handled"), } } }; TestRuntime.RunAndValidateWorkflow(tryCatchFinally); }
public void TryCatchFinallyInLoops() { Variable <int> count = new Variable <int>("Counter", 0); TestWhile whileAct = new TestWhile { Variables = { count }, ConditionExpression = e => count.Get(e) < 5, Body = new TestSequence { Activities = { new TestTryCatch { Try = new TestThrow <ArgumentException>() { ExpectedOutcome = Outcome.CaughtException() }, Catches = { { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Caught", "Caught") } } }, Finally = new TestSequence{ Activities ={ new TestWriteLine("Finally", "Finally") } } }, new TestIncrement { CounterVariable = count, IncrementCount = 1 } } }, HintIterationCount = 5 }; TestRuntime.RunAndValidateWorkflow(whileAct); }
public void RethrowCustomExceptionWithNonSerializableProperty() { //TestParameters.DisableXamlRoundTrip = true; string message = "this is expected uncaught exception"; TestTryCatch ttc = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <CustomExceptionWithNonSerializableProperty> { ExceptionExpression = context => new CustomExceptionWithNonSerializableProperty(message) { NonSerializableP = new NonSerializableType("A") }, ExpectedOutcome = Outcome.CaughtException(typeof(CustomExceptionWithNonSerializableProperty)), } } }, Catches = { new TestCatch <CustomExceptionWithNonSerializableProperty> { Body = new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(CustomExceptionWithNonSerializableProperty)), } } } }; Dictionary <string, string> exceptionProperties = new Dictionary <string, string>(); TestRuntime.RunAndValidateAbortedException(ttc, typeof(CustomExceptionWithNonSerializableProperty), exceptionProperties); }
public void CustomParentChildInheritedExceptionCatchAndRethrow() { TestTryCatch ttc = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <CustomException> { ExceptionExpression = context => new CustomException("this is expected uncaught exception"), ExpectedOutcome = Outcome.CaughtException(typeof(CustomException)), } } }, Catches = { new TestCatch <CustomException> { Body = new TestSequence("seq1 in Catch-TAC.ApplicationException-") { Activities = { new TestWriteLine { Message = "This should be printed", HintMessage = "This should be printed", }, new TestRethrow { DisplayName = "LastRethrow", ExpectedOutcome = Outcome.UncaughtException(typeof(CustomException)), } } } }, new TestCatch <Exception> { Body = new TestSequence("seq1 in Catch-Exception-") { ExpectedOutcome = Outcome.None, Activities = { new TestWriteLine { Message = "This should not be printed", }, new TestRethrow { DisplayName = "FirstRethrow", } } } }, } }; Dictionary <string, string> exceptionProperties = new Dictionary <string, string>(); TestRuntime.RunAndValidateAbortedException(ttc, typeof(CustomException), exceptionProperties); }
/// <summary> /// Nest trycatchfinallies 5 levels deep and catch uncaught exception in outer try catch /// Nest trycatchfinallies 5 levels deep and catch uncatched exception in outer try catch…etc /// </summary> /// Disabled and failed in desktop //[Fact] public void TryCatchFinallyNested() { TestTryCatch NestedTryCatch = new TestTryCatch("Level1Try") { Try = new TestTryCatch("Level2Try") { Try = new TestTryCatch("Level3Try") { Try = new TestTryCatch("Level4Try") { Try = new TestTryCatch("Level5Try") { Try = new TestThrow <ArithmeticException>("Level5Throw") { ExpectedOutcome = Outcome.CaughtException() }, Catches = { new TestCatch <ArgumentOutOfRangeException>() { Body = new TestWriteLine("Not Catching"), } } }, Catches = { new TestCatch <ArithmeticException>() { Body = new TestThrow <MemberAccessException>("Level4Throw") { ExpectedOutcome = Outcome.CaughtException() } } } }, Catches = { new TestCatch <MemberAccessException>() { Body = new TestThrow <FileNotFoundException>("Level3Throw") { ExpectedOutcome = Outcome.CaughtException() } } } }, Catches = { new TestCatch <FileNotFoundException>() { Body = new TestThrow <ArgumentException>("Level2Throw") { ExpectedOutcome = Outcome.CaughtException() } } } }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("No More Catching!", "No More Catching!") } } }; TestRuntime.RunAndValidateWorkflow(NestedTryCatch); }