Last active
June 18, 2020 19:00
-
-
Save AnsonSmith/c81b042231d4031485f249f2a49bf9ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Morcatko.AspNetCore.JsonMergePatch.Builder; | |
using Newtonsoft.Json; | |
using Xunit; | |
namespace UnitTests | |
{ | |
class ClassOne | |
{ | |
[JsonProperty("id")] | |
public int Id { get; set; } = 1; | |
[JsonProperty("rec_id")] | |
public string RecId { get; set; } = "abc"; | |
} | |
class ClassTwo | |
{ | |
[JsonProperty("first_name")] | |
public string FirstName { get; set; } | |
[JsonProperty("last_name")] | |
public string LastName { get; set; } | |
[JsonProperty("obj_property")] | |
public ClassOne ObjProperty { get; set; } = new ClassOne(); | |
} | |
public class TestCases | |
{ | |
private readonly PatchBuilder<ClassTwo> _patchBuilder = new PatchBuilder<ClassTwo>(); | |
[Fact] | |
public void CanPatchTopLevelProperties() | |
{ | |
var original = new ClassTwo(); | |
var patch = _patchBuilder.Build("{'first_name': 'MyFirstName'}"); | |
var result = patch.ApplyTo(original); | |
Assert.Equal("MyFirstName", result.FirstName); | |
} | |
[Fact] | |
public void CannotPatchSubObject() | |
{ | |
var original = new ClassTwo(); | |
var patch = _patchBuilder.Build("{'obj_property': { 'id': 3 }}"); | |
var result = patch.ApplyTo(original); | |
Assert.Equal(3, result.ObjProperty.Id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment