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

                Assert.That(representation, Does.Contain("__BackingField")
                    .And.Contain(">3<")
                    .And.Contain(">s<"));
            }
        }
        public void DataContractDeserialization_OfObsoleteCurrency_DoesNotRaiseEvent()
        {
            using (var serializer = new DataContractRoundtripSerializer <CurrencyIsoCode>())
            {
#pragma warning disable 618
                var obsolete = CurrencyIsoCode.EEK;
#pragma warning restore 618
                serializer.Serialize(obsolete);
                Action deserializeObsolete = () => serializer.Deserialize();
                Assert.That(deserializeObsolete, Must.Not.Raise.ObsoleteEvent());
            }
        }
        public void DatacontractSerialization_OfDefaultInstance_StoresAndDeserializesNoCurrency()
        {
            var @default = new Money();

            var serializer = new DataContractRoundtripSerializer <Money>();

            serializer.Serialize(@default);

            Money deserialized = serializer.Deserialize();

            Assert.That(deserialized, Must.Be.MoneyWith(0m, Currency.Xxx));
        }
Exemplo n.º 8
0
        public void Serialize_SerializableType_AStringRepresentationOfSerializedObject()
        {
            using (var subject = new DataContractRoundtripSerializer <Serializable>())
            {
                string representation = subject.Serialize(new Serializable {
                    S = "s", D = 3m
                });

                Assert.That(representation, Does.Contain("S").And.Contain("D")
                            .And.Contain(">3<")
                            .And.Contain(">s<"));
            }
        }
Exemplo n.º 9
0
        public void Serialization_OutOfTheBox_NotLikeCanonicalJsonSerialization()
        {
            _proxy.Serializer = _proxy.Default;

            using (var serializer = new DataContractRoundtripSerializer <Money>())
            {
                var toSerialize = new Money(14.3m, CurrencyIsoCode.XTS);

                string @default = toSerialize.ToJson();

                string canonical = serializer.Serialize(toSerialize);
                Assert.That(@default, Is.Not.EqualTo(canonical));
            }
        }
        public void Deserialize_AfterSerializingSerializableType_InitialObject()
        {
            using (var subject = new DataContractRoundtripSerializer<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.º 11
0
        public void Deserialize_AfterSerializingSerializableType_InitialObject()
        {
            using (var subject = new DataContractRoundtripSerializer <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));
            }
        }