public void AmqpCodecMapTest() { byte[] workBuffer = new byte[4096]; ByteBuffer buffer = new ByteBuffer(workBuffer, 0, 0, workBuffer.Length); string strBig = new string('A', 512); Map map = new Map(); map.Add(new Symbol("boolTrue"), boolTrue); map.Add(new Symbol("boolFalse"), boolFalse); map.Add(new Symbol("ubyte"), ubyteValue); map.Add(new Symbol("ushort"), ushortValue); map.Add(new Symbol("uint"), uintValue); map.Add(new Symbol("ulong"), ulongValue); map.Add(new Symbol("byte"), byteValue); map.Add(new Symbol("short"), shortValue); map.Add(new Symbol("int"), intValue); map.Add(new Symbol("long"), longValue); map.Add(new Symbol("null"), null); map.Add(new Symbol("float"), floatValue); map.Add(new Symbol("double"), doubleValue); map.Add(new Symbol("char"), charValue); map.Add(new Symbol("datetime"), dtValue); map.Add(new Symbol("uuid"), uuidValue); map.Add(new Symbol("binaryNull"), null); map.Add(new Symbol("binary8"), bin8ValueEncoded); map.Add(new Symbol("binary32"), bin32ValueEncoded); map.Add(new Symbol("symbolNull"), (Symbol)null); map.Add(new Symbol("symbol8"), new Symbol(strValue)); map.Add(new Symbol("symbol32"), new Symbol(strBig)); map.Add(new Symbol("string8"), strValue); map.Add(new Symbol("string32"), strBig); map.Add(new Symbol("described1"), described1); AmqpCodec.EncodeObject(buffer, map); // make sure the size written is correct (it has to be Map32) // the first byte is FormatCode.Map32 int mapSize = (workBuffer[1] << 24) | (workBuffer[2] << 16) | (workBuffer[3] << 8) | workBuffer[4]; Assert.AreEqual(buffer.LengthAvailableToRead - 5, mapSize); Map decMap = (Map)AmqpCodec.DecodeBoxedObject(buffer); Assert.IsTrue(decMap[new Symbol("boolTrue")].Equals(true), "Boolean true expected."); Assert.IsTrue(decMap[new Symbol("boolFalse")].Equals(false), "Boolean false expected."); Assert.IsTrue(decMap[new Symbol("ubyte")].Equals(ubyteValue), "UByte value not equal."); Assert.IsTrue(decMap[new Symbol("ushort")].Equals(ushortValue), "UShort value not equal."); Assert.IsTrue(decMap[new Symbol("uint")].Equals(uintValue), "UInt value not equal."); Assert.IsTrue(decMap[new Symbol("ulong")].Equals(ulongValue), "ULong value not equal."); Assert.IsTrue(decMap[new Symbol("byte")].Equals(byteValue), "Byte value not equal."); Assert.IsTrue(decMap[new Symbol("short")].Equals(shortValue), "Short value not equal."); Assert.IsTrue(decMap[new Symbol("int")].Equals(intValue), "Int value not equal."); Assert.IsTrue(decMap[new Symbol("long")].Equals(longValue), "Long value not equal."); Assert.IsTrue(decMap[new Symbol("null")] == null, "Null object expected."); Assert.IsTrue(decMap[new Symbol("float")].Equals(floatValue), "Float value not equal."); Assert.IsTrue(decMap[new Symbol("double")].Equals(doubleValue), "Double value not equal."); Assert.IsTrue(decMap[new Symbol("char")].Equals(charValue), "Char value not equal."); Assert.IsTrue(decMap[new Symbol("datetime")].Equals(dtValue), "TimeStamp value not equal."); Assert.IsTrue(decMap[new Symbol("uuid")].Equals(uuidValue), "Uuid value not equal."); Assert.IsTrue(decMap[new Symbol("binaryNull")] == null, "Null binary expected."); byte[] bin8 = (byte[])decMap[new Symbol("binary8")]; EnsureEqual(bin8, 0, bin8.Length, bin8ValueEncoded, 0, bin8ValueEncoded.Length); byte[] bin32 = (byte[])decMap[new Symbol("binary32")]; EnsureEqual(bin32, 0, bin32.Length, bin32ValueEncoded, 0, bin32ValueEncoded.Length); Assert.Null(decMap[new Symbol("symbolNull")], "Null symbol expected."); Symbol symDecode = (Symbol)decMap[new Symbol("symbol8")]; Assert.AreEqual(symDecode, (Symbol)strValue, "AmqpSymbol value not equal."); symDecode = (Symbol)decMap[new Symbol("symbol32")]; Assert.AreEqual(symDecode, (Symbol)strBig, "AmqpSymbol value (big) not equal."); string strDecode = (string)decMap[new Symbol("string8")]; Assert.AreEqual(strDecode, strValue, "string value not equal."); strDecode = (string)decMap[new Symbol("string32")]; Assert.AreEqual(strDecode, strBig, "string value (big) not equal."); DescribedType described = (DescribedType)decMap[new Symbol("described1")]; Assert.AreEqual(described1.Descriptor, described.Descriptor, "Described value 1 descriptor is different"); Assert.AreEqual(described1, described, "Described value 1 value is different"); }
public void AmqpCodecListTest() { byte[] workBuffer = new byte[4096]; ByteBuffer buffer = new ByteBuffer(workBuffer, 0, 0, workBuffer.Length); string strBig = new string('A', 512); var list = new AmqpList(); list.Add(boolTrue); list.Add(boolFalse); list.Add(ubyteValue); list.Add(ushortValue); list.Add(uintValue); list.Add(ulongValue); list.Add(byteValue); list.Add(shortValue); list.Add(intValue); list.Add(longValue); list.Add(null); list.Add(floatValue); list.Add(doubleValue); list.Add(charValue); list.Add(dtValue); list.Add(uuidValue); list.Add(bin8ValueEncoded); list.Add(bin32ValueEncoded); list.Add((Symbol)null); list.Add(new Symbol(strValue)); list.Add(new Symbol(strBig)); list.Add(strValue); list.Add(strBig); list.Add(described1); list.Add(described2); list.Add(described3); list.Add(described4); AmqpCodec.EncodeObject(buffer, list); // make sure the size written is correct (it has to be List32) // the first byte is FormatCode.List32 int listSize = (workBuffer[1] << 24) | (workBuffer[2] << 16) | (workBuffer[3] << 8) | workBuffer[4]; Assert.AreEqual(buffer.LengthAvailableToRead - 5, listSize); IList decList = AmqpCodec.DecodeObject <AmqpList>(buffer); int index = 0; Assert.IsTrue(decList[index++].Equals(true), "Boolean true expected."); Assert.IsTrue(decList[index++].Equals(false), "Boolean false expected."); Assert.IsTrue(decList[index++].Equals(ubyteValue), "UByte value not equal."); Assert.IsTrue(decList[index++].Equals(ushortValue), "UShort value not equal."); Assert.IsTrue(decList[index++].Equals(uintValue), "UInt value not equal."); Assert.IsTrue(decList[index++].Equals(ulongValue), "ULong value not equal."); Assert.IsTrue(decList[index++].Equals(byteValue), "Byte value not equal."); Assert.IsTrue(decList[index++].Equals(shortValue), "Short value not equal."); Assert.IsTrue(decList[index++].Equals(intValue), "Int value not equal."); Assert.IsTrue(decList[index++].Equals(longValue), "Long value not equal."); Assert.IsTrue(decList[index++] == null, "Null object expected."); Assert.IsTrue(decList[index++].Equals(floatValue), "Float value not equal."); Assert.IsTrue(decList[index++].Equals(doubleValue), "Double value not equal."); Assert.IsTrue(decList[index++].Equals(charValue), "Char value not equal."); Assert.IsTrue(decList[index++].Equals(dtValue), "TimeStamp value not equal."); Assert.IsTrue(decList[index++].Equals(uuidValue), "Uuid value not equal."); byte[] bin8 = (byte[])decList[index++]; EnsureEqual(bin8, 0, bin8.Length, bin8ValueEncoded, 0, bin8ValueEncoded.Length); byte[] bin32 = (byte[])decList[index++]; EnsureEqual(bin32, 0, bin32.Length, bin32ValueEncoded, 0, bin32ValueEncoded.Length); Assert.IsTrue(decList[index++] == null, "Null symbol expected."); Symbol symDecode = (Symbol)decList[index++]; Assert.IsTrue(symDecode.Equals((Symbol)strValue), "AmqpSymbol value not equal."); symDecode = (Symbol)decList[index++]; Assert.IsTrue(symDecode.Equals((Symbol)strBig), "AmqpSymbol value (big) not equal."); string strDecode = (string)decList[index++]; Assert.IsTrue(strDecode.Equals(strValue), "string value not equal."); strDecode = (string)decList[index++]; Assert.IsTrue(strDecode.Equals(strBig), "string value (big) not equal."); //Assert.AreEqual(described1, (DescribedType)decList[index++]); //Assert.AreEqual(described2, (DescribedType)decList[index++]); //Assert.AreEqual(described3, (DescribedType)decList[index++]); //Assert.AreEqual(described4, (DescribedType)decList[index++]); DescribedType described; described = (DescribedType)decList[index++]; Assert.IsTrue(described.Descriptor.Equals(described1.Descriptor), "Described value 1 descriptor is different"); Assert.IsTrue(described.Equals(described1), "Described value 1 value is different"); described = (DescribedType)decList[index++]; Assert.IsTrue(described.Descriptor.Equals(described2.Descriptor), "Described value 2 descriptor is different"); Assert.IsTrue(described.Equals(described2), "Described value 2 value is different"); described = (DescribedType)decList[index++]; Assert.IsTrue(described.Descriptor.Equals(described3.Descriptor), "Described value 3 descriptor is different"); Assert.IsTrue(described.Equals(described3), "Described value 3 value is different"); described = (DescribedType)decList[index++]; Assert.IsTrue(described.Descriptor.Equals(described4.Descriptor), "Described value 4 descriptor is different"); EnsureEqual(((DescribedValue <AmqpList>)described).Value, ((DescribedValue <AmqpList>)described4).Value); }