-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
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,35 @@ | ||
using LibraryCore.Aot.Json; | ||
using System.Text.Json; | ||
|
||
namespace LibraryCore.Tests.Aot.Json; | ||
|
||
public class JsonSerializationTest | ||
{ | ||
public record TestModel(int Id, string Text); | ||
|
||
[Fact] | ||
public void NonAotWithGeneral() | ||
{ | ||
var serializationOptions = new JsonSerializerOptions(JsonSerializerDefaults.General); | ||
|
||
var json = JsonSerializer.Serialize(new TestModel(99, "99"), serializationOptions); | ||
|
||
var backToModel = JsonSerializer.Deserialize(json, ResolveJsonType.ResolveJsonTypeInfo<TestModel>())!; | ||
|
||
Assert.Equal(99, backToModel.Id); | ||
Assert.Equal("99", backToModel.Text); | ||
} | ||
|
||
[Fact] | ||
public void NonAotWithWeb() | ||
{ | ||
var serializationOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); | ||
|
||
var json = JsonSerializer.Serialize(new TestModel(88, "88"), serializationOptions); | ||
|
||
var backToModel = JsonSerializer.Deserialize(json, ResolveJsonType.ResolveJsonTypeInfo<TestModel>())!; | ||
|
||
Assert.Equal(88, backToModel.Id); | ||
Assert.Equal("88", backToModel.Text); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Tests/LibraryCore.Tests.Aot.Json/LibraryCore.Tests.Aot.Json.csproj
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,39 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
<Using Include="Moq" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="coverage.opencover.xml" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\LibraryCore.Shared\LibraryCore.Aot.Json\LibraryCore.Aot.Json.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |