public void TestSendSmallMessage_XML() { //Setting up the ILogger moq var loggerMock = CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockSendStep step = new MockSendStep(); step.Url = connectionUri.Uri.OriginalString; step.RequestPath = "TestRequest.xml"; step.Encoding = "UTF-8"; step.Timeout = 30; //Validating the test step step.Validate(context); //Executing the step step.Execute(context); //Now we read the message in the inbound handler Message msg = null; IInboundReply reply; inboundHandler.TryReceive(TimeSpan.FromSeconds(10), out msg, out reply); Assert.IsNotNull(msg, "Message instance was not returned"); Assert.AreEqual(ReadRequestFileContent(step.RequestPath), GeneralTestHelper.GetBodyAsString(msg, Encoding.UTF8), "Message contents of received message is different"); loggerMock.Verify(l => l.LogData( It.Is <string>(s => !string.IsNullOrEmpty(s)), It.Is <string>(s => !string.IsNullOrEmpty(s))), Times.AtLeastOnce(), "The LogData message was not called"); }
public void TestSendSmallMessage_XML() { //Setting up the ILogger moq var loggerMock = CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockSolicitResponseStep step = new MockSolicitResponseStep(); step.Url = connectionUri.Uri.OriginalString; step.RequestPath = "TestRequest.xml"; step.Encoding = "UTF-8"; step.Timeout = 30; //Validating the test step step.Validate(context); //Setting up a manual reset event System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false); //here we queue up the step.Execute method in a separate thread as the execution model would actually be Message msg = null; IInboundReply reply; //Creating the reply message Message msgReply = GeneralTestHelper.CreateMessageWithBase64EncodedBody( ReadRequestFileContent("TestResponse.xml"), Encoding.UTF8); System.Threading.ThreadPool.QueueUserWorkItem((state) => { //Now we read the message in the inbound handler inboundHandler.TryReceive(TimeSpan.FromSeconds(10), out msg, out reply); reply.Reply(msgReply, TimeSpan.FromSeconds(10)); manualEvent.Set(); }); //Executing the step step.Execute(context); manualEvent.WaitOne(10000); Assert.IsNotNull(msg, "Message instance was not received"); string expectedRequest = ReadRequestFileContent(step.RequestPath); string actualRequest = GeneralTestHelper.GetBodyAsString(msg, Encoding.UTF8); Assert.AreEqual(expectedRequest, actualRequest, "Message contents of received message is different"); loggerMock.Verify(l => l.LogData( It.Is <string>(s => !string.IsNullOrEmpty(s)), It.Is <string>(s => !string.IsNullOrEmpty(s))), Times.AtLeastOnce(), "The LogData message was not called"); }
public void TestOneWayReceive_XML() { inboundHandler.StartListener(null, new TimeSpan(0, 0, 60)); string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", connectionUri.Uri.AbsolutePath, PipeDirection.InOut, PipeOptions.Asynchronous)) { byte[] xmlBytes = Encoding.UTF8.GetBytes(xml); pipeClient.Connect(10000); pipeClient.Write(xmlBytes, 0, xmlBytes.Count()); pipeClient.WaitForPipeDrain(); pipeClient.Close(); } //Now we read the message in the inbound handler Message msg = null; IInboundReply reply; inboundHandler.TryReceive(new TimeSpan(0, 0, 10), out msg, out reply); //Sending empty message to emulate the exact behavior of BizTalk for one way communication reply.Reply(GeneralTestHelper.CreateMessageWithEmptyBody(), TimeSpan.FromSeconds(10)); Assert.IsNotNull(msg, "Message instance was not returned"); Assert.AreEqual(xml, GeneralTestHelper.GetBodyAsString(msg, Encoding.UTF8), "Message contents of received message is different"); }