Beispiel #1
0
        public void AmqpCodecMapTest()
        {
            byte[]     workBuffer = new byte[4096];
            ByteBuffer buffer     = new ByteBuffer(workBuffer);
            string     strBig     = new string('A', 512);

            AmqpMap map = new AmqpMap();

            map.Add(new MapKey("boolTrue"), boolTrue);
            map.Add(new MapKey("boolFalse"), boolFalse);
            map.Add(new MapKey("ubyte"), ubyteValue);
            map.Add(new MapKey("ushort"), ushortValue);
            map.Add(new MapKey("uint"), uintValue);
            map.Add(new MapKey("ulong"), ulongValue);
            map.Add(new MapKey("byte"), byteValue);
            map.Add(new MapKey("short"), shortValue);
            map.Add(new MapKey("int"), intValue);
            map.Add(new MapKey("long"), longValue);
            map.Add(new MapKey("null"), null);
            map.Add(new MapKey("float"), floatValue);
            map.Add(new MapKey("double"), doubleValue);
            map.Add(new MapKey("decimal32"), decimal32Value);
            map.Add(new MapKey("decimal64"), decimal64Value);
            map.Add(new MapKey("decimal128"), decimal128Value);
            map.Add(new MapKey("char"), charValue);
            map.Add(new MapKey("datetime"), dtValue);
            map.Add(new MapKey("uuid"), uuidValue);
            map.Add(new MapKey("binaryNull"), new ArraySegment <byte>());
            map.Add(new MapKey("binary8"), bin8Value);
            map.Add(new MapKey("binary32"), bin32Value);
            map.Add(new MapKey("symbolNull"), new AmqpSymbol());
            map.Add(new MapKey("symbol8"), new AmqpSymbol(strValue));
            map.Add(new MapKey("symbol32"), new AmqpSymbol(strBig));
            map.Add(new MapKey("string8"), strValue);
            map.Add(new MapKey("string32"), strBig);
            map.Add(new MapKey("described1"), described1);

            AmqpCodec.EncodeMap(map, buffer);

            // make sure the size written is correct (it has to be Map32)
            // the first byte is FormatCode.Map32
            int mapSize = (int)AmqpBitConverter.ReadUInt(workBuffer, 1, 4);

            Assert.Equal(buffer.Length - 5, mapSize);

            AmqpMap decMap = AmqpCodec.DecodeMap(buffer);

            Assert.True(decMap[new MapKey("boolTrue")].Equals(true), "Boolean true expected.");
            Assert.True(decMap[new MapKey("boolFalse")].Equals(false), "Boolean false expected.");
            Assert.True(decMap[new MapKey("ubyte")].Equals(ubyteValue), "UByte value not equal.");
            Assert.True(decMap[new MapKey("ushort")].Equals(ushortValue), "UShort value not equal.");
            Assert.True(decMap[new MapKey("uint")].Equals(uintValue), "UInt value not equal.");
            Assert.True(decMap[new MapKey("ulong")].Equals(ulongValue), "ULong value not equal.");
            Assert.True(decMap[new MapKey("byte")].Equals(byteValue), "Byte value not equal.");
            Assert.True(decMap[new MapKey("short")].Equals(shortValue), "Short value not equal.");
            Assert.True(decMap[new MapKey("int")].Equals(intValue), "Int value not equal.");
            Assert.True(decMap[new MapKey("long")].Equals(longValue), "Long value not equal.");
            Assert.True(decMap[new MapKey("null")] == null, "Null object expected.");
            Assert.True(decMap[new MapKey("float")].Equals(floatValue), "Float value not equal.");
            Assert.True(decMap[new MapKey("double")].Equals(doubleValue), "Double value not equal.");
            Assert.True(decMap[new MapKey("decimal32")].Equals(decimal32Value), "Decimal32 value not equal.");
            Assert.True(decMap[new MapKey("decimal64")].Equals(decimal64Value), "Decimal64 value not equal.");
            Assert.True(decMap[new MapKey("decimal128")].Equals(decimal128Value), "Decimal128 value not equal.");
            Assert.True(decMap[new MapKey("char")].Equals(charValue), "Char value not equal.");
            Assert.True(decMap[new MapKey("datetime")].Equals(dtValue), "TimeStamp value not equal.");
            Assert.True(decMap[new MapKey("uuid")].Equals(uuidValue), "Uuid value not equal.");
            Assert.True(decMap[new MapKey("binaryNull")] == null, "Null binary expected.");
            ArraySegment <byte> bin8 = (ArraySegment <byte>)decMap[new MapKey("binary8")];

            EnsureEqual(bin8.Array, bin8.Offset, bin8.Count, bin8Value.Array, bin8Value.Offset, bin8Value.Count);
            ArraySegment <byte> bin32 = (ArraySegment <byte>)decMap[new MapKey("binary32")];

            EnsureEqual(bin32.Array, bin32.Offset, bin32.Count, bin32Value.Array, bin32Value.Offset, bin32Value.Count);

            Assert.True(decMap[new MapKey("symbolNull")] == null, "Null symbol expected.");
            AmqpSymbol symDecode = (AmqpSymbol)decMap[new MapKey("symbol8")];

            Assert.True(symDecode.Equals(strValue), "AmqpSymbol value not equal.");
            symDecode = (AmqpSymbol)decMap[new MapKey("symbol32")];
            Assert.True(symDecode.Equals(strBig), "AmqpSymbol value (big) not equal.");

            string strDecode = (string)decMap[new MapKey("string8")];

            Assert.True(strDecode.Equals(strValue), "string value not equal.");
            strDecode = (string)decMap[new MapKey("string32")];
            Assert.True(strDecode.Equals(strBig), "string value (big) not equal.");

            DescribedType described = (DescribedType)decMap[new MapKey("described1")];

            Assert.True(described.Descriptor.Equals(described1.Descriptor), "Described value 1 descriptor is different");
            Assert.True(described.Value.Equals(described1.Value), "Described value 1 value is different");
        }