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 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 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 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 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");
            }
        }
Beispiel #6
0
        public void TestOneWayReceive_FlatFile_ISO88591()
        {
            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            string ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;";

            using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost",
                                                                                connectionUri.Uri.AbsolutePath, PipeDirection.InOut, PipeOptions.Asynchronous))
            {
                byte[] ffBytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(ffContent);

                pipeClient.Connect(10000);
                pipeClient.Write(ffBytes, 0, ffBytes.Count());
                pipeClient.WaitForPipeDrain();
            }
            //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(ffContent,
                            GeneralTestHelper.GetBodyAsString(msg, Encoding.GetEncoding("ISO-8859-1")), "Message contents of received message is different");
        }
Beispiel #7
0
        public void TestOneWayReceive_XML_PromotePOP3AdapterProperties()
        {
            const string adapterNamespace = "http://schemas.microsoft.com/BizTalk/2003/pop3-properties";

            string[] propertyArray = new string[] {
                "[email protected]",
                "POP3.Subject=Test mail",
                "[email protected]",
                "[email protected]",
                "[email protected]"
            };
            //Initializing the inbound handler again and passing the desired property
            InitInboundHandler("mock://localhost/TestEndpoint",
                               string.Join(";", propertyArray));

            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();
            }
            //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");

            //Verify the promoted properties
            var promotedProperties = msg.Properties
                                     .Where(p => p.Key == "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote")
                                     .Single();

            Assert.IsNotNull(promotedProperties, "The promoted properties list is not present");

            var propertiesList = promotedProperties.Value as List <KeyValuePair <XmlQualifiedName, object> >;

            Assert.AreEqual(propertiesList.Count, 5, "The element count in the promoted properties list differ");

            for (int i = 0; i < propertiesList.Count; i++)
            {
                string[] propertyDetails = propertyArray[i].Split('=');

                VerifyPromotedProperty(propertiesList[i],
                                       adapterNamespace,
                                       propertyDetails[0].Replace("POP3.", string.Empty),
                                       propertyDetails[1]);
            }
        }
Beispiel #8
0
        public void TestOneWayReceive_XML_ISO88591()
        {
            adapter.Encoding = "ISO-8859-1";
            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            //TODO: implement sending XML message to the inbound handler
            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.GetEncoding("ISO-8859-1").GetBytes(xml);

                pipeClient.Connect(10000);
                pipeClient.Write(xmlBytes, 0, xmlBytes.Count());
                pipeClient.WaitForPipeDrain();
            }
            //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.GetEncoding("ISO-8859-1")), "Message contents of received message is different");
        }
Beispiel #9
0
        public void TestSendSmallMessage_FlatFile()
        {
            //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.txt";
            step.Encoding    = "UTF-8";
            step.Timeout     = 30;
            //Validated the 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 TestReceiveSmallMessage_XML_LambdaValidation()
        {
            //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  = 10;

            string xml = @"<SomeTestMessage>
                <Element1 attribute1=""attributeValue"">
                </Element1>
                <Element2>Some element content</Element2>
            </SomeTestMessage>";

            // Calling Validate in order to start the pipe server
            step.Validate(context);

            // Setting up a manual reset event
            System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false);

            // Creating the validation step
            var validationStep = new LambdaValidationStep()
            {
                MessageValidationCallback = (m) =>
                {
                    Assert.AreEqual(xml, m.Body,
                                    "Validation of received message failed");

                    return(true);
                }
            };

            step.SubSteps.Add(validationStep);
            // 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();
            });

            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");
        }
Beispiel #11
0
        public void TestTwoWayReceive_XML_Unicode()
        {
            adapter.Encoding = "Unicode";
            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost",
                                                                                connectionUri.Uri.AbsolutePath, PipeDirection.InOut, PipeOptions.Asynchronous))
            {
                //TODO: implement sending XML message to the inbound handler
                string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>";

                byte[] xmlBytes = Encoding.Unicode.GetBytes(xml);

                pipeClient.Connect(10000);
                pipeClient.Write(xmlBytes, 0, xmlBytes.Count());
                //Send the EOF bytes
                //pipeClient.Write(new byte[] { 0x00, 0x00 }, 0, 2);
                pipeClient.WriteByte(0x00);
                pipeClient.WaitForPipeDrain();
                //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);

                Assert.IsNotNull(msg, "Message instance was not returned");
                Assert.AreEqual(xml, GeneralTestHelper.GetBodyAsString(msg, Encoding.Unicode), "Message contents of received message is different");
                //we send the response message
                string  responseXml     = "<Response><Description>The request was successfully processed</Description></Response>";
                Message responseMessage = GeneralTestHelper.CreateMessageWithBase64EncodedBody(responseXml, Encoding.Unicode);

                byte[] inBuffer = new byte[256];
                int    bytesCountRead = 0, eofCountRead = 0;
                System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false);
                //We queue up the reply so that it executes from the context of another thread.
                System.Threading.ThreadPool.QueueUserWorkItem(cb =>
                {
                    //we try to read from the pipe
                    bytesCountRead = pipeClient.Read(inBuffer, 0, inBuffer.Length);
                    //read the EOF bytes.
                    byte[] eofBytes = new byte[2];
                    eofCountRead    = pipeClient.Read(eofBytes, 0, 1);

                    manualEvent.Set();
                }
                                                              );

                reply.Reply(responseMessage, new TimeSpan(0, 0, 10));
                //We wait for the event to be signalled
                manualEvent.WaitOne(10000);

                string receivedResponseXml = GeneralTestHelper.GetMessageFromArray(inBuffer, bytesCountRead - (1 - eofCountRead), Encoding.Unicode);

                Assert.AreEqual(responseXml, receivedResponseXml, "The received response is not correct");
            }
        }
        public void TestReceiveSmallMessages_Debatch2_Expect3_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  = 1;
            step.DebatchedMessageCount = 3;
            //Calling 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

            bool timeoutExceptionThrown = false;

            System.Threading.ThreadPool.QueueUserWorkItem((state) =>
            {
                try
                {
                    step.Execute(context);
                    manualEvent.Set();
                }
                catch (TimeoutException)
                {
                    timeoutExceptionThrown = true;
                }
            });

            string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>";

            for (int i = 0; i < 2; i++)
            {
                Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);

                outboundHandler.Execute(msg, TimeSpan.FromSeconds(10));
            }

            // Waiting for the manual event to be set
            // The wait time is slightly longer than the step's timeout in order to
            // to be able to capture the TimeoutException correctly
            manualEvent.WaitOne(2000);

            Assert.IsTrue(timeoutExceptionThrown, "The expected exception was not thrown");

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s)),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s))),
                              Times.Exactly(2), "The LogData message was not called");
        }
        public void TestReceiveSmallMessages_Debatch3_SerialValidationSingleStep_XML()
        {
            // Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            BizUnit.
            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 30;
            step.DebatchedMessageCount = 3;

            // Setting up a validation step mock
            var validationStepMock = CreateSubStepMock();

            step.SubSteps.Add(validationStepMock.Object);

            // Calling 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>";

            for (int i = 0; i < 3; i++)
            {
                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");

            validationStepMock.Verify(vs => vs.Execute(
                                          It.Is <Stream>(s => s != null),
                                          It.Is <Context>(c => c != null)),
                                      Times.Exactly(3),
                                      "The SubStep mock was not called the expected number of times");
        }
Beispiel #14
0
        public void TestReceiveSmallMessages_Debatch50_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;
            step.DebatchedMessageCount = 50;
            //Calling 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();
            });

            var responseMessageList = new List <Message>(3);

            string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>";

            for (int i = 0; i < 50; i++)
            {
                Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);
                msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true);

                var responseMsg = outboundHandler.Execute(msg, TimeSpan.FromSeconds(10));
                responseMessageList.Add(responseMsg);
            }

            //Waiting for the manual event to be set
            manualEvent.WaitOne(3000);

            //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");
            Assert.AreEqual(50, responseMessageList.Count, "The number of response messages is incorrect.");

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s)),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s))),
                              Times.Exactly(100),
                              "The LogData method was not called");
        }
Beispiel #15
0
        public void TestSendSmallMessage_XML_FaultResponse()
        {
            //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("CustomFault.xml"), Encoding.UTF8);
            Message msgReply = Message.CreateMessage(
                MessageVersion.Default,
                MessageFault.CreateFault(
                    new FaultCode("Custom"),
                    "wanna fail"),
                "Test action");


            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");
        }
Beispiel #16
0
        public void TestOneWayReceive_XML_MediumMessage()
        {
            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            byte[] xmlBytes   = new byte[256];
            int    fileLength = 0;

            using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost",
                                                                                connectionUri.Uri.AbsolutePath, PipeDirection.InOut, PipeOptions.Asynchronous))
            {
                pipeClient.Connect(10000);

                int byteCountRead = 0;

                using (FileStream fs = File.OpenRead("MediumMessage.xml"))
                {
                    fileLength = (int)fs.Length;

                    while ((byteCountRead = fs.Read(xmlBytes, 0, xmlBytes.Length)) > 0)
                    {
                        pipeClient.Write(xmlBytes, 0, byteCountRead);
                    }
                }

                pipeClient.WaitForPipeDrain();
            }

            //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.IsNotNull(reply, "Reply instance was not returned");

            byte[] receivedMessageBytes = GeneralTestHelper.GetBodyAsBytes(msg);

            Assert.AreEqual(fileLength, receivedMessageBytes.Length, "The message length is wrong");

            string fileHash    = GeneralTestHelper.CalculateFileHash("MediumMessage.xml");
            string messageHash = GeneralTestHelper.CalculateBytesHash(receivedMessageBytes);

            Assert.AreEqual(fileHash, messageHash,
                            "Message contents of received message is different");
        }
Beispiel #17
0
        public void TestReceiveSmallMessage_ResponseSelector_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.ResponseSelector = (request, index) => SelectStaticResponse(request, index);

            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);

            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");

            byte[] responseBytes = GeneralTestHelper.GetBodyAsBytes(responseMsg);
            Assert.AreEqual(
                GeneralTestHelper.CalculateFileHash("TestResponse.xml"),
                GeneralTestHelper.CalculateBytesHash(responseBytes),
                "The second response is not as expected");
        }
Beispiel #18
0
        public void TestOneWayReceive_XML_PromoteFTPAdapterProperties()
        {
            //Initializing the inbound handler again and passing the desired property
            InitInboundHandler("mock://localhost/TestEndpoint", @"FTP.ReceivedFileName=File1.xml");

            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            //TODO: implement sending XML message to the inbound handler
            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();
            }
            //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");

            //Verify the promoted properties
            var promotedProperties = msg.Properties
                                     .Where(p => p.Key == "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote")
                                     .Single();

            Assert.IsNotNull(promotedProperties, "The promoted properties list is not present");

            var propertiesList = promotedProperties.Value as List <KeyValuePair <XmlQualifiedName, object> >;

            Assert.AreEqual(propertiesList.Count, 1, "The element count in the promoted properties list differ");

            VerifyPromotedProperty(propertiesList[0],
                                   "http://schemas.microsoft.com/BizTalk/2003/ftp-properties",
                                   "ReceivedFileName",
                                   "File1.xml");
        }
        public void TestReceiveSmallMessages_Debatch50_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  = 10;
            step.DebatchedMessageCount = 50;
            //Calling 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>";

            for (int i = 0; i < 50; i++)
            {
                Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);

                outboundHandler.Execute(msg, TimeSpan.FromSeconds(10));
            }

            //Waiting for the manual event to be set
            if (!manualEvent.WaitOne(1000))
            {
                manualEvent.WaitOne(5000);
            }

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s)),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s))),
                              Times.Exactly(50),
                              "The LogData method was not called");
        }
        public void TestReceiveSmallMessage_FlatFile()
        {
            //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 ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;";

            Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(ffContent, 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) &&
                                                 s == "MockReceiveStep received a message with content"),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;")),
                              Times.AtLeastOnce(),
                              "The LogData method was not called");
        }
Beispiel #21
0
        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");
                    }
                }
            }
        }
Beispiel #22
0
        public void TestOneWayReceive_XML_PromoteMQAdapterProperties()
        {
            const string adapterNamespace = "http://schemas.microsoft.com/BizTalk/2003/mq-properties";

            string[] propertyArray = new string[] {
                "MQMD.ApplIdentityData=SomeIdentityData",
                "MQMD.ApplOriginData=SAP123",
                "MQMD.CorrelId=TestCorrelationToken",
                "MQMD.Encoding=Binary",
                "MQMD.Expiry=2017-09-05T12:00:00",
                "MQMD.Format=Text",
                "MQMD.GroupID=",
                "MQMD.MsgId=TestMessageId",
                "MQMD.MsgSeqNumber=123",
                "MQMD.MsgType=Normal",
                "MQMD.Offset=0",
                "MQMD.OriginalLength=123456"
            };

            string properties = string.Join(";", propertyArray);

            //Initializing the inbound handler again and passing the desired property
            InitInboundHandler("mock://localhost/TestEndpoint",
                               properties);

            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            //TODO: implement sending XML message to the inbound handler
            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();
            }
            //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");

            //Verify the promoted properties
            var promotedProperties = msg.Properties
                                     .Where(p => p.Key == "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote")
                                     .Single();

            Assert.IsNotNull(promotedProperties, "The promoted properties list is not present");

            var propertiesList = promotedProperties.Value as List <KeyValuePair <XmlQualifiedName, object> >;

            Assert.AreEqual(propertiesList.Count, propertyArray.Length, "The element count in the promoted properties list differ");

            for (int i = 0; i < propertiesList.Count; i++)
            {
                string[] propertyDetails = propertyArray[i].Split('=');

                VerifyPromotedProperty(propertiesList[i],
                                       adapterNamespace,
                                       propertyDetails[0].Replace('.', '_'),
                                       propertyDetails[1]);
            }
        }
Beispiel #23
0
        public void TestTwoWayReceive_XML_MediumRequestResponse()
        {
            inboundHandler.StartListener(null, new TimeSpan(0, 0, 60));

            using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost",
                                                                                connectionUri.Uri.AbsolutePath, PipeDirection.InOut, PipeOptions.Asynchronous))
            {
                int    bytesCountRead = 0;
                int    fileLength     = 0;
                byte[] xmlBytes       = new byte[256];

                pipeClient.Connect(10000);

                using (FileStream fs = File.OpenRead("MediumMessage.xml"))
                {
                    fileLength = (int)fs.Length;

                    while ((bytesCountRead = fs.Read(xmlBytes, 0, xmlBytes.Length)) > 0)
                    {
                        pipeClient.Write(xmlBytes, 0, bytesCountRead);
                    }
                }

                //Send the EOF bytes
                pipeClient.WriteByte(0x00);
                pipeClient.WaitForPipeDrain();

                //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);

                Assert.IsNotNull(msg, "Message instance was not returned");

                byte[] msgBytes = GeneralTestHelper.GetBodyAsBytes(msg);

                Assert.AreEqual(fileLength, msgBytes.Length, "The message length is not correct");

                string requestMessageHash = GeneralTestHelper.CalculateBytesHash(msgBytes);
                string fileHash           = GeneralTestHelper.CalculateFileHash("MediumMessage.xml");

                Assert.AreEqual(fileHash,
                                requestMessageHash, "Message contents of received message is different");
                //we send the response message

                Message responseMessage = GeneralTestHelper.CreateMessageWithBase64EncodedBody(File.ReadAllBytes("MediumMessage.xml"));

                byte[] inBuffer = new byte[512];

                using (MemoryStream memStream = new MemoryStream(512))
                {
                    System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false);
                    //We queue up the reply so that it executes from the context of another thread.
                    System.Threading.ThreadPool.QueueUserWorkItem(cb =>
                    {
                        bool eof = false;
                        //we try to read from the pipe
                        while (!eof)
                        {
                            bytesCountRead = pipeClient.Read(inBuffer, 0, inBuffer.Length);

                            if (bytesCountRead > 0)
                            {
                                //if (inBuffer[bytesCountRead - 1] == 0x00 &&
                                //    inBuffer[bytesCountRead - 2] == 0x00)
                                if (inBuffer[bytesCountRead - 1] == 0x00)
                                {
                                    eof = true;
                                }

                                memStream.Write(inBuffer, 0, !eof ? bytesCountRead : bytesCountRead - 1);
                            }
                            else
                            {
                                eof = true;
                            }
                        }

                        manualEvent.Set();
                    }
                                                                  );

                    reply.Reply(responseMessage, new TimeSpan(0, 0, 10));
                    //We wait for the event to be signalled
                    manualEvent.WaitOne(10000);

                    string responseHash = GeneralTestHelper.CalculateBytesHash(memStream.ToArray());

                    Assert.AreEqual(fileHash, responseHash,
                                    "The received response is not correct");
                }
            }
        }
Beispiel #24
0
        public void TestSendSmallMessage_XML_MessageProperties()
        {
            //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;

            step.MessageProperties.Add(
                Utils.BizTalkProperties.BTS.Operation,
                "SomeTestOperation.com");

            step.MessageProperties.Add(
                Utils.BizTalkProperties.FILE.ReceivedFileName,
                @"\blabla\bla\TestFile.xml");
            //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");

            //Verify the promoted properties
            var promotedProperties = msg.Properties
                                     .Where(p => p.Key == "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote")
                                     .SingleOrDefault();

            Assert.IsNotNull(promotedProperties, "The promoted properties list is not present");

            var propertiesList = promotedProperties.Value as List <KeyValuePair <XmlQualifiedName, object> >;

            Assert.AreEqual(2, propertiesList.Count, "The element count in the promoted properties list differ");

            MessagePropertyValidator
            .ValidatePromotedProperty(propertiesList[0],
                                      "http://schemas.microsoft.com/BizTalk/2003/system-properties",
                                      "Operation",
                                      @"SomeTestOperation.com");

            MessagePropertyValidator
            .ValidatePromotedProperty(propertiesList[1],
                                      "http://schemas.microsoft.com/BizTalk/2003/file-properties",
                                      "ReceivedFileName",
                                      @"\blabla\bla\TestFile.xml");
        }