コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
    private static int Main()
    {
#if !MULTIMODULE_BUILD
        TestLdstr.Run();
        TestException.Run();
        TestThreadStaticNotInitialized.Run();
        TestUntouchedThreadStaticInitialized.Run();
        TestPointers.Run();
        TestConstants.Run();
        TestArray.Run();
        TestMdArray.Run();
        TestSimpleObject.Run();
        TestFinalizableObject.Run();
        TestStoreIntoOtherStatic.Run();
        TestCctorCycle.Run();
        TestReferenceTypeAllocation.Run();
        TestReferenceTypeWithGCPointerAllocation.Run();
        TestRelationalOperators.Run();
        TestTryFinally.Run();
        TestTryCatch.Run();
        TestBadClass.Run();
        TestRefs.Run();
        TestDelegate.Run();
        TestInitFromOtherClass.Run();
        TestInitFromOtherClassDouble.Run();
        TestDelegateToOtherClass.Run();
#else
        Console.WriteLine("Preinitialization is disabled in multimodule builds for now. Skipping test.");
#endif

        return(100);
    }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void RethrowInTry()
        {
            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")),
                        },
                        tr
                    }
                },
                Catches =
                {
                    new TestCatch <TAC.ApplicationException>
                    {
                        Body = new TestRethrow()
                    }
                },
            };

            TestRuntime.ValidateInstantiationException(root, string.Format(ErrorStrings.RethrowNotInATryCatch, tr.DisplayName));
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        /// <summary>
        /// Setup a t/c/f statement.
        /// </summary>
        /// <param name="tryBody">Try activity.</param>
        /// <param name="tc">Array of Catches.</param>
        /// <param name="finallyBody">Finally activity.</param>
        /// <param name="type">Type of workflow to create.</param>
        /// <param name="otherActivities">Flag indicating whether extra activities should be added.</param>
        public static TestActivity CreateTryCatchFinally(TestActivity tryBody, TestCatch[] tc,
                                                         TestActivity finallyBody, WFType type, bool otherActivities)
        {
            // create the try/catch/finally
            TestTryCatch tcf = new TestTryCatch("TestTcf");

            if (tryBody != null)
            {
                tcf.Try = tryBody;
            }
            if (tc != null)
            {
                foreach (TestCatch testCatch in tc)
                {
                    tcf.Catches.Add(testCatch);
                }
            }
            if (finallyBody != null)
            {
                tcf.Finally = finallyBody;
            }

            // extra activities to add around activity if otherActivities is true
            TestWriteLine before = new TestWriteLine("BeforeTry", "BeforeTry");
            TestWriteLine after  = new TestWriteLine("AfterTry", "AfterTry");

            // sequence
            if (type == WFType.SEQ)
            {
                TestSequence seq = new TestSequence("SequenceOfActivitiesContainingTCF");
                if (otherActivities)
                {
                    seq.Activities.Add(before);
                }
                seq.Activities.Add(tcf);
                if (otherActivities)
                {
                    seq.Activities.Add(after);
                }
                return(seq);
            }

            // otherwise do flowchart
            else // type == wfType.FLOW
            {
                TestFlowchart flowchart = new TestFlowchart("FlowchartContainingTCF");
                if (otherActivities)
                {
                    flowchart.AddStartLink(before);
                    flowchart.AddLink(before, tcf);
                    flowchart.AddLink(tcf, after);
                }
                else
                {
                    flowchart.AddStartLink(tcf);
                }
                return(flowchart);
            }
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
        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;
                }
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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();
            }
        }
コード例 #21
0
        public void CancelInTryBlock()
        {
            TestBlockingActivity blocking = new TestBlockingActivity("Bookmark")
            {
                ExpectedOutcome = Outcome.Canceled
            };

            TestTryCatch tryCatch = new TestTryCatch("TryCatchTest")
            {
                Try = new TestSequence("TrySeq")
                {
                    Activities =
                    {
                        blocking,
                        new TestThrow <ArgumentException>("TryException")
                        {
                            ExpectedOutcome = Outcome.None
                        },
                    },
                },

                Catches =
                {
                    new TestCatch <ArgumentException>()
                    {
                        Body            = new TestWriteLine("Caught", "Caught"),
                        ExpectedOutcome = Outcome.None
                    }
                }
            };

            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tryCatch))
            {
                testWorkflowRuntime.ExecuteWorkflow();

                testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing);

                testWorkflowRuntime.CancelWorkflow();

                testWorkflowRuntime.WaitForCanceled();
            }
        }
コード例 #22
0
        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);
        }
コード例 #23
0
    private static int Main()
    {
#if !MULTIMODULE_BUILD
        TestLdstr.Run();
        TestException.Run();
        TestThreadStaticNotInitialized.Run();
        TestUntouchedThreadStaticInitialized.Run();
        TestPointers.Run();
        TestConstants.Run();
        TestArray.Run();
        TestArrayOutOfRange.Run();
        TestMdArray.Run();
        TestSimpleObject.Run();
        TestFinalizableObject.Run();
        TestStoreIntoOtherStatic.Run();
        TestCctorCycle.Run();
        TestReferenceTypeAllocation.Run();
        TestReferenceTypeWithGCPointerAllocation.Run();
        TestReferenceTypeWithReadonlyNullGCPointerAllocation.Run();
        TestRelationalOperators.Run();
        TestTryFinally.Run();
        TestTryCatch.Run();
        TestBadClass.Run();
        TestRefs.Run();
        TestDelegate.Run();
        TestInitFromOtherClass.Run();
        TestInitFromOtherClassDouble.Run();
        TestDelegateToOtherClass.Run();
        TestLotsOfBackwardsBranches.Run();
        TestDrawCircle.Run();
        TestValueTypeDup.Run();
        TestFunctionPointers.Run();
        TestGCInteraction.Run();
        TestDuplicatedFields.Run();
        TestInstanceDelegate.Run();
#else
        Console.WriteLine("Preinitialization is disabled in multimodule builds for now. Skipping test.");
#endif

        return(100);
    }
コード例 #24
0
        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);
        }
コード例 #25
0
        public void TerminateActivityInTry()
        {
            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 TestTerminateWorkflow()
                        {
                            ExceptionExpression = ((env) => 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!"
                        }
                    }
                },
            };

            RunTestWithWorkflowRuntime(tryCatch);
        }
コード例 #26
0
        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));
        }
コード例 #27
0
        /// <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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        /// <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);
        }