-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
src/3.0-JsonMergePatch.Tests/NewtonsoftJson/Patching/Attributes.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Morcatko.AspNetCore.JsonMergePatch.NewtonsoftJson.Builders; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace Morcatko.AspNetCore.JsonMergePatch.Tests.NewtonsoftJson.Patching | ||
{ | ||
public class Attributes | ||
{ | ||
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(); | ||
} | ||
|
||
|
||
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); | ||
} | ||
} | ||
} |