Skip to content

Commit

Permalink
add unit tests for aot.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dibiancoj committed Feb 25, 2024
1 parent 2661bac commit 843cc62
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LibraryCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryCore.Aot.Json", "Src
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aot", "Aot", "{896C5DB1-3EDC-4DCC-AAAB-73F705B52B18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryCore.Tests.Aot.Json", "Tests\LibraryCore.Tests.Aot.Json\LibraryCore.Tests.Aot.Json.csproj", "{01CB3A66-9110-4BFA-9D7D-3117578E1575}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -288,6 +290,10 @@ Global
{9169F37A-8A3E-4E73-A75E-830A3F8E3224}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9169F37A-8A3E-4E73-A75E-830A3F8E3224}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9169F37A-8A3E-4E73-A75E-830A3F8E3224}.Release|Any CPU.Build.0 = Release|Any CPU
{01CB3A66-9110-4BFA-9D7D-3117578E1575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01CB3A66-9110-4BFA-9D7D-3117578E1575}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01CB3A66-9110-4BFA-9D7D-3117578E1575}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01CB3A66-9110-4BFA-9D7D-3117578E1575}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -347,6 +353,7 @@ Global
{43270FFA-B5A6-4F20-AE0B-C7C3F9DBD957} = {EC8F3521-E377-420D-B5A1-82D2B29FB611}
{9169F37A-8A3E-4E73-A75E-830A3F8E3224} = {896C5DB1-3EDC-4DCC-AAAB-73F705B52B18}
{896C5DB1-3EDC-4DCC-AAAB-73F705B52B18} = {75C64940-5413-442D-B876-AEAA8DC20FC0}
{01CB3A66-9110-4BFA-9D7D-3117578E1575} = {896C5DB1-3EDC-4DCC-AAAB-73F705B52B18}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E61C7767-7D12-4313-8DA2-56AE8FC5AAD5}
Expand Down
1 change: 1 addition & 0 deletions Tests/LibraryCore.Tests.Aot.Json/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
35 changes: 35 additions & 0 deletions Tests/LibraryCore.Tests.Aot.Json/JsonSerializationTest.cs
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 Tests/LibraryCore.Tests.Aot.Json/LibraryCore.Tests.Aot.Json.csproj
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>

0 comments on commit 843cc62

Please sign in to comment.