public void ApplyToIfPatchable_Property_NoAddWhenNoPatchableAttribute() { var expectedError = "The property at path 'StringValueNP' could not be updated."; var expectedValue = "Not Patchable Value"; var target = new TestTarget() { StringValueNP = expectedValue }; var patch = new JsonPatchDocument( new List <Operation> { new Operation("add", "StringValueNP", null, "Value Patched") }, new DefaultContractResolver()); var errors = new List <JsonPatchError>(); patch.ApplyToIfPatchable(target, error => errors.Add(error)); Assert.Equal(expectedValue, target.StringValueNP); Assert.Single(errors); var error = errors[0]; Assert.Equal(target, error.AffectedObject); Assert.Equal(patch.Operations[0], error.Operation); Assert.Equal(expectedError, error.ErrorMessage); }
public void ApplyToIfPatchable_Collection_AddWhenPatchableAttribute() { var expectedValue = "Value Patched"; var target = new TestTarget(); var patch = new JsonPatchDocument( new List <Operation> { new Operation("add", "StringCollectionP/-", null, expectedValue) }, new DefaultContractResolver()); patch.ApplyToIfPatchable(target); Assert.Single(target.StringCollectionP); Assert.Equal(expectedValue, target.StringCollectionP[0]); }
public void ApplyToIfPatchable_T_Property_RemoveWhenPatchableAttribute() { ; var target = new TestTarget() { StringValueP = "Patchable Value" }; var patch = new JsonPatchDocument <TestTarget>( new List <Operation <TestTarget> > { new Operation <TestTarget>("remove", "StringValueP", null) }, new DefaultContractResolver()); patch.ApplyToIfPatchable(target); Assert.Null(target.StringValueP); }
public void ApplyToIfPatchable_T_Property_AddWhenPatchableAttribute() { var expectedValue = "Value Patched"; var target = new TestTarget() { StringValueP = "Patchable Value" }; var patch = new JsonPatchDocument <TestTarget>( new List <Operation <TestTarget> > { new Operation <TestTarget>("add", "StringValueP", null, expectedValue) }, new DefaultContractResolver()); patch.ApplyToIfPatchable(target); Assert.Equal(expectedValue, target.StringValueP); }