public void TestReadObject()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
            byte testByte             = (byte)2;

            msg.WriteByte(testByte);
            msg.Reset();
            Assert.IsTrue((byte)msg.ReadObject() == testByte);
            msg.ClearBody();

            short testShort = 3;

            msg.WriteInt16(testShort);
            msg.Reset();
            Assert.IsTrue((short)msg.ReadObject() == testShort);
            msg.ClearBody();

            int testInt = 4;

            msg.WriteInt32(testInt);
            msg.Reset();
            Assert.IsTrue((int)msg.ReadObject() == testInt);
            msg.ClearBody();

            long testLong = 6L;

            msg.WriteInt64(testLong);
            msg.Reset();
            Assert.IsTrue((long)msg.ReadObject() == testLong);
            msg.ClearBody();

            float testFloat = 6.6f;

            msg.WriteSingle(testFloat);
            msg.Reset();
            Assert.IsTrue((float)msg.ReadObject() == testFloat);
            msg.ClearBody();

            double testDouble = 7.7d;

            msg.WriteDouble(testDouble);
            msg.Reset();
            Assert.IsTrue((double)msg.ReadObject() == testDouble);
            msg.ClearBody();

            char testChar = 'z';

            msg.WriteChar(testChar);
            msg.Reset();
            Assert.IsTrue((char)msg.ReadObject() == testChar);
            msg.ClearBody();

            byte[] data = new byte[50];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)i;
            }
            msg.WriteBytes(data);
            msg.Reset();
            byte[] valid = (byte[])msg.ReadObject();
            Assert.IsTrue(valid.Length == data.Length);
            for (int i = 0; i < valid.Length; i++)
            {
                Assert.IsTrue(valid[i] == data[i]);
            }
            msg.ClearBody();
            msg.WriteBoolean(true);
            msg.Reset();
            Assert.IsTrue((bool)msg.ReadObject());
        }
        public void TestReadOnlyBody()
        {
            ActiveMQStreamMessage message = new ActiveMQStreamMessage();

            try
            {
                message.WriteBoolean(true);
                message.WriteByte((byte)1);
                message.WriteBytes(new byte[1]);
                message.WriteBytes(new byte[3], 0, 2);
                message.WriteChar('a');
                message.WriteDouble(1.5);
                message.WriteSingle((float)1.5);
                message.WriteInt32(1);
                message.WriteInt64(1);
                message.WriteObject("stringobj");
                message.WriteInt16((short)1);
                message.WriteString("string");
            }
            catch (MessageNotWriteableException)
            {
                Assert.Fail("Should be writeable");
            }
            message.Reset();
            try
            {
                message.ReadBoolean();
                message.ReadByte();
                Assert.AreEqual(1, message.ReadBytes(new byte[10]));
                Assert.AreEqual(-1, message.ReadBytes(new byte[10]));
                Assert.AreEqual(2, message.ReadBytes(new byte[10]));
                Assert.AreEqual(-1, message.ReadBytes(new byte[10]));
                message.ReadChar();
                message.ReadDouble();
                message.ReadSingle();
                message.ReadInt32();
                message.ReadInt64();
                message.ReadString();
                message.ReadInt16();
                message.ReadString();
            }
            catch (MessageNotReadableException)
            {
                Assert.Fail("Should be readable");
            }
            try
            {
                message.WriteBoolean(true);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteByte((byte)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteBytes(new byte[1]);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteBytes(new byte[3], 0, 2);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try {
                message.WriteChar('a');
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteDouble(1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteSingle((float)1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteInt32(1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteInt64(1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteObject("stringobj");
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteSingle((short)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteString("string");
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
        }
        public void TestReadBytes()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();

            byte[] test = new byte[50];
            for (int i = 0; i < test.Length; i++)
            {
                test[i] = (byte)i;
            }
            msg.WriteBytes(test);
            msg.Reset();
            byte[] valid = new byte[test.Length];
            msg.ReadBytes(valid);
            for (int i = 0; i < valid.Length; i++)
            {
                Assert.IsTrue(valid[i] == test[i]);
            }
            msg.Reset();
            try
            {
                msg.ReadByte();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt16();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt32();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt64();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadSingle();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadString();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
        }