private void RunTestWithWorkflowRuntime(TestActivity activity)
        {
            using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(activity))
            {
                testWorkflowRuntime.OnWorkflowCompleted += new EventHandler <TestWorkflowCompletedEventArgs>(workflowInstance_Completed);
                testWorkflowRuntime.ExecuteWorkflow();

                WorkflowTrackingWatcher watcher = testWorkflowRuntime.GetWatcher();
                OrderedTraces           orderedExpectedTrace = new OrderedTraces
                {
                    Steps =
                    {
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Started),
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Terminated),
                        new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Deleted)
                        {
                            Optional = true
                        }
                    }
                };

                ExpectedTrace expectedWorkflowInstacneTrace = new ExpectedTrace(orderedExpectedTrace);

                Exception exp = new Exception();
                testWorkflowRuntime.WaitForTerminated(1, out exp, watcher.ExpectedTraces, expectedWorkflowInstacneTrace);
            }
        }
Example #2
0
        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();
            }
        }
        private void WaitForTerminationHelper(TestWorkflowRuntime testWorkflowRuntime)
        {
            WorkflowTrackingWatcher watcher = testWorkflowRuntime.GetWatcher();
            OrderedTraces           orderedExpectedTrace = new OrderedTraces
            {
                Steps =
                {
                    new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Started),
                    new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Terminated),
                    new WorkflowInstanceTrace(testWorkflowRuntime.CurrentWorkflowInstanceId, WorkflowInstanceState.Deleted)
                    {
                        Optional = true
                    }
                }
            };

            ExpectedTrace expectedWorkflowInstacneTrace = new ExpectedTrace(orderedExpectedTrace);

            Exception exp = new Exception();

            testWorkflowRuntime.WaitForTerminated(1, out exp, watcher.ExpectedTraces, expectedWorkflowInstacneTrace);
        }