Beispiel #1
0
        public void TestSynchronizedDictionarySerialization()
        {
            SynchronizedDictionary ht = new SynchronizedDictionary();

            SimplePofContext    ctx        = new SimplePofContext();
            BinaryPofSerializer serializer = new BinaryPofSerializer(1);

            ctx.RegisterUserType(1, ht.GetType(), serializer);

            Assert.AreEqual(1, ctx.GetUserTypeIdentifier(ht));
            Assert.AreEqual(1, ctx.GetUserTypeIdentifier(ht.GetType()));

            Assert.AreEqual(ht.GetType(), ctx.GetType(1));
            Assert.AreEqual(ht.GetType().FullName, ctx.GetTypeName(1));
            Assert.AreEqual(serializer, ctx.GetPofSerializer(1));

            ht.Add(1, 1);
            ht.Add(2, 2);
            ht.Add(3, 3);
            ht.Add(4, 4);
            ht.Add(5, 5);
            ht.Add(6, 6);
            ht.Add(7, 7);

            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), ht);

            stream.Position = 0;
            SynchronizedDictionary ht2 = (SynchronizedDictionary)ctx.Deserialize(new DataReader(stream));

            Assert.AreEqual(ht[1], ht2[1]);
            Assert.AreEqual(ht[2], ht2[2]);
            Assert.AreEqual(ht[3], ht2[3]);
            Assert.AreEqual(ht[4], ht2[4]);
            Assert.AreEqual(ht[5], ht2[5]);
            Assert.AreEqual(ht[6], ht2[6]);
            Assert.AreEqual(ht[7], ht2[7]);
        }