Exemple #1
0
        public void CompressedStream_SerializePersonA()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  personA  = new PersonA(@"Bob", @"Bones", addressA);

            byte[] memory;

            using (MemoryStream stream = new MemoryStream())
                using (Stream compressed = Compression.CompressingStream(stream))
                {
                    SerializationHelper.Serialize(compressed, personA);
                    Assert.IsTrue(stream.Length > 0);
                    memory = stream.ToArray();
                }

            PersonA deserializedPersonA;

            using (Stream stream = new MemoryStream(memory))
                using (Stream decompressed = Compression.DecompressingStream(stream))
                {
                    deserializedPersonA = SerializationHelper.Deserialize <PersonA>(decompressed);
                }

            Assert.AreEqual(personA, deserializedPersonA);
        }
Exemple #2
0
        public void ByteArray_SerializePersonA()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  personA  = new PersonA(@"Bob", @"Bones", addressA);

            byte[] data = SerializationHelper.SerializeToBytes(personA);
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
            PersonA deserializedPersonA = SerializationHelper.DeserializeFromBytes <PersonA>(data);

            Assert.AreEqual(personA, deserializedPersonA);
        }
Exemple #3
0
        public void XmlSerialization_SerializePersonA()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  personA  = new PersonA(@"Bob", @"Bones", addressA);
            string   xmlData  = SerializationHelper.SerializeToXmlString(personA);

            Assert.IsNotNull(xmlData);
            Assert.IsTrue(xmlData.Length > 0);
            PersonA deserializedPersonA = SerializationHelper.DeserializeFromXmlString <PersonA>(xmlData);

            Assert.AreEqual(personA, deserializedPersonA);
        }
Exemple #4
0
        public void XmlSerialization_SerializePersonAUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  person  = new PersonA(@"Bob", @"Bones", address);
            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 <PersonA>(person);
        }
Exemple #5
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);
        }
Exemple #6
0
        public void CompressedByteArray_SerializePersonAUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  person  = new PersonA(@"Bob", @"Bones", address);

            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 <PersonA>(person);
        }
Exemple #7
0
        public void Stream_SerializePersonA()
        {
            AddressA addressA = new AddressA(@"CornerStreet", @"00501", @"New york");
            PersonA  personA  = new PersonA(@"Bob", @"Bones", addressA);

            using (Stream stream = new MemoryStream())
            {
                SerializationHelper.Serialize(stream, personA);
                Assert.IsTrue(stream.Length > 0);
                stream.Position = 0;
                PersonA deserializedPersonA = SerializationHelper.Deserialize <PersonA>(stream);
                Assert.AreEqual(personA, deserializedPersonA);
            }
        }
Exemple #8
0
        public void Stream_SerializePersonAUsingAnInterface()
        {
            IAddress address = new AddressA(@"CornerStreet", @"00501", @"New york");
            IPerson  person  = new PersonA(@"Bob", @"Bones", address);

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