public void WillNotSerializeFields() { var serializer = new DocumentConvention().CreateSerializer(); var stringWriter = new StringWriter(); serializer.Serialize(stringWriter, new Company("Hibernating Rhinos", "Middle East")); var s = stringWriter.GetStringBuilder().ToString(); Assert.DoesNotContain("k__BackingField", s); }
public void CanSerializeToJsonCorrectly() { var serializer = new DocumentConvention().CreateSerializer(); var stringWriter = new StringWriter(); serializer.Serialize(stringWriter, new Company("Hibernating Rhinos", "Middle East")); var deserializeObject = serializer.Deserialize<Company>(new JsonTextReader(new StringReader(stringWriter.GetStringBuilder().ToString()))); Assert.Equal("Hibernating Rhinos", deserializeObject.Name); Assert.Equal("Middle East", deserializeObject.Region); }
public void CanBeSerializedProperly() { var jsonSerializer = new DocumentConvention().CreateSerializer(); var stringWriter = new StringWriter(); var item = new WithDic { Items = new Dictionary<DateTime, int> { {new DateTime(2011, 11, 24), 1} } }; jsonSerializer.Serialize(stringWriter, item); var s = stringWriter.GetStringBuilder().ToString(); Assert.Equal("{\"Items\":{\"2011-11-24T00:00:00.0000000+02:00\":1}}", s); }
public void CanBeDeSerializedProperly() { var jsonSerializer = new DocumentConvention().CreateSerializer(); var stringWriter = new StringWriter(); var item = new WithDic { Items = new Dictionary<DateTime, int> { {new DateTime(2011, 11, 24), 1} } }; jsonSerializer.Serialize(stringWriter, item); var s = stringWriter.GetStringBuilder().ToString(); var withDic = jsonSerializer.Deserialize<WithDic>(new JsonTextReader(new StringReader(s))); Assert.Equal(1, withDic.Items[new DateTime(2011, 11, 24)]); }