Exemplo n.º 1
0
 public void Deserialize_BeforeSerializing_Exception()
 {
     using (var subject = new BinaryRoundtripSerializer <Serializable>())
     {
         Assert.That(() => subject.Deserialize(), Throws.InstanceOf <SerializationException>());
     }
 }
 public void Serialize_NonSerializableType_Exception()
 {
     using (var subject = new BinaryRoundtripSerializer<NonSerializable>())
     {
         Assert.That(() => subject.Serialize(new NonSerializable("s")), Throws.InstanceOf<SerializationException>());
     }
 }
Exemplo n.º 3
0
 public void Serialize_NonSerializableType_Exception()
 {
     using (var subject = new BinaryRoundtripSerializer <NonSerializable>())
     {
         Assert.That(() => subject.Serialize(new NonSerializable("s")), Throws.InstanceOf <SerializationException>());
     }
 }
 public void Deserialize_BeforeSerializing_Exception()
 {
     using (var subject = new BinaryRoundtripSerializer<Serializable>())
     {
         Assert.That(() => subject.Deserialize(), Throws.InstanceOf<SerializationException>());
     }
 }
 public void BinaryDeserialization_DoesNotPreservesInstanceUniqueness()
 {
     using (var serializer = new BinaryRoundtripSerializer <Currency>())
     {
         Currency usd = Currency.Get("USD");
         serializer.Serialize(usd);
         Assert.That(serializer.Deserialize(), Is.EqualTo(usd));
     }
 }
 public void BinaryDeserialization_OfObsoleteCurrency_DoesNotRaiseEvent(CurrencyIsoCode obsolete)
 {
     using (var serializer = new BinaryRoundtripSerializer <CurrencyIsoCode>())
     {
         serializer.Serialize(obsolete);
         Action deserializeObsolete = () => serializer.Deserialize();
         Assert.That(deserializeObsolete, Must.Not.Raise.ObsoleteEvent());
     }
 }
        public void Serialize_SerializableType_AStringRepresentationOfSerializedObject()
        {
            using (var subject = new BinaryRoundtripSerializer<Serializable>())
            {
                string representation = subject.Serialize(new Serializable { S = "s", D = 3m });

                Assert.That(representation, Does.Contain(".Serializable"));
            }
        }
 public void BinaryDeserialization_OfObsoleteCurrency_RaisesEvent(string threeLetterIsoCode)
 {
     using (var serializer = new BinaryRoundtripSerializer <Currency>())
     {
         var obsolete = Currency.Get(threeLetterIsoCode);
         serializer.Serialize(obsolete);
         Action deserializeObsolete = () => serializer.Deserialize();
         Assert.That(deserializeObsolete, Must.Raise.ObsoleteEvent());
     }
 }
 public void BinaryDeserialization_DoesNotPreservesInstanceUniqueness()
 {
     using (var serializer = new BinaryRoundtripSerializer <CurrencyIsoCode>())
     {
         CurrencyIsoCode usd = CurrencyIsoCode.USD;
         serializer.Serialize(CurrencyIsoCode.USD);
         Assert.That(serializer.Deserialize(), Is.Not.SameAs(usd)
                     .And.EqualTo(usd));
     }
 }
Exemplo n.º 10
0
        public void Serialize_SerializableType_AStringRepresentationOfSerializedObject()
        {
            using (var subject = new BinaryRoundtripSerializer <Serializable>())
            {
                string representation = subject.Serialize(new Serializable {
                    S = "s", D = 3m
                });

                Assert.That(representation, Does.Contain(".Serializable"));
            }
        }
        public void BinarySerialization_OfDefaultInstance_StoresAndDeserializesNoCurrency()
        {
            var @default = new Money();

            using (var serializer = new BinaryRoundtripSerializer <Money>())
            {
                serializer.Serialize(@default);

                Money deserialized = serializer.Deserialize();

                Assert.That(deserialized, Must.Be.MoneyWith(0m, Currency.Xxx));
            }
        }
        public void Deserialize_AfterSerializingSerializableType_InitialObject()
        {
            using (var subject = new BinaryRoundtripSerializer<Serializable>())
            {
                var serialized = new Serializable { S = "s", D = 3m };
                subject.Serialize(serialized);

                Serializable deserialized = subject.Deserialize();

                Assert.That(deserialized, Is.Not.SameAs(serialized)
                    .And.Property("S").EqualTo("s")
                    .And.Property("D").EqualTo(3m));
            }
        }
Exemplo n.º 13
0
        public void Deserialize_AfterSerializingSerializableType_InitialObject()
        {
            using (var subject = new BinaryRoundtripSerializer <Serializable>())
            {
                var serialized = new Serializable {
                    S = "s", D = 3m
                };
                subject.Serialize(serialized);

                Serializable deserialized = subject.Deserialize();

                Assert.That(deserialized, Is.Not.SameAs(serialized)
                            .And.Property("S").EqualTo("s")
                            .And.Property("D").EqualTo(3m));
            }
        }