public void TestReceiveSmallMessage_XML() { //Setting up the ILogger moq var loggerMock = TestMockReceiveStep.CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockRequestResponseStep step = new MockRequestResponseStep(); step.Url = connectionUri.Uri.OriginalString; step.Encoding = "UTF-8"; step.ResponsePath = "TestResponse.xml"; step.Timeout = 30; //Calling Validate in order to start the server 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 System.Threading.ThreadPool.QueueUserWorkItem((state) => { step.Execute(context); manualEvent.Set(); }); string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8); msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true); Message responseMsg = outboundHandler.Execute(msg, TimeSpan.FromSeconds(10)); //Waiting for the manual event to be set manualEvent.WaitOne(1000); //string expected = ReadResponseFileContent("TestResponse.xml").Trim().Replace("\r\n", string.Empty).Replace("\t", string.Empty); //string actual = GeneralTestHelper.GetBodyAsString(responseMsg, Encoding.UTF8).Trim().Replace("\r\n", string.Empty).Replace("\t", string.Empty); //Assert.AreEqual(expected, actual, // "Response message is not matching the expected content"); loggerMock.Verify(l => l.LogData( It.Is <string>(s => !string.IsNullOrEmpty(s)), It.Is <string>(s => !string.IsNullOrEmpty(s))), Times.Exactly(2), "The LogData method was not called"); }
public void TestReceiveSmallMessage_XML() { //Setting up the ILogger moq var loggerMock = CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockReceiveStep step = new MockReceiveStep(); step.Url = connectionUri.Uri.OriginalString; step.Encoding = "UTF-8"; step.Timeout = 30; //Colling Validate in order to start the 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 System.Threading.ThreadPool.QueueUserWorkItem((state) => { step.Execute(context); manualEvent.Set(); }); string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8); outboundHandler.Execute(msg, TimeSpan.FromSeconds(10)); //Waiting for the manual event to be set manualEvent.WaitOne(1000); 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 TestSendOneWay_XML() { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( connectionUri.Uri.AbsolutePath, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8); OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnected(cb), testHelper); outboundHandler.Execute(msg, new TimeSpan(0, 0, 10)); //Here we wait for the event to be signalled testHelper.syncEvent.WaitOne(60000); //The event was signalled, we get the message stirng from the outBuffer string receivedResponseXml = GeneralTestHelper.GetMessageFromArray(testHelper.memStream.ToArray(), (int)testHelper.memStream.Length, Encoding.UTF8); Assert.AreEqual(xml, receivedResponseXml, "Contents of received message is different"); } }