コード例 #1
0
        public void XmlSerialization_SerializePersonB()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  partner  = new PersonA(@"Kate", @"Moss", addressA);
            PersonA  personB  = new PersonB(@"Bob", @"Bones", addressA, partner);
            string   xmlData  = SerializationHelper.SerializeToXmlString(personB);

            Assert.IsNotNull(xmlData);
            Assert.IsTrue(xmlData.Length > 0);
            PersonB deserializedPersonB = SerializationHelper.DeserializeFromXmlString <PersonB>(xmlData);

            Assert.AreEqual(personB, deserializedPersonB);
        }
コード例 #2
0
        public void CompressedByteArray_SerializePersonB()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  partner  = new PersonA(@"Kate", @"Moss", addressA);
            PersonA  personB  = new PersonB(@"Bob", @"Bones", addressA, partner);

            byte[] data = SerializationHelper.SerializeToBytes(personB, true);
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
            PersonB deserializedPersonB = SerializationHelper.DeserializeFromBytes <PersonB>(data, true);

            Assert.AreEqual(personB, deserializedPersonB);
        }
コード例 #3
0
        public void XmlSerialization_SerializePersonBUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  partner = new PersonA(@"Kate", @"Moss", address);
            IPerson  person  = new PersonB(@"Bob", @"Bones", address, partner);
            string   xmlData = SerializationHelper.SerializeToXmlString(person);

            Assert.IsNotNull(xmlData);
            Assert.IsTrue(xmlData.Length > 0);
            IPerson deserializedPerson = SerializationHelper.DeserializeFromXmlString <IPerson>(xmlData);

            Assert.AreEqual(person, deserializedPerson);
            Assert.IsInstanceOf <PersonB>(person);
        }
コード例 #4
0
        public void CompressedByteArray_SerializePersonBUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  partner = new PersonA(@"Kate", @"Moss", address);
            IPerson  person  = new PersonB(@"Bob", @"Bones", address, partner);

            byte[] data = SerializationHelper.SerializeToBytes(person, true);
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
            IPerson deserializedPerson = SerializationHelper.DeserializeFromBytes <IPerson>(data, true);

            Assert.AreEqual(person, deserializedPerson);
            Assert.IsInstanceOf <PersonB>(person);
        }
コード例 #5
0
        public void Stream_SerializePersonB()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  partner  = new PersonA(@"Kate", @"Moss", addressA);
            PersonA  personB  = new PersonB(@"Bob", @"Bones", addressA, partner);

            using (Stream stream = new MemoryStream())
            {
                SerializationHelper.Serialize(stream, personB);
                Assert.IsTrue(stream.Length > 0);
                stream.Position = 0;
                PersonA deserializedPersonB = SerializationHelper.Deserialize <PersonA>(stream);
                Assert.AreEqual(personB, deserializedPersonB);
            }
        }
コード例 #6
0
        public void Stream_SerializePersonBUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  partner = new PersonA(@"Kate", @"Moss", address);
            IPerson  person  = new PersonB(@"Bob", @"Bones", address, partner);

            using (Stream stream = new MemoryStream())
            {
                SerializationHelper.Serialize(stream, person);
                Assert.IsTrue(stream.Length > 0);
                stream.Position = 0;
                IPerson deserializedPerson = SerializationHelper.Deserialize <IPerson>(stream);
                Assert.AreEqual(person, deserializedPerson);
                Assert.IsInstanceOf <PersonA>(person);
            }
        }