public void WhenSendStubInvokedSimulatesCommunicationException()
        {
            // Arrange
            var xamlInjector = new XamlInjector(Constants.ActivityWithSendCatchCommExceptionXaml);
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            var sut = xamlInjector.GetActivity();
            var host = new WorkflowInvokerTest(sut);

            var stubExtension = new MessagingStubExtension();

            // Add an implementation that will simulate a bad URI for the activity
            // Note: If the DisplayName is not set, the name will be the name of the SendStub activity
            stubExtension.SetImplementation("SendStub", () => { throw new EndpointNotFoundException(); });
            host.Extensions.Add(stubExtension);

            try
            {
                // Act
                host.TestActivity();

                // Assert
                // Shows that the SendStub activity was used
                host.Tracking.Assert.Exists("SendStub", ActivityInstanceState.Executing);
                host.Tracking.Assert.DoesNotExist("Send", ActivityInstanceState.Closed);
                host.AssertOutArgument.IsTrue("CatchHandled");
                host.AssertOutArgument.IsInstanceOfType("CaughtException", typeof(EndpointNotFoundException));
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
Example #2
0
        public void CanSimulateSendFailure()
        {
            // Arrange
            var xamlInjector = new XamlInjector(@"MockingMessagingActivities\ServiceWithSend.xamlx");

            // Setup the XamlInjector to replace the receive / send activities
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            xamlInjector.ReplaceAll(typeof(ReceiveReply), typeof(ReceiveReplyStub));

            // Access the workflow service Body activity for testing with WorkflowInvoker
            var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);

            // Setup the extension
            var stubExtension = new MessagingStubExtension();

            // The first receive will start the process
            stubExtension.EnqueueReceive(this.serviceContractName, "GetData", 123);

            // The first send will result in an exception
            stubExtension.SetImplementation("Send Primary", () => { throw new EndpointNotFoundException(); });

            // The second send should succeed
            // The next receive reply should simulate data from the backup service
            stubExtension.EnqueueReceiveReply(this.serviceContractName, "GetData", BackupResponse);
            host.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // Assert
                // The final reply is "Backup 123"
                Assert.AreEqual(BackupResponse, stubExtension.Messages[4].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }