public void AddNewPropertyToExpandoOjectInTypedObject() { var doc = new NestedDTO() { DynamicProperty = new ExpandoObject() }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/NewInt", 1); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized); deserialized.ApplyTo(doc); Assert.Equal(1, doc.DynamicProperty.NewInt); }
public void ShouldNotBeAbleToAddToNonExistingPropertyThatIsNotTheRoot() { //Adding to a Nonexistent Target // // An example target JSON document: // { "foo": "bar" } // A JSON Patch document: // [ // { "op": "add", "path": "/baz/bat", "value": "qux" } // ] // This JSON Patch document, applied to the target JSON document above, // would result in an error (therefore, it would not be applied), // because the "add" operation's target location that references neither // the root of the document, nor a member of an existing object, nor a // member of an existing array. var doc = new NestedDTO() { DynamicProperty = new ExpandoObject() }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/OtherProperty/IntProperty", 1); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized); var exception = Assert.Throws <JsonPatchException>(() => { deserialized.ApplyTo(doc); }); Assert.Equal( "The property at path '/DynamicProperty/OtherProperty/IntProperty' could not be added.", exception.Message); }
public void AddNewPropertyToTypedObjectInExpandoObject() { dynamic dynamicProperty = new ExpandoObject(); dynamicProperty.StringProperty = "A"; var doc = new NestedDTO() { DynamicProperty = dynamicProperty }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/StringProperty", "B"); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument>(serialized); deserialized.ApplyTo(doc); Assert.Equal("B", doc.DynamicProperty.StringProperty); }
public void ShouldNotBeAbleToAddToNonExistingPropertyThatIsNotTheRoot() { //Adding to a Nonexistent Target // // An example target JSON document: // { "foo": "bar" } // A JSON Patch document: // [ // { "op": "add", "path": "/baz/bat", "value": "qux" } // ] // This JSON Patch document, applied to the target JSON document above, // would result in an error (therefore, it would not be applied), // because the "add" operation's target location that references neither // the root of the document, nor a member of an existing object, nor a // member of an existing array. var doc = new NestedDTO() { DynamicProperty = new ExpandoObject() }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/OtherProperty/IntProperty", 1); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized); var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); }); Assert.Equal( "The property at path '/DynamicProperty/OtherProperty/IntProperty' could not be added.", exception.Message); }
public void AddNewPropertyToTypedObjectInExpandoObject() { dynamic dynamicProperty = new ExpandoObject(); dynamicProperty.StringProperty = "A"; var doc = new NestedDTO() { DynamicProperty = dynamicProperty }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/StringProperty", "B"); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized); deserialized.ApplyTo(doc); Assert.Equal("B", doc.DynamicProperty.StringProperty); }
public void AddNewPropertyToExpandoOjectInTypedObject() { var doc = new NestedDTO() { DynamicProperty = new ExpandoObject() }; // create patch JsonPatchDocument patchDoc = new JsonPatchDocument(); patchDoc.Add("DynamicProperty/NewInt", 1); var serialized = JsonConvert.SerializeObject(patchDoc); var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized); deserialized.ApplyTo(doc); Assert.Equal(1, doc.DynamicProperty.NewInt); }
public SimpleDTOWithNestedDTO() { NestedDTO = new NestedDTO(); SimpleDTO = new SimpleDTO(); ListOfSimpleDTO = new List <SimpleDTO>(); }
public SimpleDTOWithNestedDTO() { NestedDTO = new NestedDTO(); SimpleDTO = new SimpleDTO(); ListOfSimpleDTO = new List<SimpleDTO>(); }