Apache.NMS.Test.ForeignMessageTransformationTest.SendReceiveForeignBytesMessageTest C# (CSharp) Method

SendReceiveForeignBytesMessageTest() private method

private SendReceiveForeignBytesMessageTest ( [ deliveryMode ) : void
deliveryMode [
return void
        public void SendReceiveForeignBytesMessageTest(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using(IConnection connection = CreateConnection())
            {
                connection.Start();
                using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using(IMessageConsumer consumer = session.CreateConsumer(destination))
                    using(IMessageProducer producer = session.CreateProducer(destination))
                    {
                        try
                        {
                            producer.DeliveryMode = deliveryMode;
                            BytesMessage request = new BytesMessage();
                            request.Properties[propertyName] = propertyValue;
                            request.WriteBytes(bytesContent);

                            producer.Send(request);

                            IBytesMessage message = consumer.Receive(receiveTimeout) as IBytesMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                            // Check the body
                            byte[] content = new byte[bytesContent.Length];
                            Assert.AreEqual(bytesContent.Length, message.ReadBytes(content));
                            Assert.AreEqual(bytesContent, content, "BytesMessage body was wrong.");

                            // use generic API to access entries
                            Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);

                            // use type safe APIs
                            Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName),   "map entry: " + propertyName);
                        }
                        catch(NotSupportedException)
                        {
                        }
                    }
                }
            }
        }