ClearBody() public method

public ClearBody ( ) : void
return void
 public void TestClearBody()
 {
     ActiveMQStreamMessage streamMessage = new ActiveMQStreamMessage();
     try
     {
         streamMessage.WriteObject((Int64) 2);
         streamMessage.ClearBody();
         Assert.IsFalse(streamMessage.ReadOnlyBody);
         streamMessage.WriteObject((Int64) 2);
         streamMessage.ReadObject();
         Assert.Fail("should throw exception");
     }
     catch(MessageNotReadableException)
     {
     }
     catch(MessageNotWriteableException)
     {
         Assert.Fail("should be writeable");
     }
 }
        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 TestWriteObject()
 {
     try
     {
         ActiveMQStreamMessage message = new ActiveMQStreamMessage();
         message.ClearBody();
         message.WriteObject("test");
         message.WriteObject((Char) 'a');
         message.WriteObject((Boolean) false);
         message.WriteObject((Byte) ((byte) 2));
         message.WriteObject((Int16) ((short) 2));
         message.WriteObject((Int32) 2);
         message.WriteObject((Int64) 2L);
         message.WriteObject((Single) 2.0f);
         message.WriteObject((Double) 2.0);
     }
     catch(Exception e)
     {
         Assert.Fail(e.Message);
     }
     try
     {
         ActiveMQStreamMessage message = new ActiveMQStreamMessage();
         message.ClearBody();
         message.WriteObject(new Object());
         Assert.Fail("should throw an exception");
     }
     catch(MessageFormatException)
     {
     }
     catch(Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
        public void TestWriteOnlyBody()
        {
            ActiveMQStreamMessage message = new ActiveMQStreamMessage();
            message.ClearBody();
            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.WriteSingle((short)1);
                message.WriteString("string");
            }
            catch(MessageNotWriteableException)
            {
                Assert.Fail("Should be writeable");
            }
            try
            {
                message.ReadBoolean();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadByte();
                Assert.Fail("Should have thrown exception");
            } catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadBytes(new byte[1]);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadBytes(new byte[2]);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadDouble();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadSingle();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException) {
            }

            try
            {
                message.ReadInt32();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadInt64();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadString();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadInt16();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
            try
            {
                message.ReadString();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageNotReadableException)
            {
            }
        }
        public void TestReadString()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();

            byte testByte = (byte)2;
            msg.WriteString(((Byte)testByte).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadByte() == testByte);
            msg.ClearBody();
            short testShort = 3;
            msg.WriteString(((Int16)testShort).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt16() == testShort);
            msg.ClearBody();
            int testInt = 4;
            msg.WriteString(((Int32)testInt).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt32() == testInt);
            msg.ClearBody();
            long testLong = 6L;
            msg.WriteString(((Int64)testLong).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt64() == testLong);
            msg.ClearBody();
            float testFloat = 6.6f;
            msg.WriteString(((Single)testFloat).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadSingle() == testFloat);
            msg.ClearBody();
            double testDouble = 7.7d;
            msg.WriteString(((Double)testDouble).ToString());
            msg.Reset();
            Assert.AreEqual( testDouble, msg.ReadDouble(), 0.05 );
            msg.ClearBody();
            msg.WriteString("true");
            msg.Reset();
            Assert.IsTrue(msg.ReadBoolean());
            msg.ClearBody();
            msg.WriteString("a");
            msg.Reset();
            try
            {
                msg.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }
            msg.ClearBody();
            msg.WriteString("777");
            msg.Reset();
            try
            {
                msg.ReadBytes(new byte[3]);
                Assert.Fail("Should have thrown exception");
            }
            catch(MessageFormatException)
            {
            }
        }