public void DictionaryEvents() { SerializationEventTestDictionary obj = new SerializationEventTestDictionary { { 1.1m, "first" }, { 2.222222222m, "second" }, { int.MaxValue, "third" }, { Convert.ToDecimal(Math.PI), "fourth" } }; Assert.AreEqual(11, obj.Member1); Assert.AreEqual("Hello World!", obj.Member2); Assert.AreEqual("This is a nonserialized value", obj.Member3); Assert.AreEqual(null, obj.Member4); string json = JsonConvert.SerializeObject(obj, Formatting.Indented); StringAssert.AreEqual( @"{ ""1.1"": ""first"", ""2.222222222"": ""second"", ""2147483647"": ""third"", ""3.14159265358979"": ""fourth"", ""79228162514264337593543950335"": ""Inserted on serializing"" }", json ); Assert.AreEqual(11, obj.Member1); Assert.AreEqual("This value was reset after serialization.", obj.Member2); Assert.AreEqual("This is a nonserialized value", obj.Member3); Assert.AreEqual(null, obj.Member4); obj = JsonConvert.DeserializeObject <SerializationEventTestDictionary>(json); Assert.AreEqual(11, obj.Member1); Assert.AreEqual("Hello World!", obj.Member2); Assert.AreEqual("This value was set during deserialization", obj.Member3); Assert.AreEqual("This value was set after deserialization.", obj.Member4); }
public void DictionaryEvents() { SerializationEventTestDictionary obj = new SerializationEventTestDictionary { { 1.1m, "first" }, { 2.222222222m, "second" }, { int.MaxValue, "third" }, { Convert.ToDecimal(Math.PI), "fourth" } }; Assert.AreEqual(11, obj.Member1); Assert.AreEqual("Hello World!", obj.Member2); Assert.AreEqual("This is a nonserialized value", obj.Member3); Assert.AreEqual(null, obj.Member4); string json = JsonConvert.SerializeObject(obj, Formatting.Indented); StringAssert.AreEqual(@"{ ""1.1"": ""first"", ""2.222222222"": ""second"", ""2147483647"": ""third"", ""3.14159265358979"": ""fourth"", ""79228162514264337593543950335"": ""Inserted on serializing"" }", json); Assert.AreEqual(11, obj.Member1); Assert.AreEqual("This value was reset after serialization.", obj.Member2); Assert.AreEqual("This is a nonserialized value", obj.Member3); Assert.AreEqual(null, obj.Member4); obj = JsonConvert.DeserializeObject<SerializationEventTestDictionary>(json); Assert.AreEqual(11, obj.Member1); Assert.AreEqual("Hello World!", obj.Member2); Assert.AreEqual("This value was set during deserialization", obj.Member3); Assert.AreEqual("This value was set after deserialization.", obj.Member4); }