public void ShouldSerializeObjectWithTypeName() { var target = new SerializationTestTarget { Id = "42" }; const string expected = "{\"$type\":\"" + TestTargetTypeName + "\",\"Id\":\"42\"}"; JsonAssert.SerializesTo(target, expected); }
public void ShouldDeserializeObjectWithoutTypeInfo() { const string json = "{\"$type\":\"" + TestTargetTypeName + "\",\"Id\":\"HalliGalli\"}"; var expected = new SerializationTestTarget { Id = "HalliGalli" }; JsonAssert.DeserializesTo(json, expected); }
public void ShouldNotSerializeNullProperty() { // ReSharper disable once AssignNullToNotNullAttribute var target = new SerializationTestTarget { Id = null }; const string expected = "{\"$type\":\"" + TestTargetTypeName + "\"}"; JsonAssert.SerializesTo(target, expected); }
public void ShouldPrettyPrintObject() { var target = new SerializationTestTarget { Id = "Foo" }; const string expected = "{\r\n" + " \"Id\": \"Foo\"\r\n" + "}"; var actual = target.ToPrettyPrintJson(); Assert.AreEqual(expected, actual); }
public void ShouldNotSerializeNullPropertyWhenFormatting() { // ReSharper disable once AssignNullToNotNullAttribute var target = new SerializationTestTarget { Id = null }; const string expected = "{\r\n" + " \"$type\": \"" + TestTargetTypeName + "\"\r\n" + "}"; var actual = target.ToFormattedJson(); Assert.AreEqual(expected, actual); }
public void ShouldSerializeFormatted() { var target = new SerializationTestTarget { Id = "666" }; const string expected = "{\r\n" + " \"$type\": \"" + TestTargetTypeName + "\",\r\n" + " \"Id\": \"666\"\r\n" + "}"; var actual = target.ToFormattedJson(); Assert.AreEqual(expected, actual); }
private bool Equals(SerializationTestTarget other) { return(string.Equals(Id, other.Id)); }