Exemplo n.º 1
0
        public void TestIdFromContext()
        {
            SimplePofContext context = new SimplePofContext();

            context.RegisterUserType(9999, typeof(MyCollection), new MySerializer());
            Assert.AreEqual(9999, context.GetUserTypeIdentifier(MyCollection.Instance.GetType()));
        }
Exemplo n.º 2
0
        public void TestIdFromPofHelper()
        {
            SimplePofContext context = new SimplePofContext();

            context.RegisterUserType(9999, typeof(MyCollection), new MySerializer());
            Assert.AreEqual(9999, PofHelper.GetPofTypeId(MyCollection.Instance.GetType(), context));
        }
        public void TestEvolvable()
        {
            var cxt1 = new SimplePofContext();
            var cxt2 = new SimplePofContext();

            cxt1.RegisterUserType(1001, typeof(PersonV1), new PofAnnotationSerializer(1001, typeof(PersonV1)));
            cxt2.RegisterUserType(1001, typeof(PersonV2), new PofAnnotationSerializer(1001, typeof(PersonV2)));

            var personV1 = new PersonV1("Frank", "Spencer", 57);
            // verify we can go forward 1 => 2
            var teleportedV2 = EH.FromBinary(EH.ToBinary(personV1, cxt1), cxt2) as PersonV2;

            // verify we can go back 2 => 1
            teleportedV2.m_fMale = true;
            var teleportedV1       = EH.FromBinary(EH.ToBinary(teleportedV2, cxt2), cxt1) as PersonV1;
            var teleportedV2FromV1 = EH.FromBinary(EH.ToBinary(teleportedV1, cxt1), cxt2) as PersonV2;

            // v1 => v2
            Assert.IsNotNull(teleportedV2);
            Assert.AreEqual("Frank", teleportedV2.m_firstName);
            Assert.AreEqual("Spencer", teleportedV2.m_lastName);
            Assert.AreEqual(57, teleportedV2.m_age);
            // v2 => v1
            Assert.IsNotNull(teleportedV1);
            Assert.IsNotNull(teleportedV1.FutureData);
            Assert.AreEqual("Frank", teleportedV1.m_firstName);
            Assert.AreEqual("Spencer", teleportedV1.m_lastName);
            Assert.AreEqual(57, teleportedV1.m_age);
            Assert.IsNotNull(teleportedV2FromV1);
            Assert.AreEqual("Frank", teleportedV2FromV1.m_firstName);
            Assert.AreEqual("Spencer", teleportedV2FromV1.m_lastName);
            Assert.AreEqual(57, teleportedV2FromV1.m_age);
            Assert.IsTrue(teleportedV2FromV1.m_fMale);
        }
        public void TestSerialization()
        {
            SimplePofContext cxt = new SimplePofContext();

            cxt.RegisterUserType(1001, typeof(PersonV1), new PofAnnotationSerializer(1001, typeof(PersonV1)));
            cxt.RegisterUserType(1002, typeof(Child), new PofAnnotationSerializer(1002, typeof(Child), true));

            PersonV1 value = new PersonV1("Frank", "Spencer", 57);
            Child    child = new Child("Betty", "Spencer", 55);

            Binary binValue = EH.ToBinary(child, cxt);
            var    reader   = new DataReader(binValue.GetStream());
            int    typeId   = reader.ReadByte() == 21 ? reader.ReadPackedInt32() : -1;

            PersonV1 teleported  = EH.FromBinary(SerializationHelper.ToBinary(value, cxt), cxt) as PersonV1;
            Child    teleported2 = EH.FromBinary(binValue, cxt) as Child;

            Assert.AreEqual(1002, typeId);
            Assert.IsNotNull(teleported);
            Assert.IsNotNull(teleported2);
            Assert.AreEqual("Frank", teleported.m_firstName);
            Assert.AreEqual("Spencer", teleported.m_lastName);
            Assert.AreEqual(57, teleported.m_age);
            Assert.AreEqual("Betty", teleported2.m_firstName);
            Assert.AreEqual("Spencer", teleported2.m_lastName);
            Assert.AreEqual(55, teleported2.m_age);
        }
        public void TestVersionIdNegativeVelueException()
        {
            SimplePofContext ctx    = new SimplePofContext();
            Stream           stream = new MemoryStream();
            IPofWriter       writer = new PofStreamWriter.UserTypeWriter(new DataWriter(stream), ctx, 1, -1);

            writer.VersionId = -1;
        }
 private void initPOFReader()
 {
     if (m_ctx == null)
     {
         m_ctx = new SimplePofContext();
     }
     m_stream.Position = 0;
     m_reader          = new DataReader(m_stream);
     m_pofReader       = new PofStreamReader(m_reader, m_ctx);
 }
 private void initPOFWriter()
 {
     if (m_ctx == null)
     {
         m_ctx = new SimplePofContext();
     }
     m_stream    = new MemoryStream();
     m_writer    = new DataWriter(m_stream);
     m_pofWriter = new PofStreamWriter(m_writer, m_ctx);
 }
        public void TestBeginPropertyWithExcepton1()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(PortablePerson), new PortableObjectSerializer(1));
            PortablePerson zoja   = new PortablePerson("Zoja", new DateTime(1982, 11, 11, 7, 15, 30));
            Stream         stream = new MemoryStream();
            IPofWriter     writer = new PofStreamWriter.UserTypeWriter(new DataWriter(stream), ctx, 1, -1);

            writer.WriteObject(-1, zoja);
        }
        public void TestUserTypeConstuctor()
        {
            SimplePofContext ctx    = new SimplePofContext();
            Stream           stream = new MemoryStream();
            IPofWriter       writer = new PofStreamWriter.UserTypeWriter(new DataWriter(stream),
                                                                         ctx, 1, -1);

            Assert.IsTrue(writer != null);
            Assert.AreEqual(1, writer.UserTypeId);
            Assert.AreEqual(0, writer.VersionId);
        }
        public void TestSerializationWithNonPortableType()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(PersonLite), new PortableObjectSerializer(1));

            PersonLite ana = new PersonLite("Ana Maria Seovic", new DateTime(2006, 8, 14));

            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), ana);
        }
Exemplo n.º 11
0
        public void TestPofTypeID()
        {
            Assert.AreEqual(PofConstants.T_BOOLEAN, PofHelper.GetPofTypeId(true.GetType(), new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_CHAR, PofHelper.GetPofTypeId('t'.GetType(), new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_INT16,
                            PofHelper.GetPofTypeId(Int16.MinValue.GetType(), new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_INT32, PofHelper.GetPofTypeId((-1).GetType(), new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_INT64,
                            PofHelper.GetPofTypeId(Int64.MaxValue.GetType(), new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_DATETIME,
                            PofHelper.GetPofTypeId(new DateTime(11, 11, 11, 11, 11, 11).GetType(),
                                                   new SimplePofContext()));
            Assert.AreEqual(PofConstants.T_CHAR_STRING, PofHelper.GetPofTypeId("test".GetType(), new SimplePofContext()));

            double[] uniformArray = new double[] { Double.MaxValue, 0, -1, Double.NegativeInfinity };
            Assert.AreEqual(PofConstants.T_UNIFORM_ARRAY,
                            PofHelper.GetPofTypeId(uniformArray.GetType(), new SimplePofContext()));

            Object[] objArray = new object[] { new DateTime(11, 11, 11), 13, Double.NaN };
            Assert.AreEqual(PofConstants.T_ARRAY, PofHelper.GetPofTypeId(objArray.GetType(), new SimplePofContext()));

            ArrayList al = new ArrayList();

            al.Add(new DateTime(11, 11, 11));
            al.Add(5.55);
            Assert.AreEqual(PofConstants.T_COLLECTION, PofHelper.GetPofTypeId(al.GetType(), new SimplePofContext()));

            Hashtable ht = new Hashtable();

            ht.Add("now", new DateTime(2006, 8, 11, 12, 49, 0));
            Assert.AreEqual(PofConstants.T_MAP, PofHelper.GetPofTypeId(ht.GetType(), new SimplePofContext()));

            ICollection ll = new LinkedList <double>();

            Assert.AreEqual(PofConstants.T_COLLECTION, PofHelper.GetPofTypeId(ll.GetType(), new SimplePofContext()));

            Binary bin = new Binary(new byte[] { 1, 2, 3 });

            Assert.AreEqual(PofConstants.T_OCTET_STRING, PofHelper.GetPofTypeId(bin.GetType(), new SimplePofContext()));

            SimplePofContext ctx = new SimplePofContext();

            Assert.AreEqual(PofConstants.T_OCTET_STRING, PofHelper.GetPofTypeId(typeof(byte[]), ctx));
            Assert.AreEqual(PofConstants.T_ARRAY, PofHelper.GetPofTypeId(typeof(object[]), ctx));
            Assert.AreEqual(PofConstants.T_ARRAY, PofHelper.GetPofTypeId(typeof(string[]), ctx));

            ctx.RegisterUserType(1000, typeof(string[]), new PortableObjectSerializer(1000));

            Assert.AreEqual(PofConstants.T_OCTET_STRING, PofHelper.GetPofTypeId(typeof(byte[]), ctx));
            Assert.AreEqual(PofConstants.T_ARRAY, PofHelper.GetPofTypeId(typeof(object[]), ctx));
            Assert.AreEqual(1000, PofHelper.GetPofTypeId(typeof(string[]), ctx));
        }
Exemplo n.º 12
0
        public void TestConfigPofContextException()
        {
            LikeFilter filter = new LikeFilter("field", "goran", '\\', false);

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

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

            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), filter);
        }
        public void testNestedType()
        {
            m_ctx = new SimplePofContext();
            ((SimplePofContext)m_ctx).RegisterUserType(101, typeof(NestedTypeWithReference), new PortableObjectSerializer(101));
            ((SimplePofContext)m_ctx).RegisterUserType(102, typeof(PortablePerson), new PortableObjectSerializer(102));

            var tv = new NestedTypeWithReference();

            initPOFWriter();
            m_pofWriter.EnableReference();
            m_pofWriter.WriteObject(0, tv);

            initPOFReader();
            var result = (NestedTypeWithReference)m_pofReader.ReadObject(0);
        }
        public void TestGenerics()
        {
            SimplePofContext cxt = new SimplePofContext();

            cxt.RegisterUserType(1001, typeof(PersonV1), new PofAnnotationSerializer(1001, typeof(PersonV1)));

            PersonV1 value = new PersonV1("Frank", "Spencer", 57);

            PersonV1 teleported = EH.FromBinary(EH.ToBinary(value, cxt), cxt) as PersonV1;

            Assert.IsNotNull(teleported);
            Assert.AreEqual("Frank", teleported.m_firstName);
            Assert.AreEqual("Spencer", teleported.m_lastName);
            Assert.AreEqual(57, teleported.m_age);
        }
Exemplo n.º 15
0
        public SerializationPerformanceComparisonTests()
        {
            pofSerializer = new SimplePofContext();

            ConfigurePofContext();
            emptyObject     = CreateEmptyObjectInstance();
            populatedObject = CreatePopulatedObjectInstance();
            typeName        = emptyObject.GetType().FullName;

            binarySerializer = new BinaryFormatter();
            jsonSerializer   = new JavaScriptSerializer(new SimpleTypeResolver());
            xmlSerializer    = new XmlSerializer(emptyObject.GetType());
            dcSerializer     = new DataContractSerializer(emptyObject.GetType());
            dcJsonSerializer = new DataContractJsonSerializer(emptyObject.GetType());
        }
        public void TestSerializationWithSkippingReadingType()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(SkippingPersonLite), new PortableObjectSerializer(1));

            SkippingPersonLite ana = new SkippingPersonLite("Ana Maria Seovic", new DateTime(2006, 8, 14));

            Stream stream = new MemoryStream();

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

            stream.Position = 0;
            SkippingPersonLite ana2 = (SkippingPersonLite)ctx.Deserialize(new DataReader(stream));
        }
        public void TestReferencesInUniformMap()
        {
            var localCtx = new SimplePofContext();

            localCtx.RegisterUserType(101, typeof(PortablePerson),
                                      new PortableObjectSerializer(101));
            localCtx.RegisterUserType(102, typeof(PortablePersonReference),
                                      new PortableObjectSerializer(102));
            localCtx.RegisterUserType(201, typeof(CompositeKey),
                                      new PortableObjectSerializer(201));

            IDictionary  mapPerson = new Dictionary <CompositeKey, IPortableObject>();
            const String lastName  = "Smith";
            CompositeKey key1      = new CompositeKey(lastName, "ivan"),
                         key2      = new CompositeKey(lastName, "goran");
            var ivan = new PortablePersonReference("Ivan", new DateTime(78, 4, 25));

            ivan.Children = null;
            mapPerson.Add(key1, ivan);
            mapPerson.Add(key2, ivan);

            initPOFWriter();
            m_pofWriter = new PofStreamWriter(m_writer, localCtx);
            m_pofWriter.EnableReference();
            m_pofWriter.WriteDictionary(0, mapPerson, typeof(CompositeKey),
                                        typeof(PortablePersonReference));

            var mapPersonR = new Dictionary <CompositeKey, IPortableObject>();

            initPOFReader();
            m_pofReader = new PofStreamReader(m_reader, localCtx);
            m_pofReader.ReadDictionary(0, (IDictionary)mapPersonR);

            // compare mapPerson with result
            Assert.IsTrue(mapPersonR[key1].Equals(mapPerson[key1]));
            Assert.IsTrue(mapPersonR[key2].Equals(mapPerson[key2]));

            ICollection colValR = mapPersonR.Values;
            IEnumerator iter    = colValR.GetEnumerator();

            iter.MoveNext();
            var val1 = (PortablePersonReference)iter.Current;

            iter.MoveNext();
            var val2 = (PortablePersonReference)iter.Current;

            Assert.IsTrue(val1 == val2);
        }
        public void TestEvolvableObjectSerialization()
        {
            SimplePofContext ctx_v1 = new SimplePofContext();

            ctx_v1.RegisterUserType(1, typeof(EvolvablePortablePerson), new PortableObjectSerializer(1));
            ctx_v1.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            SimplePofContext ctx_v2 = new SimplePofContext();

            ctx_v2.RegisterUserType(1, typeof(EvolvablePortablePerson2), new PortableObjectSerializer(1));
            ctx_v2.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            EvolvablePortablePerson2 aleks = new EvolvablePortablePerson2("Aleksandar Seovic", new DateTime(1974, 8, 24));
            EvolvablePortablePerson2 ana   = new EvolvablePortablePerson2("Ana Maria Seovic", new DateTime(2004, 8, 14, 7, 43, 0));

            aleks.Address      = ana.Address = new Address("208 Myrtle Ridge Rd", "Lutz", "FL", "33549");
            aleks.Nationality  = ana.Nationality = "Serbian";
            aleks.PlaceOfBirth = new Address(null, "Belgrade", "Serbia", "11000");
            ana.PlaceOfBirth   = new Address("128 Asbury Ave, #401", "Evanston", "IL", "60202");
            aleks.Children     = new EvolvablePortablePerson2[] { ana };

            Stream stream_v2 = new MemoryStream();

            ctx_v2.Serialize(new DataWriter(stream_v2), aleks);

            stream_v2.Position = 0;
            EvolvablePortablePerson aleks_v1 = (EvolvablePortablePerson)ctx_v1.Deserialize(new DataReader(stream_v2));

            EvolvablePortablePerson marija_v1 = new EvolvablePortablePerson("Marija Seovic", new DateTime(1978, 2, 20));

            marija_v1.Address  = aleks_v1.Address;
            marija_v1.Children = aleks_v1.Children;
            aleks_v1.Spouse    = marija_v1;

            Stream stream_v1 = new MemoryStream();

            ctx_v1.Serialize(new DataWriter(stream_v1), aleks_v1);

            stream_v1.Position = 0;
            EvolvablePortablePerson2 aleks_v2 = (EvolvablePortablePerson2)ctx_v2.Deserialize(new DataReader(stream_v1));

            Assert.AreEqual(aleks.Name, aleks_v2.Name);
            Assert.AreEqual(aleks.Nationality, aleks_v2.Nationality);
            Assert.AreEqual(aleks.DOB, aleks_v2.DOB);
            Assert.AreEqual(aleks_v1.Spouse.Name, aleks_v2.Spouse.Name);
            Assert.AreEqual(aleks.Address.City, aleks_v2.Address.City);
            Assert.AreEqual(aleks.PlaceOfBirth.City, aleks_v2.PlaceOfBirth.City);
        }
        public void TestInheritance()
        {
            var cxt = new SimplePofContext();

            cxt.RegisterUserType(1001, typeof(PersonV1), new PofAnnotationSerializer(1001, typeof(PersonV1)));
            cxt.RegisterUserType(1005, typeof(BewilderedPerson), new PofAnnotationSerializer(1005, typeof(BewilderedPerson), true));

            var value      = new BewilderedPerson("Frank", "Spencer", 57, "dizzy");
            var teleported = EH.FromBinary(EH.ToBinary(value, cxt), cxt) as BewilderedPerson;

            Assert.IsNotNull(teleported);
            Assert.AreEqual("Frank", teleported.m_firstName);
            Assert.AreEqual("Spencer", teleported.m_lastName);
            Assert.AreEqual(57, teleported.m_age);
            Assert.AreEqual("dizzy", teleported.m_state);
        }
Exemplo n.º 20
0
        public void Setup()
        {
            V1 = new SimplePofContext();
            V1.RegisterUserType(1, typeof(Test.V1.Pet),
                                new PortableTypeSerializer(1, typeof(Test.V1.Pet)));
            V1.RegisterUserType(2, typeof(Test.V1.Dog),
                                new PortableTypeSerializer(2, typeof(Test.V1.Dog)));

            V2 = new SimplePofContext();
            V2.RegisterUserType(1, typeof(Test.V2.Pet),
                                new PortableTypeSerializer(1, typeof(Test.V2.Pet)));
            V2.RegisterUserType(2, typeof(Test.V2.Dog),
                                new PortableTypeSerializer(2, typeof(Test.V2.Dog)));
            V2.RegisterUserType(3, typeof(Test.V2.Animal),
                                new PortableTypeSerializer(3, typeof(Test.V2.Animal)));
            V2.RegisterUserType(5, typeof(Color), new EnumPofSerializer());
        }
        public void TestTypeRegistration()
        {
            SimplePofContext         ctx        = new SimplePofContext();
            PortableObjectSerializer serializer = new PortableObjectSerializer(1);

            ctx.RegisterUserType(1, this.GetType(), serializer);
            ctx.RegisterUserType(2, typeof(IPortableObject), new PortableObjectSerializer(2));

            Assert.AreEqual(1, ctx.GetUserTypeIdentifier(this));
            Assert.AreEqual(1, ctx.GetUserTypeIdentifier(this.GetType()));
            Assert.AreEqual(1, ctx.GetUserTypeIdentifier(this.GetType().AssemblyQualifiedName));

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

            ctx.UnregisterUserType(1);
            ctx.UnregisterUserType(2);
        }
        public void TestSerialization()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(PortablePerson), new PortableObjectSerializer(1));
            ctx.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            PortablePerson aleks  = new PortablePerson("Aleksandar Seovic", new DateTime(1974, 8, 24));
            PortablePerson marija = new PortablePerson("Marija Seovic", new DateTime(1978, 2, 20));
            PortablePerson ana    = new PortablePerson("Ana Maria Seovic", new DateTime(2004, 8, 14, 7, 43, 0));

            aleks.Spouse   = marija;
            aleks.Address  = marija.Address = ana.Address = new Address("208 Myrtle Ridge Rd", "Lutz", "FL", "33549");
            aleks.Children = marija.Children = new PortablePerson[] { ana };

            Stream stream = new MemoryStream();

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

            stream.Position = 0;
            PortablePerson aleks2 = (PortablePerson)ctx.Deserialize(new DataReader(stream));

            Assert.AreEqual(aleks.Name, aleks2.Name);
            Assert.AreEqual(aleks.DOB, aleks2.DOB);
            Assert.AreEqual(aleks.Spouse.Name, aleks2.Spouse.Name);
            Assert.AreEqual(aleks.Address.City, aleks2.Address.City);
            Assert.AreEqual(1, aleks2.Children.Length);
            Assert.AreEqual(ana.Name, aleks2.Children[0].Name);
            Assert.AreEqual(ana.Address.Street, aleks2.Children[0].Address.Street);

            SimplePofContext liteCtx = new SimplePofContext();

            liteCtx.RegisterUserType(1, typeof(PortablePersonLite), new PortableObjectSerializer(1));
            liteCtx.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            stream.Position = 0;
            PortablePersonLite aleks3 = (PortablePersonLite)liteCtx.Deserialize(new DataReader(stream));

            Assert.AreEqual(aleks.Name, aleks3.Name);
            Assert.AreEqual(aleks.DOB, aleks3.DOB);
        }
Exemplo n.º 23
0
        public void SetUp()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(101,
                                 typeof(DictionaryTestClass <Int32, String>),
                                 new PortableObjectSerializer(101));

            ctx.RegisterUserType(102,
                                 typeof(DictionaryTestClass <String, Int32>),
                                 new PortableObjectSerializer(102));

            ctx.RegisterUserType(103,
                                 typeof(CollectionTestClass <Int32>),
                                 new PortableObjectSerializer(103));

            ctx.RegisterUserType(104,
                                 typeof(DictionaryTestClass <int, object>),
                                 new PortableObjectSerializer(104));
            m_serializer = ctx;
        }
Exemplo n.º 24
0
        public void TestDotNetTypeID()
        {
            SimplePofContext ctx = new SimplePofContext();

            object o = new byte[0];

            Assert.AreEqual(PofConstants.N_BYTE_ARRAY, PofHelper.GetDotNetTypeId(o, ctx));

            o = new object[0];
            Assert.AreEqual(PofConstants.N_OBJECT_ARRAY, PofHelper.GetDotNetTypeId(o, ctx));

            o = new string[0];
            Assert.AreEqual(PofConstants.N_OBJECT_ARRAY, PofHelper.GetDotNetTypeId(o, ctx));

            ctx.RegisterUserType(1000, o.GetType(), new PortableObjectSerializer(1000));
            o = new object[0];
            Assert.AreEqual(PofConstants.N_OBJECT_ARRAY, PofHelper.GetDotNetTypeId(o, ctx));

            o = new string[0];
            Assert.AreEqual(PofConstants.N_USER_TYPE, PofHelper.GetDotNetTypeId(o, ctx));
        }
Exemplo n.º 25
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]);
        }
        public void testCircularReferences()
        {
            var ctx = new SimplePofContext();

            ctx.RegisterUserType(101, typeof(PortablePerson),
                                 new PortableObjectSerializer(101));
            ctx.RegisterUserType(102, typeof(PortablePersonReference),
                                 new PortableObjectSerializer(102));

            var ivan = new PortablePersonReference("Ivan", new DateTime(78, 4, 25));

            ivan.Children    = new PortablePerson[1];
            ivan.Children[0] = new PortablePerson("Mary Jane", new DateTime(97, 8, 14));
            ivan.Spouse      = new PortablePerson("Eda", new DateTime(79, 6, 25));

            var goran = new PortablePersonReference("Goran", new DateTime(82, 3, 3));

            goran.Children    = new PortablePerson[2];
            goran.Children[0] = new PortablePerson("Tom", new DateTime(103, 7, 5));
            goran.Children[1] = new PortablePerson("Ellen", new DateTime(105, 3, 15));
            goran.Spouse      = new PortablePerson("Tiffany", new DateTime(82, 3, 25));
            goran.Friend      = ivan;
            ivan.Friend       = goran;

            initPOFWriter();
            m_pofWriter = new PofStreamWriter(m_writer, ctx);
            m_pofWriter.EnableReference();
            m_pofWriter.WriteObject(0, ivan);

            initPOFReader();
            m_pofReader = new PofStreamReader(m_reader, ctx);

            var ivanR = (PortablePersonReference)m_pofReader.ReadObject(0);

            Assert.IsTrue(ivanR.Name.Equals(ivan.Name));
            Assert.IsTrue(ivanR.Children.Length == 1);
            Assert.IsTrue(ivanR.Friend.Equals(goran));
        }
        public void TestDeserializationException()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.RegisterUserType(1, typeof(PortablePerson), new PortableObjectSerializer(1));
            ctx.RegisterUserType(2, typeof(Address), new PortableObjectSerializer(2));

            PortablePerson aleks  = new PortablePerson("Aleksandar Seovic", new DateTime(1974, 8, 24));
            PortablePerson marija = new PortablePerson("Marija Seovic", new DateTime(1978, 2, 20));
            PortablePerson ana    = new PortablePerson("Ana Maria Seovic", new DateTime(2004, 8, 14, 7, 43, 0));

            aleks.Spouse   = marija;
            aleks.Address  = marija.Address = ana.Address = new Address("208 Myrtle Ridge Rd", "Lutz", "FL", "33549");
            aleks.Children = marija.Children = new PortablePerson[] { ana };

            Stream stream = new MemoryStream();

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

            stream.Position = 0;
            stream.Close();
            PortablePerson aleks2 = (PortablePerson)ctx.Deserialize(new DataReader(stream));
        }
        public void TestAncestry()
        {
            SimplePofContext cxt = new SimplePofContext();

            cxt.RegisterUserType(1002, typeof(GrandFather), new PofAnnotationSerializer(1002, typeof(GrandFather), true));
            cxt.RegisterUserType(1003, typeof(Father), new PofAnnotationSerializer(1003, typeof(Father), true));
            cxt.RegisterUserType(1004, typeof(Child), new PofAnnotationSerializer(1004, typeof(Child), true));

            var son = new Child("Bart", "Simpson", 10);
            var dad = new Father("Homer", "Simpson", 50, son);
            var gf  = new GrandFather("Abe", "Simpson", 100, dad);

            var teleported = (GrandFather)EH.FromBinary(EH.ToBinary(gf, cxt), cxt);

            Assert.AreEqual("Abe", teleported.m_firstName);
            Assert.AreEqual("Simpson", teleported.m_lastName);
            Assert.AreEqual(100, teleported.m_age);
            Assert.AreEqual("Homer", teleported.m_father.m_firstName);
            Assert.AreEqual("Simpson", teleported.m_father.m_lastName);
            Assert.AreEqual(50, teleported.m_father.m_age);
            Assert.AreEqual("Bart", teleported.m_father.m_child.m_firstName);
            Assert.AreEqual("Simpson", teleported.m_father.m_child.m_lastName);
            Assert.AreEqual(10, teleported.m_father.m_child.m_age);
        }
        public void TestXmlPofSerializer()
        {
            MemoryStream     stream        = new MemoryStream();
            DataWriter       writer        = new DataWriter(stream);
            XmlPofSerializer xmlSerializer = new XmlPofSerializer(1);
            SimplePofContext context       = new SimplePofContext();

            context.RegisterUserType(1, typeof(DataSet), xmlSerializer);

            // create test DataSet
            DataSet set = CreateTestDataSet();

            // serialize DataSet
            context.Serialize(writer, set);

            // deserialize DataSet
            stream.Seek(0, SeekOrigin.Begin);
            DataReader reader   = new DataReader(stream);
            object     deserObj = context.Deserialize(reader);

            Assert.IsInstanceOf(typeof(DataSet), deserObj);
            DataSet deserDS = (DataSet)deserObj;

            // Assert tables
            Assert.AreEqual(set.Tables.Count, deserDS.Tables.Count);
            for (int i = 0; i < set.Tables.Count; i++)
            {
                DataTable table      = set.Tables[i];
                DataTable deserTable = deserDS.Tables[i];
                Assert.AreEqual(table.TableName, deserTable.TableName);
                Assert.AreEqual(table.Columns.Count, deserTable.Columns.Count);

                for (int j = 0, c = table.Columns.Count; j < c; j++)
                {
                    DataColumn column1 = table.Columns[j];
                    DataColumn column2 = deserTable.Columns[j];
                    Assert.AreEqual(column1.ColumnName, column2.ColumnName);
                    Assert.AreEqual(column1.DataType, column2.DataType);
                    Assert.AreEqual(column1.Unique, column2.Unique);
                }

                Assert.AreEqual(table.Rows.Count, deserTable.Rows.Count);
                for (int k = 0, r = table.Rows.Count; k < r; k++)
                {
                    DataRow row1 = table.Rows[k];
                    DataRow row2 = deserTable.Rows[k];
                    for (int m = 0, c = table.Columns.Count; m < c; m++)
                    {
                        Assert.AreEqual(row1[m], row2[m]);
                    }
                }
            }

            // Assert relations
            Assert.AreEqual(set.Relations.Count, deserDS.Relations.Count);
            for (int i = 0; i < set.Relations.Count; i++)
            {
                DataColumn[] parentColumns1 = set.Relations[i].ParentColumns;
                DataColumn[] parentColumns2 = deserDS.Relations[i].ParentColumns;
                Assert.AreEqual(parentColumns1.Length, parentColumns2.Length);
                for (int j = 0; j < parentColumns1.Length; j++)
                {
                    Assert.AreEqual(parentColumns1[j].ColumnName, parentColumns2[j].ColumnName);
                }

                DataColumn[] childColumns1 = set.Relations[i].ChildColumns;
                DataColumn[] childColumns2 = deserDS.Relations[i].ChildColumns;
                Assert.AreEqual(childColumns1.Length, childColumns2.Length);
                for (int j = 0; j < childColumns1.Length; j++)
                {
                    Assert.AreEqual(childColumns1[j].ColumnName, childColumns2[j].ColumnName);
                }
            }
        }
        public void TestGetUserTypeIdentifierWithNullObject()
        {
            SimplePofContext ctx = new SimplePofContext();

            ctx.GetUserTypeIdentifier((object)null);
        }