public void CanMockReceiveAndSendReply() { // Arrange const int Expected = 123; var xamlInjector = new XamlInjector(MockingMessagingActivities + "\\" + Service1Xamlx); // Setup the XamlInjector to replace the receive / send activities xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); // Access the workflow service Body activity for testing with WorkflowInvoker var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body); // Setup the extension var stubExtension = new MessagingStubExtension(); stubExtension.EnqueueReceive(this.serviceContractName, "GetData", Expected); host.Extensions.Add(stubExtension); try { host.TestActivity(); // The reply should be "123" Assert.AreEqual(Expected.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Content); } finally { Trace.WriteLine("*** Messaging Stub Dump"); stubExtension.Trace(); Trace.WriteLine("\r\n*** Workflow Tracking Records"); host.Tracking.Trace(); } }
public void CanImplementMessagingProtocol() { // Arrange const int Expected = 123; const int Increment = 3; var xamlInjector = new XamlInjector(Constants.ServicewithtworeceivesandincrementXamlx); // Setup the XamlInjector to replace the receive / send activities xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); // Access the workflow service Body activity for testing with WorkflowInvoker var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body); // Setup the extension var stubExtension = new MessagingStubExtension(); host.Extensions.Add(stubExtension); stubExtension.EnqueueReceive(this.serviceContractName, "GetData", Expected); stubExtension.OnIdle = s => { // If processing the reply to the initial message if (s.Messages.Count == 2 && s.QueueCount == 0) { // Access the content and add the increment s.EnqueueReceive( this.serviceContractName, "IncrementData", ((int)s.Messages[1].Content) + Increment); } }; try { // Act host.TestActivity(); // Assert Assert.AreEqual(Expected + Expected + Increment, stubExtension.Messages[3].Content); Assert.AreEqual(0, stubExtension.QueueCount); } 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 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 CanSendToAnyParallelBranch() { var xamlInjector = new XamlInjector(Constants.ServiceWithParallelThreeReceivesXamlx); xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); var host = new WorkflowInvokerTest(xamlInjector.GetWorkflowService().Body); var stubExtension = new MessagingStubExtension(); host.Invoker.Extensions.Add(stubExtension); stubExtension.EnqueueReceive(this.serviceContractName, "GetData3", 3); stubExtension.EnqueueReceive(this.serviceContractName, "GetData1", 1); stubExtension.EnqueueReceive(this.serviceContractName, "GetData2", 2); try { host.TestActivity(); Assert.AreEqual(6, stubExtension.Messages.Count); Assert.AreEqual("3", stubExtension.Messages[1].Content); Assert.AreEqual("1", stubExtension.Messages[3].Content); Assert.AreEqual("2", stubExtension.Messages[5].Content); } finally { Trace.WriteLine("*** Messaging Stub Dump"); stubExtension.Trace(); Trace.WriteLine("\r\n*** Workflow Tracking Records"); host.Tracking.Trace(); } }
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(); } }
public void CanMockTwoReceiveAndSendReplyWithParameters() { // Arrange var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service2Parameters.xamlx"); // Setup the XamlInjector to replace the receive / send activities xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); // Access the workflow service Body activity for testing with WorkflowInvoker var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body); // Setup the extension var stubExtension = new MessagingStubExtension(); // Setup the first message dynamic parameterValues1 = new WorkflowArguments(); parameterValues1.value1 = 5; parameterValues1.value2 = 4; stubExtension.EnqueueReceive(this.serviceContractName, "GetData", parameterValues1); // Setup the second message dynamic parameterValues2 = new WorkflowArguments(); parameterValues2.value1 = 6; parameterValues2.value2 = 3; stubExtension.EnqueueReceive(this.serviceContractName, "GetData2", parameterValues2); host.Extensions.Add(stubExtension); try { host.TestActivity(); // Assert // The first reply parameter "data1" is "5" Assert.AreEqual("5", stubExtension.Messages[1].Parameter("data1")); // The first reply parameter "data1" is "4" Assert.AreEqual("4", stubExtension.Messages[1].Parameter("data2")); // The second reply parameter "data1" is "7" Assert.AreEqual("7", stubExtension.Messages[3].Parameter("data1")); // The second reply parameter "data1" is "5" Assert.AreEqual("5", stubExtension.Messages[3].Parameter("data2")); } finally { Trace.WriteLine("*** Messaging Stub Dump"); stubExtension.Trace(); Trace.WriteLine("\r\n*** Workflow Tracking Records"); host.Tracking.Trace(); } }
public void CanMockTwoReceiveAndSendReply() { // Arrange var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service2.xamlx"); // Setup the XamlInjector to replace the receive / send activities xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); // Access the workflow service Body activity for testing with WorkflowInvoker var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body); // Setup the extension var stubExtension = new MessagingStubExtension(); stubExtension.EnqueueReceive(this.serviceContractName, "GetData", 5); stubExtension.EnqueueReceive(this.serviceContractName, "GetData2", 6); host.Extensions.Add(stubExtension); try { host.TestActivity(); // Assert // The first reply is "5" Assert.AreEqual("5", stubExtension.Messages[1].Content); // The second reply is "8" Assert.AreEqual("8", stubExtension.Messages[3].Content); } finally { Trace.WriteLine("*** Messaging Stub Dump"); stubExtension.Trace(); Trace.WriteLine("\r\n*** Workflow Tracking Records"); host.Tracking.Trace(); } }
public void CanMockReceiveAndSendReplyWithParameters() { // Arrange const int Value1 = 123; const int Value2 = 456; var xamlInjector = new XamlInjector(@"MockingMessagingActivities\Service1Parameters.xamlx"); // Setup the XamlInjector to replace the receive / send activities xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub)); xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub)); // Access the workflow service Body activity for testing with WorkflowInvoker var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body); // Setup the extension dynamic arguments = new WorkflowArguments(); arguments.value1 = Value1; arguments.value2 = Value2; var stubExtension = new MessagingStubExtension(); stubExtension.EnqueueReceive(this.serviceContractName, "GetData", arguments); host.Extensions.Add(stubExtension); try { host.TestActivity(); // The first reply message parameter data1 should be "123" Assert.AreEqual(Value1.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Parameter("data1")); // The first reply message parameter data2 should be "456" Assert.AreEqual(Value2.ToString(CultureInfo.InvariantCulture), stubExtension.Messages[1].Parameter("data2")); } finally { Trace.WriteLine("*** Messaging Stub Dump"); stubExtension.Trace(); Trace.WriteLine("\r\n*** Workflow Tracking Records"); host.Tracking.Trace(); } }