public void InheritedExceptions1() { // exception which is raised Exception exc = new Exception(); // try TestSequence trySeq = new TestSequence(); trySeq.Activities.Add(new TestWriteLine("Try", "Try")); TestThrow <Exception> tt = new TestThrow <Exception>("TestThrow1") { ExceptionExpression = (context => new Exception()) }; trySeq.Activities.Add(tt); // catch TestCatch[] catches = new TestCatch[] { new TestCatch <ArgumentException>() }; // create and run TestActivity act = CreateTryCatchFinally(trySeq, catches, null, WFType.SEQ, true); TestRuntime.RunAndValidateAbortedException(act, exc.GetType(), new Dictionary <string, string> { { "Message", exc.Message } }); }
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); } }
/// <summary> /// TryCatchfinally that throws from the catch that doesn’t catch /// </summary> /// Disabled and failed in desktop //[Fact] public void TryCatchFinallyWithExceptionInUncatchingCatch() { // try TestSequence trySeq = new TestSequence("Try"); trySeq.Activities.Add(new TestThrow <ArgumentException>("ThrowFromInner")); // catch TestCatch[] catches = new TestCatch[] { new TestCatch <ArgumentException>() { HintHandleException = true, Body = new TestWriteLine("Catch", "Catch") }, new TestCatch <UnauthorizedAccessException>() { HintHandleException = false, Body = new TestThrow <UnauthorizedAccessException>("Throw from uncalled catch") } }; // finally TestWriteLine finalWrite = new TestWriteLine("Final", "Final"); // Run test TestRuntime.RunAndValidateWorkflow (CreateTryCatchFinally(trySeq, catches, finalWrite, WFType.SEQ, false)); }
/// <summary> /// Simple tcf scenario in a sequential wf. Exception is thrown then caught. /// </summary> /// Disabled and failed in desktop //[Fact] public void SimpleTryCatchSequential() { // try TestSequence trySeq = new TestSequence(); trySeq.Activities.Add(new TestWriteLine("Try", "Try")); trySeq.Activities.Add(new TestThrow <ArgumentException>()); // catch TestCatch[] catches = new TestCatch[] { new TestCatch <ArgumentException>() { HintHandleException = true, Body = new TestWriteLine("Catch", "Catch") } }; // finally TestSequence finalSeq = new TestSequence(); finalSeq.Activities.Add(new TestWriteLine("Final", "Final")); // Run test TestRuntime.RunAndValidateWorkflow (CreateTryCatchFinally(trySeq, catches, finalSeq, WFType.SEQ, false)); }
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 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); }
public void EmptyTry() { // catch TestCatch <Exception> testcatch1 = new TestCatch <Exception>(); TestCatch <MemberAccessException> testcatch2 = new TestCatch <MemberAccessException>(); TestCatch[] catches = new TestCatch[] { testcatch1, testcatch2 }; // finally TestSequence finalSeq = new TestSequence(); finalSeq.Activities.Add(new TestWriteLine("Final", "Final")); // Run test TestRuntime.RunAndValidateWorkflow( CreateTryCatchFinally(null, catches, finalSeq, WFType.SEQ, false)); }
/// <summary> /// Exception is thrown in try and caught. /// Exception is thrown in try and caught. Catch contains a base of thrown child exception. /// </summary> /// Disabled and failed in desktop //[Fact] public void InheritedExceptions2() { // try TestSequence trySeq = new TestSequence(); trySeq.Activities.Add(new TestWriteLine("Try", "Try")); trySeq.Activities.Add(new TestThrow <ArgumentException>("TestThrow1")); // catch TestCatch[] catches = new TestCatch[] { new TestCatch <Exception>() }; catches[0].HintHandleException = true; // create and run TestActivity act = CreateTryCatchFinally(trySeq, catches, null, WFType.SEQ, true); TestRuntime.RunAndValidateWorkflow(act); }
public void CatchBothUnhandledExceptionHandlerAndInCatch() { // try // Throws a handled exception, then a caught exception TestSequence trySeq = new TestSequence("Try") { Activities = { new TestThrow <FormatException>("ThrowFormat") { ExceptionExpression = (context => new FormatException(CustomUtility.CustomMessage)), ExpectedOutcome = Outcome.HandledException(), }, }, ExpectedOutcome = Outcome.Canceled }; // catch // Should not catch anything TestCatch[] catches = new TestCatch[] { new TestCatch <ArgumentException>() { } }; // finally // Just confirm it executed TestWriteLine finalSeq = new TestWriteLine("Final", "Final"); // Run test TestActivity act = CreateTryCatchFinally(trySeq, catches, finalSeq, WFType.SEQ, false); // Run and validate trace using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(act)) { // Add the unhandled handler runtime.WorkflowRuntimeAdapterType = typeof(AddHandleExceptionRuntimeAdapter); runtime.ExecuteWorkflow(); runtime.GetWatcher().WaitForWorkflowCanceled(); } }
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 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 UncaughtExceptionFlowchart() { // exception which is raised ArithmeticException exc = new ArithmeticException(); // try TestThrow <ArithmeticException> tt = new TestThrow <ArithmeticException>("Test Throw") { ExceptionExpression = (context => new ArithmeticException()) }; // catch TestCatch[] catches = new TestCatch[] { new TestCatch <FileNotFoundException>(), new TestCatch <ArgumentException>(), new TestCatch <ArgumentOutOfRangeException>() }; // finally TestSequence finallySeq = new TestSequence("Finally"); // create and run TestActivity act = CreateTryCatchFinally(tt, catches, finallySeq, WFType.FLOW, true); TestRuntime.RunAndValidateAbortedException(act, exc.GetType(), null); }
/// <summary> /// Simple tcf scenario in a flowchart wf. Exception is thrown then caught. /// </summary> /// Disabled and failed in desktop //[Fact] public void SimpleTryCatchFlowchart() { // try TestSequence trySeq = new TestSequence(); trySeq.Activities.Add(new TestWriteLine("Try", "Try")); trySeq.Activities.Add(new TestThrow <ArgumentException>()); trySeq.Activities.Add(new TestWriteLine("NotCalled", "NotCalled")); // catch TestCatch[] catches = new TestCatch[] { new TestCatch <ArgumentException>() }; catches[0].HintHandleException = true; catches[0].Body = new TestWriteLine("Catch", "Catch"); // finally TestSequence finalSeq = new TestSequence(); finalSeq.Activities.Add(new TestWriteLine("Final", "Final")); TestRuntime.RunAndValidateWorkflow (CreateTryCatchFinally(trySeq, catches, finalSeq, WFType.FLOW, false)); }