protected AmqpNmsTextMessageFacade CreateReceivedTextMessageFacade(global::Amqp.Message message)
        {
            AmqpNmsTextMessageFacade facade = new AmqpNmsTextMessageFacade();

            facade.Initialize(CreateMockConsumer(), message);
            return(facade);
        }
        private AmqpNmsMessageFacade CreateMessageFacadeFromTypeId(sbyte msgType)
        {
            AmqpNmsMessageFacade message;
            switch (msgType)
            {
                case MessageSupport.JMS_TYPE_MSG:
                    message = new AmqpNmsMessageFacade();
                    break;
                case MessageSupport.JMS_TYPE_BYTE:
                    message = new AmqpNmsBytesMessageFacade();
                    break;
                case MessageSupport.JMS_TYPE_TXT:
                    message = new AmqpNmsTextMessageFacade();
                    break;
                case MessageSupport.JMS_TYPE_OBJ:
                    message = new AmqpNmsObjectMessageFacade();
                    break;
                case MessageSupport.JMS_TYPE_STRM:
                    message = new AmqpNmsStreamMessageFacade();
                    break;
                case MessageSupport.JMS_TYPE_MAP:
                    message = new AmqpNmsMapMessageFacade();
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(msgType));
            }

            message.Initialize(CreateMockAmqpConnection());

            return message;
        }
        public void TestGetTextUsingReceivedMessageWithNoBodySectionReturnsNull()
        {
            global::Amqp.Message     message           = new global::Amqp.Message();
            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.Null(textMessageFacade.Text, "expected null string");
        }
        protected AmqpNmsTextMessageFacade CreateNewTextMessageFacade()
        {
            AmqpNmsTextMessageFacade facade = new AmqpNmsTextMessageFacade();

            facade.Initialize(CreateMockAmqpConnection());
            return(facade);
        }
        public void TestNewMessageToSendReturnsNullText()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();

            textMessageFacade.ClearBody();
            Assert.Null(textMessageFacade.Text);
        }
        public void TestMessageClearBodyWorks()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();

            Assert.Null(textMessageFacade.Text);
            textMessageFacade.Text = "SomeTextForMe";
            Assert.NotNull(textMessageFacade.Text);
            textMessageFacade.ClearBody();
            Assert.Null(textMessageFacade.Text);
        }
        public void TestNewMessageToSendDoesNotContainMessageTypeAnnotation()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();


            MessageAnnotations annotations = textMessageFacade.MessageAnnotations;

            Assert.Null(annotations, "MessageAnnotations section was present");
            Assert.AreEqual(MessageSupport.JMS_TYPE_TXT, textMessageFacade.JmsMsgType);
        }
        public void TestMessageCopy()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();

            textMessageFacade.Text = "SomeTextForMe";

            AmqpNmsTextMessageFacade copy = textMessageFacade.Copy() as AmqpNmsTextMessageFacade;

            Assert.IsNotNull(copy);
            Assert.AreEqual(textMessageFacade.Text, copy.Text);
        }
        public void TestSetGetTextWithNewMessageToSend()
        {
            string text = "myTestText";
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();

            textMessageFacade.Text = text;
            Assert.NotNull(textMessageFacade.Message.BodySection);
            Assert.IsInstanceOf <AmqpValue>(textMessageFacade.Message.BodySection);
            Assert.AreEqual(text, ((AmqpValue)textMessageFacade.Message.BodySection).Value);
            Assert.AreEqual(text, textMessageFacade.Text);
        }
        public void TestGetTextUsingReceivedMessageWithAmqpValueSectionContainingNull()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue {
                    Value = null
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.Null(textMessageFacade.Text, "expected null string");
        }
        public void TestGetTextWithNonAmqpValueOrDataSectionReportsNoBody()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpSequence()
                {
                    List = new List <object>()
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.False(textMessageFacade.HasBody());
        }
        public void TestCreateWithEmptyAmqpValue()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue {
                    Value = null
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            // Should be able to use the message, e.g clearing it and adding to it.
            textMessageFacade.ClearBody();
            textMessageFacade.Text = "TEST";
            Assert.AreEqual("TEST", textMessageFacade.Text);
        }
        public void TestGetTextUsingReceivedMessageWithZeroLengthDataSectionReturnsEmptyString()
        {
            byte[] bytes = Encoding.UTF8.GetBytes("");

            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new Data()
                {
                    Binary = bytes
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.AreEqual(string.Empty, textMessageFacade.Text, "expected zero-length string");
        }
        public void TestGetTextUsingReceivedMessageWithDataSectionContainingNothingReturnsEmptyString()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new Data()
                {
                    Binary = null
                }
            };

            // This shouldn't happen with actual received messages, since Data sections can't really
            // have a null value in them, they would have an empty byte array, but just in case...
            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.AreEqual(string.Empty, textMessageFacade.Text, "expected zero-length string");
        }
        public void TestGetTextWithAmqpValueContainingNonNullNonStringValueThrowsIse()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue()
                {
                    Value = true
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.Catch <IllegalStateException>(() =>
            {
                string text = textMessageFacade.Text;
            });
        }
        public void TestGetTextWithNonAmqpValueOrDataSectionThrowsIse()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpSequence()
                {
                    List = new List <object>()
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.Catch <IllegalStateException>(() =>
            {
                string text = textMessageFacade.Text;
            });
        }
        public void TestGetTextUsingReceivedMessageWithDataSectionContainingStringBytes()
        {
            string encodedString = "myEncodedString";

            byte[] bytes = Encoding.UTF8.GetBytes(encodedString);

            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new Data()
                {
                    Binary = bytes
                }
            };

            AmqpNmsTextMessageFacade textMessageFacade = CreateReceivedTextMessageFacade(message);

            Assert.AreEqual(encodedString, textMessageFacade.Text);
        }
        public void TestNewMessageToSendClearBodyDoesNotFail()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();

            textMessageFacade.ClearBody();
        }