public void WhenSendWithNoContentStubInvoked()
        {
            var xamlInjector = new XamlInjector(Constants.ActivityWithSendXaml);
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            var sut = xamlInjector.GetActivity();
            var host = new WorkflowInvokerTest(sut);
            var stubExtension = new MessagingStubExtension();
            host.Invoker.Extensions.Add(stubExtension);
            try
            {
                host.TestActivity();

                // Shows that the SendStub activity was used
                host.Tracking.Assert.Exists("SendStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.DoesNotExist("Send", ActivityInstanceState.Closed);
                Assert.AreEqual(1, stubExtension.Messages.Count);
                Assert.AreEqual(1, stubExtension.Messages[0].Content);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        public void WhenSendWithParametersContentStubInvoked()
        {
            var xamlInjector = new XamlInjector(Constants.ActivityWithSendParametersContentXaml);
            xamlInjector.ReplaceAll(typeof(Send), typeof(SendStub));
            var sut = xamlInjector.GetActivity();
            var host = new WorkflowInvokerTest(sut);
            var stubExtension = new MessagingStubExtension();
            host.Invoker.Extensions.Add(stubExtension);

            try
            {
                host.TestActivity();

                // Shows that the SendStub activity was used
                host.Tracking.Assert.Exists("SendStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.DoesNotExist("Send", ActivityInstanceState.Closed);

                // There should be two send activities
                Assert.AreEqual(2, stubExtension.Messages.Count);

                // Verify the parameters content from the first send
                Assert.AreEqual(1, stubExtension.Messages[0].Parameter("num"));
                Assert.AreEqual("test1", stubExtension.Messages[0].Parameter("test"));

                // Verify the parameters content from the second send
                Assert.AreEqual(2, stubExtension.Messages[1].Parameter("num"));
                Assert.AreEqual("test2", stubExtension.Messages[1].Parameter("test"));
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        public void StubCorrelationActivities()
        {
            // Arrange
            const int Expected = 12;
            var xamlInjector = new XamlInjector(Constants.ActivityWithReceiveAndSendReplyAndCorrXaml);
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));
            xamlInjector.ReplaceAll(typeof(InitializeCorrelation), typeof(InitializeCorrelationStub));
            var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

            var stubExtension = new MessagingStubExtension();
            stubExtension.EnqueueReceive(
                this.serviceContractName, "Sum", new Dictionary<string, object> { { "x", 5 }, { "y", 7 } });
            host.Extensions.Add(stubExtension);

            try
            {
                // Act
                host.TestActivity();

                // Assert
                host.Tracking.Assert.Exists("ReceiveStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.Exists("SendReplyToReceive", ActivityInstanceState.Closed);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Idle);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Completed);
                host.AssertOutArgument.AreEqual("sum", Expected);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        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();
            }
        }
        public void ReceiveStubShouldGoIdleWithBookmark()
        {
            // Arrange
            var xamlInjector = new XamlInjector(Constants.ActivityWithReceiveXaml);
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            var host = WorkflowApplicationTest.Create(xamlInjector.GetActivity());
            var stubExtension = new MessagingStubExtension();
            host.Extensions.Add(stubExtension);

            try
            {
                // Act
                // Run until idle with this bookmark
                host.TestWorkflowApplication.RunEpisode("{http://tempuri.org/}IService|Sum");

                // Assert
                host.Tracking.Assert.Exists("ReceiveStub", ActivityInstanceState.Executing);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Idle);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        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();
            }
        }
        public void MessagingStubImplementationShouldSupplyMessageResults()
        {
            // Arrange
            const int Expected = 12;
            var xamlInjector = new XamlInjector(Constants.ActivityWithReceiveMessageXaml);
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

            var stubExtension = new MessagingStubExtension();
            stubExtension.EnqueueReceive(this.serviceContractName, "Sum", 5);
            host.Extensions.Add(stubExtension);

            try
            {
                // Act
                host.TestActivity();

                // Assert
                host.Tracking.Assert.Exists("ReceiveStub", ActivityInstanceState.Closed);
                host.Tracking.Assert.Exists(WorkflowInstanceRecordState.Idle);
                host.AssertOutArgument.AreEqual("sum", Expected);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        public void CustomStubShouldBeInvoked()
        {
            // Arrange
            var xamlInjector = new XamlInjector(Constants.ActivityWithTwoReceivesXaml);
            xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
            var sut = xamlInjector.GetActivity();
            var host = WorkflowInvokerTest.Create(sut);
            var stubExtension = new TestMessagingStubExtensionImplementation();
            host.Extensions.Add(stubExtension);
            stubExtension.EnqueueReceive(this.serviceContractName, "Operation1", null);
            stubExtension.EnqueueReceive(this.serviceContractName, "Operation2", null);

            try
            {
                // Act
                host.TestActivity();

                // Assert
                Assert.IsTrue(stubExtension.Operation1Invoked);
                Assert.IsTrue(stubExtension.Operation2Invoked);
            }
            finally
            {
                Trace.WriteLine("*** Messaging Stub Dump");
                stubExtension.Trace();

                Trace.WriteLine("\r\n*** Workflow Tracking Records");
                host.Tracking.Trace();
            }
        }
        /// <summary>
        /// The verify injection.
        /// </summary>
        /// <param name="xamlInjector">
        /// The xaml injector. 
        /// </param>
        private void VerifyInjection(XamlInjector xamlInjector)
        {
            // The first TestActivity1 will not be replaced - will add 1 to sum

            // Replace the second TestActivity1 with TestActivity2 - will add 2 to sum
            xamlInjector.ReplaceAt(1, typeof(TestActivity1), typeof(TestActivity2));

            // Replace third TestActivity1 with TestActivity3 - will add 3 to sum
            xamlInjector.ReplaceAt(2, typeof(TestActivity1), typeof(TestActivity3));

            // Replace all (2) TestActivity4 with TestActivity5 - will add 10 to sum
            xamlInjector.ReplaceAll(typeof(TestActivity4), typeof(TestActivity5));

            // Debug.WriteLine(string.Format("Invoking Injected XAML activity {0}", activity.GetType()));
            var host = new WorkflowInvokerTest(xamlInjector.GetActivity());

            try
            {
                // Act
                host.TestActivity();

                // Total should be 1+2+3+10=16
                host.AssertOutArgument.AreEqual("sum", 16);
            }
            finally
            {
                host.Tracking.Trace();
            }
        }
Esempio n. 10
0
 public void WhenGetActivityIsCalledTwiceSameActivityIsReturned()
 {
     var injector = new XamlInjector("TestInject.xaml");
     Assert.AreSame(injector.GetActivity(), injector.GetActivity());
 }
Esempio n. 11
0
        public void ShouldReplaceWriteLineActivity()
        {
            // Arrange
            var xamlInjector = new XamlInjector("TestInjectWriteLine.xaml", typeof(TestActivity1).Assembly);

            xamlInjector.ReplaceAll(typeof(TestActivity1), typeof(TestActivity2));

            xamlInjector.ReplaceAll(typeof(WriteLine), typeof(MockWriteLine));
            var activity = xamlInjector.GetActivity();

            var invokerTest = new WorkflowInvokerTest(activity);

            try
            {
                // Act
                invokerTest.TestActivity();

                // Assert
                invokerTest.Tracking.Assert.Exists("MockWriteLine", ActivityInstanceState.Closed);
            }
            finally
            {
                invokerTest.Tracking.Trace();
            }
        }