Apache.NMS.ActiveMQ.Test.Commands.ActiveMQMessageTest.TestStringPropertyConversion C# (CSharp) Method

TestStringPropertyConversion() private method

private TestStringPropertyConversion ( ) : void
return void
        public void TestStringPropertyConversion()
        {
            ActiveMQMessage msg = new ActiveMQMessage();
            String propertyName = "property";
            String stringValue = "True";
            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetString(propertyName), stringValue);
            Assert.AreEqual((string)msg.Properties[propertyName], stringValue);
            Assert.AreEqual(msg.Properties.GetBool(propertyName), true);

            stringValue = "1";
            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetByte(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetShort(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
            Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);

            Double doubleValue = 1.5;
            stringValue = doubleValue.ToString();
            msg.Properties.SetString(propertyName, stringValue);
            Assert.AreEqual(msg.Properties.GetFloat(propertyName), 1.5, 0);
            Assert.AreEqual(msg.Properties.GetDouble(propertyName), 1.5, 0);

            stringValue = "bad";
            msg.Properties.SetString(propertyName, stringValue);

            try
            {
                msg.Properties.GetByte(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetShort(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetInt(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetLong(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetFloat(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            try
            {
                msg.Properties.GetDouble(propertyName);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }

            Assert.IsFalse(msg.Properties.GetBool(propertyName));
        }