public void CanApplyToSameTypedClassWithMatchingJsonPropertyName() { // create patch JsonPatchDocument <JsonPropertyDTO> patchDocToSerialize = new JsonPatchDocument <JsonPropertyDTO>(); patchDocToSerialize.Add(p => p.Name, "Kevin"); // the patchdoc will deserialize to "anothername". As JsonPropertyDTO has // a JsonProperty signifying that "Name" should be deseriallized from "AnotherName", // we should be able to apply the patchDoc. var doc = new JsonPropertyDTO() { Name = "InitialValue" }; var serialized = JsonConvert.SerializeObject(patchDocToSerialize); var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument <JsonPropertyDTO> > (serialized); deserialized.ApplyTo(doc); Assert.Equal(doc.Name, "Kevin"); }
public void HonourJsonPropertyOnApplyForAdd() { var doc = new JsonPropertyDTO() { Name = "InitialValue" }; // create patch //var patchDoc = new JsonPatchDocument<JsonPropertyDTO>(); //patchDoc.Add(p => p.Name, "Kevin"); // serialization should serialize to "AnotherName" var serialized = "[{\"value\":\"Kevin\",\"path\":\"/AnotherName\",\"op\":\"add\"}]"; // that means we can deserialize to JsonPatchDocument<JsonPropertyWithAnotherNameDTO> var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument <JsonPropertyDTO> >(serialized); deserialized.ApplyTo(doc); Assert.Equal("Kevin", doc.Name); }