Exemplo n.º 1
0
        public void IntStringMapObjectSerialization()
        {
            MapTestPatternBuffer patternBuffer = new MapTestPatternBuffer();
            IntStringMapObject   o1            = new IntStringMapObject(new Dictionary <int, string> {
                { 321, "foo" }, { 654, "bar" }
            });

            byte[] bytes = patternBuffer.Energize(o1);
            // 1 byte       EnumIntMapObject type ID
            // 1 byte       null bits
            // 1 byte       key count
            // 1 byte       value count
            // 8 bytes      keys (2 invariant ints)
            // 8 bytes      values (6 characters total, 2 lengths)
            Assert.AreEqual(20, bytes.Length);
            object o2 = patternBuffer.Energize(bytes);

            Assert.IsTrue(o2 is IntStringMapObject);
            IntStringMapObject p1 = (IntStringMapObject)o2;

            Assert.AreEqual(o1.IntStringMap.Count, p1.IntStringMap.Count);
            Assert.IsTrue(p1.IntStringMap.ContainsKey(321));
            Assert.IsTrue(p1.IntStringMap.ContainsKey(654));
            Assert.AreEqual(o1.IntStringMap[321], p1.IntStringMap[321]);
            Assert.AreEqual(o1.IntStringMap[654], p1.IntStringMap[654]);
            Assert.IsFalse(o1 == p1);
        }
Exemplo n.º 2
0
        public void IntStringMapObjectNull()
        {
            MapTestPatternBuffer patternBuffer = new MapTestPatternBuffer();
            IntStringMapObject   o1            = new IntStringMapObject(null);

            byte[] bytes = patternBuffer.Energize(o1);
            // 1 byte       EnumIntMapObject type ID
            // 1 byte       null bits
            Assert.AreEqual(2, bytes.Length);
            object o2 = patternBuffer.Energize(bytes);

            Assert.IsTrue(o2 is IntStringMapObject);
            IntStringMapObject p1 = (IntStringMapObject)o2;

            Assert.IsNull(o1.IntStringMap);
            Assert.IsNull(((IntStringMapObject)o2).IntStringMap);
        }