-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9664 from abpframework/auto-merge/rel-4-4/495
Merge branch dev with rel-4.4
- Loading branch information
Showing
4 changed files
with
109 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
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
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
76 changes: 76 additions & 0 deletions
76
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpHasExtraPropertiesJsonConverter_Tests.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,76 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Shouldly; | ||
using Volo.Abp.Data; | ||
using Volo.Abp.ObjectExtending; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.Json | ||
{ | ||
public class AbpHasExtraPropertiesJsonConverter_Tests: AbpJsonTestBase | ||
{ | ||
private readonly IJsonSerializer _jsonSerializer; | ||
|
||
public AbpHasExtraPropertiesJsonConverter_Tests() | ||
{ | ||
_jsonSerializer = GetRequiredService<IJsonSerializer>(); | ||
} | ||
|
||
[Fact] | ||
public void JsonConverter_Test() | ||
{ | ||
var fooDto = new FooDto | ||
{ | ||
Name = "foo-dto", | ||
BarDtos = new List<BarDto>() | ||
}; | ||
fooDto.SetProperty("foo", "foo-value"); | ||
|
||
var barDto = new BarDto | ||
{ | ||
Name = "bar-dto" | ||
}; | ||
barDto.SetProperty("bar", "bar-value"); | ||
fooDto.BarDtos.Add(barDto); | ||
|
||
var json = _jsonSerializer.Serialize(fooDto); | ||
|
||
fooDto = _jsonSerializer.Deserialize<FooDto>(json); | ||
fooDto.ShouldNotBeNull(); | ||
fooDto.Name.ShouldBe("foo-dto"); | ||
fooDto.GetProperty("foo").ShouldBe("foo-value"); | ||
|
||
fooDto.BarDtos.Count.ShouldBe(1); | ||
fooDto.BarDtos.First().Name.ShouldBe("bar-dto"); | ||
fooDto.BarDtos.First().GetProperty("bar").ShouldBe("bar-value"); | ||
|
||
fooDto.Name = "new-foo-dto"; | ||
fooDto.SetProperty("foo", "new-foo-value"); | ||
fooDto.BarDtos.First().Name = "new-bar-dto"; | ||
fooDto.BarDtos.First().SetProperty("bar", "new-bar-value"); | ||
|
||
json = _jsonSerializer.Serialize(fooDto); | ||
|
||
fooDto = _jsonSerializer.Deserialize<FooDto>(json); | ||
fooDto.ShouldNotBeNull(); | ||
fooDto.Name.ShouldBe("new-foo-dto"); | ||
fooDto.GetProperty("foo").ShouldBe("new-foo-value"); | ||
|
||
fooDto.BarDtos.Count.ShouldBe(1); | ||
fooDto.BarDtos.First().Name.ShouldBe("new-bar-dto"); | ||
fooDto.BarDtos.First().GetProperty("bar").ShouldBe("new-bar-value"); | ||
} | ||
} | ||
|
||
public class FooDto : ExtensibleObject | ||
{ | ||
public string Name { get; set; } | ||
|
||
public List<BarDto> BarDtos { get; set; } | ||
} | ||
|
||
public class BarDto : ExtensibleObject | ||
{ | ||
public string Name { get; set; } | ||
} | ||
} |