public void PatchTokenCopy_UsesSerializationSettingsForPatchValues() { // Arrange var input = JToken.Parse("[]"); var serializationSettings = GetSerializerSettingsForPersonData(); // Act var output = JsonPatcher.PatchTokenCopy( input, new[] { new JsonPatchAddOperation { Path = "/-", Value = new PersonData("Ivan", 40) } }, serializationSettings); // Assert JToken.DeepEquals( JToken.Parse("[{\"name\":\"Ivan\",\"age\":40}]"), output ).ShouldBeTrue(); }
public void PatchTokenCopy_DoesNotModifyArgument() { var input = JToken.Parse("{}"); JsonPatcher.PatchTokenCopy( input, new[] { new JsonPatchAddOperation { Path = "/var", Value = JToken.Parse("3") } }); input.ShouldBeJson("{}"); }
public void PatchTokenCopy_UsesGlobalErrorHandling() { // Arrange var input = JToken.Parse("[]"); // Act var output = JsonPatcher.PatchTokenCopy( input, new[] { new JsonPatchAddOperation { Path = "/xxx", Value = 41 } }, globalErrorHandling: ErrorHandlingTypes.Skip); // Assert JToken.DeepEquals( input, output ).ShouldBeTrue(); }
public static object Patch(object input, IReadOnlyList <JsonPatchOperation> patchOperations) { return(input is JToken inputToken ? JsonPatcher.PatchTokenCopy(inputToken, patchOperations) : JsonPatcher.PatchObjectCopy(input, patchOperations)); }