예제 #1
0
        public void SendAndReceiveReplyStubMessageImplementationShouldSetSum()
        {
            // Arrange
            const int Expected = 12;
            var xamlInjector = new XamlInjector(Constants.ActivityWithSendAndReceiveReplyXaml);

            // Replace the messaging activities with stubs
            xamlInjector.ReplaceAll(typeof(ReceiveReply), typeof(ReceiveReplyStub));
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));

            var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

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

            // For the reply use the name of the contract / operation from the matching Send activity
            stubExtension.EnqueueReceiveReply(
                this.serviceContractName, "Sum", new Dictionary<string, object> { { "SumResult", Expected } });
            host.Extensions.Add(stubExtension);

            try
            {
                // Act
                host.TestActivity(Constants.Timeout);

                // Assert
                host.Tracking.Assert.Exists("SendStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.Exists("ReceiveReplyForSend", ActivityInstanceState.Closed);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Idle);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Completed);
                host.AssertOutArgument.AreEqual("sum", Expected);

                Assert.AreEqual(2, stubExtension.Messages.Count);
                Assert.AreEqual(5, stubExtension.Messages[0].Parameter("x"));
                Assert.AreEqual(7, stubExtension.Messages[0].Parameter("y"));
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
예제 #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();
            }
        }