public void AbortedEventShouldRemainSignaled()
        {
            var expectedException = new InvalidWorkflowException(this.TestContext.TestName);

            var inputs = new Dictionary<string, object> { { "AbortException", expectedException } };

            var host = WorkflowApplicationTest.Create(new ActivityThatAborts(), inputs);

            // Act
            host.TestActivity();

            // Wait for the real aborted event
            Assert.IsTrue(host.WaitForAbortedEvent());

            // Should not block because AbortedEvent remains signaled
            Assert.IsTrue(host.WaitForAbortedEvent());
        }
        public void ShouldInvokeUnhandledExceptionDelegate()
        {
            var expectedException = new InvalidWorkflowException(this.TestContext.TestName);

            var inputs = new Dictionary<string, object> { { "Exception", expectedException } };
            WorkflowApplicationUnhandledExceptionEventArgs unhandledExceptionEventArgs = null;

            var host = WorkflowApplicationTest.Create(new Throw(), inputs);

            host.OnUnhandledException = (args) =>
                {
                    unhandledExceptionEventArgs = args;
                    return UnhandledExceptionAction.Terminate;
                };

            // Act
            host.TestActivity();

            Assert.IsTrue(host.WaitForUnhandledExceptionEvent());
            Assert.IsNotNull(unhandledExceptionEventArgs);
        }
        public void ShouldCaptureAbortedArgsWhenActivityAborts()
        {
            var expectedException = new InvalidWorkflowException(this.TestContext.TestName);

            var inputs = new Dictionary<string, object> { { "AbortException", expectedException } };

            var host = WorkflowApplicationTest.Create(new ActivityThatAborts(), inputs);

            // Act
            host.TestActivity();

            Assert.IsTrue(host.WaitForAbortedEvent());

            Assert.IsNotNull(host.Results.AbortedArgs);
            Assert.IsInstanceOfType(host.Results.AbortedArgs.Reason, expectedException.GetType());
            Assert.AreSame(expectedException, host.Results.AbortedArgs.Reason);
        }
        public void ShouldInvokeAbortedDelegateWhenActivityAborts()
        {
            var expectedException = new InvalidWorkflowException(this.TestContext.TestName);

            var inputs = new Dictionary<string, object> { { "AbortException", expectedException } };
            WorkflowApplicationAbortedEventArgs abortArgs = null;

            var host = WorkflowApplicationTest.Create(new ActivityThatAborts(), inputs);

            host.Aborted = (args) => abortArgs = args;

            // Act
            host.TestActivity();

            Assert.IsTrue(host.WaitForAbortedEvent());
            Assert.IsNotNull(abortArgs);
        }
        internal static bool TryWrapSupportedVersionException(string filePath, Exception e, out Exception newException)
        {
            // We replace the exception, rather than simply wrapping it, because the activation error page highlights 
            // the innermost exception, and we want that  exception to clearly show which file is the culprit.
            // Of course, if the exception has an inner exception, that will still get highlighted instead.
            // Also, for Xaml and XmlException, we don't propagate the line info, because the exception message already contains it.
            if (e is XmlException)
            {
                newException = new XmlException(SR.ExceptionLoadingSupportedVersion(filePath, e.Message), e.InnerException);
                return true;
            }

            if (e is XamlException)
            {
                newException = new XamlException(SR.ExceptionLoadingSupportedVersion(filePath, e.Message), e.InnerException);
                return true;
            }

            if (e is InvalidWorkflowException)
            {
                newException = new InvalidWorkflowException(SR.ExceptionLoadingSupportedVersion(filePath, e.Message), e.InnerException);
                return true;
            }

            if (e is ValidationException)
            {
                newException = new ValidationException(SR.ExceptionLoadingSupportedVersion(filePath, e.Message), e.InnerException);
                return true;
            }

            newException = null;
            return false;
        }