public void TestCreateWithPopulatedMap()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue
                {
                    Value = new Map
                    {
                        { "entry1", true },
                        { "entry2", false }
                    }
                }
            };

            AmqpNmsMapMessageFacade facade = CreateReceivedMapMessageFacade(message);

            // Data should be preserved
            Assert.True(facade.Map.Keys.Count > 0);
            bool result = facade.Map.GetBool("entry1");

            Assert.True(result);
            Assert.True(facade.HasBody());

            // Should be able to use the message, e.g clearing it and adding to it.
            facade.ClearBody();
            Assert.False(facade.HasBody());
            facade.Map.SetString("entry", "value");
        }
        protected AmqpNmsMapMessageFacade CreateReceivedMapMessageFacade(global::Amqp.Message message)
        {
            AmqpNmsMapMessageFacade facade = new AmqpNmsMapMessageFacade();

            facade.Initialize(CreateMockConsumer(CreateMockAmqpConnection()), message);
            return(facade);
        }
        protected AmqpNmsMapMessageFacade CreateNewMapMessageFacade()
        {
            AmqpNmsMapMessageFacade facade = new AmqpNmsMapMessageFacade();

            facade.Initialize(CreateMockAmqpConnection());
            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 TestNewMessageToSendDoesNotContainMessageTypeAnnotation()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            Assert.Null(facade.MessageAnnotations);

            Assert.AreEqual(MessageSupport.JMS_TYPE_MAP, facade.JmsMsgType);
        }
        public void TestMessageClearBodyWorks()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            CollectionAssert.IsEmpty(facade.Map.Keys);
            facade.Map.SetString("entry1", "value1");
            CollectionAssert.IsNotEmpty(facade.Map.Keys);
            facade.ClearBody();
            CollectionAssert.IsEmpty(facade.Map.Keys);
        }
        public void TestCreateWithNullBodySection()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = null
            };

            AmqpNmsMapMessageFacade facade = CreateReceivedMapMessageFacade(message);

            // Should be able to use the message, e.g clearing it and adding to it.
            facade.ClearBody();
            facade.Map.SetString("entry", "value");
            CollectionAssert.IsNotEmpty(facade.Map.Keys);
        }
        public void TestCreateWithEmptyMap()
        {
            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue {
                    Value = new Map()
                }
            };

            AmqpNmsMapMessageFacade facade = CreateReceivedMapMessageFacade(message);

            // Should be able to use the message, e.g clearing it and adding to it.
            facade.ClearBody();
            facade.Map.SetString("entry1", "value1");
        }
        public void TestMessageCopy()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            facade.Map.SetString("entry1", "value");
            facade.Map.SetByte("entry2", 1);
            facade.Map.SetInt("entry3", 1);

            AmqpNmsMapMessageFacade copy = facade.Copy() as AmqpNmsMapMessageFacade;

            Assert.IsNotNull(copy);
            Assert.True(copy.Map.Contains("entry1"));
            Assert.True(copy.Map.Contains("entry2"));
            Assert.True(copy.Map.Contains("entry3"));
        }
        public void TestReceivedMapWithBinaryEntryReturnsByteArray()
        {
            string myKey1      = "key1";
            string bytesSource = "myBytesAmqpValue";

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

            global::Amqp.Message message = new global::Amqp.Message
            {
                BodySection = new AmqpValue {
                    Value = new Map {
                        { myKey1, bytes }
                    }
                }
            };

            AmqpNmsMapMessageFacade facade = CreateReceivedMapMessageFacade(message);

            // retrieve the bytes using getBytes, check they match expectation
            byte[] bytesValue = facade.Map.GetBytes(myKey1);
            CollectionAssert.AreEqual(bytes, bytesValue);
        }
        public void TestNewMessageToSendReturnsEmptyMapNamesEnumeration()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            Assert.NotNull(facade.Map.Keys);
        }
        public void TestNewMessageToSendItemExists()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            Assert.False(facade.Map.Contains("entry"));
        }
        public void TestNewMessageToSendReportsIsEmpty()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            CollectionAssert.IsEmpty(facade.Map.Keys);
        }
        public void TestNewMessageToSendReportsNoBody()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            facade.HasBody();
        }
        public void TestNewMessageToSendClearBodyDoesNotFail()
        {
            AmqpNmsMapMessageFacade facade = CreateNewMapMessageFacade();

            facade.ClearBody();
        }