public void TestSendOneWay_XML_WithProperties_InvalidProperty() { 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); // Adding test properties AddPromotedProperty(msg, "http://schemas.microsoft.com/BizTalk/2003/zip-properties#Imaginary", "StillWorks"); 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 var mockMessage = ConvertToMockMessage(testHelper.memStream); Assert.AreEqual(xml, mockMessage.Body, "Contents of received message is different"); Assert.IsTrue(mockMessage.Properties.Count == 1, "Number of properties received from outbound adapter is wrong"); Assert.AreEqual("StillWorks", mockMessage.Properties["http://schemas.microsoft.com/BizTalk/2003/zip-properties#Imaginary"], "The promoted property is not as expected"); } }
public void TestSendOneWay_XML_Unicode() { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( connectionUri.Uri.AbsolutePath, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { adapter.Encoding = "Unicode"; string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.Unicode); 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 var mockMessage = ConvertToMockMessage(testHelper.memStream); Assert.AreEqual(xml, mockMessage.Body, "Contents of received message is different"); } }
public void TestSendTwoWay_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); //Setting up the BTS.IsSolicitResponse property msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true); OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); //We set the response message content testHelper.responseXml = "<SomeTestMessageResponse><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessageResponse>"; pipeServer.BeginWaitForConnection(cb => testHelper .ClientConnectedSyncronous(cb, ctx => SendResponse(ctx)), testHelper); Message responseMsg = outboundHandler.Execute(msg, new TimeSpan(0, 0, 10)); var mockMessage = ConvertToMockMessage(testHelper.memStream); Assert.AreEqual(mockMessage.Body, xml, "Contents of the request message is different"); Assert.AreEqual(testHelper.responseXml, GeneralTestHelper.GetBodyAsString(responseMsg, Encoding.UTF8), "Contents of the response message is different"); } }
public void TestSendTwoWay_XML_MediumMessage() { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( connectionUri.Uri.AbsolutePath, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody( File.ReadAllBytes("MediumMessage.xml")); //Setting up the BTS.IsSolicitResponse property msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true); OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); //We set the response message content testHelper.responsePath = "MediumMessage.xml"; pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnectedSyncronous(cb), testHelper); Message responseMsg = outboundHandler.Execute(msg, new TimeSpan(0, 0, 10)); //Calculating the hashes of the messages and the file byte[] responseMessageBytes = GeneralTestHelper.GetBodyAsBytes(responseMsg); string receivedMessageHash = GeneralTestHelper.CalculateBytesHash(testHelper.memStream.ToArray()); string responseMessageHash = GeneralTestHelper.CalculateBytesHash(responseMessageBytes); string fileHash = GeneralTestHelper.CalculateFileHash("MediumMessage.xml"); //Validating the results Assert.AreEqual(fileHash, receivedMessageHash, "Contents of the request message is different"); Assert.AreEqual(fileHash, responseMessageHash, "Contents of the response message is different"); } }
public void TestSendOneWay_FlatFile_ISO88591() { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( connectionUri.Uri.AbsolutePath, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { adapter.Encoding = "ISO-8859-1"; string ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(ffContent, Encoding.GetEncoding("ISO-8859-1")); 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 receivedResponse = GeneralTestHelper.GetMessageFromArray(testHelper.memStream.ToArray(), (int)testHelper.memStream.Length, Encoding.GetEncoding("ISO-8859-1")); Assert.AreEqual(ffContent, receivedResponse, "Contents of received message is different"); } }
public static void SendResponse(OutboundTestHelper testHelper) { // Sending a response if (!string.IsNullOrEmpty(testHelper.responseXml)) { var responseMessage = new MockMessage() { Body = testHelper.responseXml }; using (var msgStream = new MemoryStream(4096)) { var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(msgStream, responseMessage); msgStream.Seek(0, SeekOrigin.Begin); //We write the response content back and flush it down the drain. testHelper.pipeServer.Write(msgStream.ToArray(), 0, (int)msgStream.Length); } } else if (!string.IsNullOrEmpty(testHelper.responsePath)) { var responseMessage = new MockMessage(testHelper.responsePath, testHelper.responseEncoding); using (var msgStream = new MemoryStream(4096)) { var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(msgStream, responseMessage); msgStream.Seek(0, SeekOrigin.Begin); int byteCountRead = 0; byte[] outBuffer = new byte[4096]; //Streaming respoonse from file while ((byteCountRead = msgStream.Read(outBuffer, 0, outBuffer.Length)) > 0) { testHelper.pipeServer.Write(outBuffer, 0, byteCountRead); } } } else { throw new InvalidOperationException("There was no response content defined"); } // Writing the EndOfMessage sequence to the end of stream testHelper.pipeServer.Write( OutboundTestHelper.EndOfMessage, 0, OutboundTestHelper.EndOfMessage.Length); testHelper.pipeServer.Flush(); testHelper.pipeServer.WaitForPipeDrain(); }
public void TestOneWay_XML() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule( new PipeAccessRule( "USERS", PipeAccessRights.CreateNewInstance | PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); // We first spin a pipe server to make sure that the send port will be able to connect using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( "OneWaySend", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps)) { string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnected(cb), testHelper); //Here we spin the pipe client that will send the message to BizTalk using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", "OneWayReceive", PipeDirection.InOut, PipeOptions.Asynchronous)) { var mockMessage = new MockMessage(); mockMessage.Body = xml; using (var memStream = new MemoryStream()) { var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(memStream, mockMessage); pipeClient.Connect(10000); pipeClient.Write(memStream.ToArray(), 0, (int)memStream.Length); pipeClient.WriteByte(0x00); pipeClient.WaitForPipeDrain(); } } //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 var receivedMsg = TestUtils.ConvertToMockMessage(testHelper.memStream); Assert.AreEqual(xml, receivedMsg.Body, "Contents of the received message is different"); Assert.IsTrue(receivedMsg.Properties.Count > 1, "Received message does not contain properties"); Assert.IsTrue(receivedMsg.Properties.ContainsKey( "http://schemas.microsoft.com/BizTalk/2003/system-properties#BizTalkMessageID"), "Received message does not contain MessageID property"); } }
public void TestOneWay_XML() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule( new PipeAccessRule( "USERS", PipeAccessRights.CreateNewInstance | PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); // We first spin a pipe server to make sure that the send port will be able to connect using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( "OneWaySend", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps)) { string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnected(cb), testHelper); //Here we spin the pipe client that will send the message to BizTalk using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", "OneWayReceive", PipeDirection.InOut, PipeOptions.Asynchronous)) { byte[] xmlBytes = Encoding.UTF8.GetBytes(xml); pipeClient.Connect(10000); pipeClient.Write(xmlBytes, 0, xmlBytes.Count()); pipeClient.WriteByte(0x00);//writing the EOF byte pipeClient.Flush(); pipeClient.WaitForPipeDrain(); } //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 receivedXml = Encoding.UTF8.GetString(testHelper.memStream.ToArray(), 0, (int)testHelper.memStream.Length); Assert.AreEqual(xml, receivedXml, "Contents of the received message is different"); } }
public void TestOneWay_FlatFile() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule("USERS", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); //We first spin a pipe server to make sure that the send port will be able to connect using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( "OneWaySend", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps)) { string ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;"; OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnected(cb), testHelper); //Here we spin the pipe client that will send the message to BizTalk using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", "OneWayReceive", PipeDirection.InOut, PipeOptions.Asynchronous)) { var mockMessage = new MockMessage(); mockMessage.Body = ffContent; using (var memStream = new MemoryStream()) { var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(memStream, mockMessage); pipeClient.Connect(10000); pipeClient.Write(memStream.ToArray(), 0, (int)memStream.Length); pipeClient.WriteByte(0x00); pipeClient.WaitForPipeDrain(); } } //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 var receivedMsg = TestUtils.ConvertToMockMessage(testHelper.memStream); Assert.AreEqual(ffContent, receivedMsg.Body, "Contents of the received message is different"); } }
public void TestOneWay_FlatFile() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule("USERS", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); //We first spin a pipe server to make sure that the send port will be able to connect using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( "OneWaySend", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps)) { string ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;"; OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnected(cb), testHelper); //Here we spin the pipe client that will send the message to BizTalk using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", "OneWayReceive", PipeDirection.InOut, PipeOptions.Asynchronous)) { byte[] flatBytes = Encoding.UTF8.GetBytes(ffContent); pipeClient.Connect(10000); pipeClient.Write(flatBytes, 0, flatBytes.Count()); //pipeClient.Flush(); pipeClient.WriteByte(0x00);//writing the EOF byte pipeClient.Flush(); pipeClient.WaitForPipeDrain(); } //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 receivedMsg = Encoding.UTF8.GetString(testHelper.memStream.ToArray(), 0, (int)testHelper.memStream.Length); Assert.AreEqual(ffContent, receivedMsg, "Contents of the received message is different"); } }
public void TestTwoWay_XML() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule("USERS", PipeAccessRights.CreateNewInstance | PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); //We first spin a pipe server to make sure that the send port will be able to connect using (NamedPipeServerStream pipeServer = new NamedPipeServerStream( "TwoWaySend", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps)) { string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; string responseXml = "<SomeTestMessageResponse><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessageResponse>"; OutboundTestHelper testHelper = new OutboundTestHelper(pipeServer, responseXml); pipeServer.BeginWaitForConnection(cb => testHelper.ClientConnectedSyncronous(cb), testHelper); System.Threading.Thread.Sleep(100); //Here we spin the pipe client that will send the message to BizTalk using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", "TwoWayReceive", PipeDirection.InOut, PipeOptions.Asynchronous)) { byte[] xmlBytes = Encoding.UTF8.GetBytes(xml); pipeClient.Connect(10000); pipeClient.Write(xmlBytes, 0, xmlBytes.Count()); pipeClient.Flush(); pipeClient.WriteByte(0x00);//writing the EOF byte pipeClient.Flush(); pipeClient.WaitForPipeDrain(); //Here we wait for the event to be signalled bool waitExpired = testHelper.syncEvent.WaitOne(10000); Assert.IsTrue(waitExpired, "The waiting time for the response has expired prior to receiving the response"); //The event was signalled, we get the message stirng from the outBuffer string receivedXml = Encoding.UTF8.GetString(testHelper.memStream.ToArray(), 0, (int)testHelper.memStream.Length); Assert.AreEqual(xml, receivedXml, "Contents of received message is different"); //Here we read from the pipeClient the response message byte[] responseBytes = new byte[256]; using (MemoryStream memStream = new MemoryStream(256)) { int byteCountRead = 0; bool eofReached = false; while (!eofReached) { byteCountRead = pipeClient.Read(responseBytes, 0, responseBytes.Length); if (byteCountRead > 2) { eofReached = (responseBytes[byteCountRead - 1] == 0x0 && responseBytes[byteCountRead - 2] != 0x0 && responseBytes[byteCountRead - 3] != 0x0); } else if (byteCountRead > 1 && !eofReached) { eofReached = (responseBytes[byteCountRead - 1] == 0x0 && responseBytes[byteCountRead - 2] == 0x0); } else if (byteCountRead == 1) { eofReached = responseBytes[byteCountRead - 1] == 0x0; } memStream.Write(responseBytes, 0, eofReached ? byteCountRead - 1 : byteCountRead); } string receivedResponseXml = GeneralTestHelper.GetMessageFromArray( memStream.ToArray(), (int)memStream.Length, Encoding.UTF8); Assert.AreEqual(responseXml, receivedResponseXml, "Contents of the response message is different"); } } } }