public void ThrowExceptionInElseBody() { // Test case description: // 2 bracnhes:throw exception in the condition throw exception in if body, else executingthrow exception // in else body if executingthrow exception in both branches if executingthrow exception in both branches // else executing TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("inner seq"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; TestIf ifAct = new TestIf("if act", HintThenOrElse.Else) { ConditionExpression = ((env) => ((int)counter.Get(env)) > 10), ThenActivity = new TestSequence("sequence in if"), ElseActivity = innerSequence }; TestThrow <ArithmeticException> throwArt = new TestThrow <ArithmeticException>("throw"); innerSequence.Activities.Add(throwArt); outerSequence.Activities.Add(ifAct); innerSequence.Activities.Add(writeLine); outerSequence.Variables.Add(counter); TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>()); }
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 ThrowFromNode() { TestFlowchart flowchart = new TestFlowchart(); Variable <int> expression = new Variable <int> { Name = "expression", Default = 3 }; flowchart.Variables.Add(expression); TestWriteLine w1 = new TestWriteLine("One", "One wont execute"); TestWriteLine w2 = new TestWriteLine("Two", "Two will execute"); TestThrow <Exception> throwAct = new TestThrow <Exception>(); Dictionary <int, TestActivity> cases = new Dictionary <int, TestActivity>(); cases.Add(1, w1); cases.Add(2, w2); cases.Add(3, throwAct); List <int> hints = new List <int>(); hints.Add(2); flowchart.AddSwitchLink <int>(new TestWriteLine("Start", "Flowchart started"), cases, hints, expression, new TestWriteLine("Default", "Default")); TestRuntime.RunAndValidateAbortedException(flowchart, typeof(Exception), null); }
public void ThrowCustomException() { TestThrow <CustomException> th = new TestThrow <CustomException>("custom exception") { ExceptionExpression = (context => new CustomException("Invalid department")) }; TestRuntime.RunAndValidateAbortedException(th, typeof(CustomException), new Dictionary <string, string>()); }
public void TryCatchFinallyWithExceptionInFinally() { // Uncaught Exception ArithmeticException exc = new ArithmeticException(); // finally TestThrow <ArithmeticException> tt = new TestThrow <ArithmeticException>("Test Throw") { ExceptionExpression = (context => new ArithmeticException()) }; // Run test TestActivity act = CreateTryCatchFinally(null, null, tt, WFType.SEQ, false); TestRuntime.RunAndValidateAbortedException(act, exc.GetType(), null); }
public void WhileInfiniteLoopFaultAfterHundredLoops() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestIncrement increment = new TestIncrement("test increment"); TestSequence inNestedSequence = new TestSequence("Sequence in Nested while"); TestThrow <ArithmeticException> throwTestActivity = new TestThrow <ArithmeticException>(); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 200), Body = innerSequence, HintIterationCount = 200, }; inNestedSequence.Activities.Add(whileAct); inNestedSequence.Activities.Add(throwTestActivity); TestWhile whileActNested = new TestWhile("while act") { ConditionExpression = ((env) => (true)), Body = inNestedSequence, HintIterationCount = 200, }; TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; increment.CounterVariable = counter; innerSequence.Activities.Add(writeLine); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileActNested); TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>()); }
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); }
public void WhileWithException() { TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("Seq"); TestIncrement increment = new TestIncrement("test increment"); TestThrow <ArithmeticException> throwArt = new TestThrow <ArithmeticException>("throw"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 10), Body = innerSequence, HintIterationCount = 10, }; increment.CounterVariable = counter; innerSequence.Activities.Add(throwArt); innerSequence.Activities.Add(increment); outerSequence.Variables.Add(counter); outerSequence.Activities.Add(whileAct); TestRuntime.RunAndValidateAbortedException(outerSequence, typeof(ArithmeticException), new Dictionary <string, string>()); }
public void ThrowException() { TestThrow <InvalidDataException> throwAct = new TestThrow <InvalidDataException>("Throw Invalid data"); TestRuntime.RunAndValidateAbortedException(throwAct, typeof(InvalidDataException), new Dictionary <string, string>()); }