public void TestReadOnlyBody()
{
ActiveMQMapMessage msg = new ActiveMQMapMessage();
msg.Body.SetBool("boolean", true);
msg.Body.SetByte("byte", (byte)1);
msg.Body["bytes"] = new byte[1];
msg.Body.SetChar("char", 'a');
msg.Body.SetDouble("double", 1.5);
msg.Body.SetFloat("float", 1.5f);
msg.Body.SetInt("int", 1);
msg.Body.SetLong("long", 1);
msg.Body["object"] = "stringObj";
msg.Body.SetShort("short", (short)1);
msg.Body.SetString("string", "string");
msg.ReadOnlyBody = true;
try
{
msg.Body.GetBool("boolean");
msg.Body.GetByte("byte");
Assert.IsNotNull(msg.Body["bytes"]);
msg.Body.GetChar("char");
msg.Body.GetDouble("double");
msg.Body.GetFloat("float");
msg.Body.GetInt("int");
msg.Body.GetLong("long");
Assert.IsNotNull(msg.Body["object"]);
msg.Body.GetShort("short");
msg.Body.GetString("string");
}
catch(MessageNotReadableException)
{
Assert.Fail("should be readable");
}
try
{
msg.Body.SetBool("boolean", true);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetByte("byte", (byte)1);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body["bytes"] = new byte[1];
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetChar("char", 'a');
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetDouble("double", 1.5);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try {
msg.Body.SetFloat("float", 1.5f);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetInt("int", 1);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetLong("long", 1);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body["object"] = "stringObj";
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetShort("short", (short)1);
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
try
{
msg.Body.SetString("string", "string");
Assert.Fail("should throw exception");
}
catch(MessageNotWriteableException)
{
}
}