Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(serializer): add failing test for record serializer when in external proj and using GenerateCodeForDeclaringAssembly #8860

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Orleans.sln
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Redis", "test\Extens
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.Serialization.Protobuf", "src\Serializers\Orleans.Serialization.Protobuf\Orleans.Serialization.Protobuf.csproj", "{A073C0EE-8732-42F9-A22E-D47034E25076}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSerializerExternalModels", "test\Misc\TestSerializerExternalModels\TestSerializerExternalModels.csproj", "{F9674B6B-67FF-4779-9B0F-41385AB1CE9E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Orleans.Streaming.AdoNet", "src\AdoNet\Orleans.Streaming.AdoNet\Orleans.Streaming.AdoNet.csproj", "{2B994F33-16CF-4679-936A-5AEABC529D2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks.AdoNet", "test\Benchmarks.AdoNet\Benchmarks.AdoNet.csproj", "{B8F43537-2D2E-42A0-BE67-5E07E4313AEA}"
Expand Down Expand Up @@ -579,6 +580,10 @@ Global
{A073C0EE-8732-42F9-A22E-D47034E25076}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A073C0EE-8732-42F9-A22E-D47034E25076}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A073C0EE-8732-42F9-A22E-D47034E25076}.Release|Any CPU.Build.0 = Release|Any CPU
{F9674B6B-67FF-4779-9B0F-41385AB1CE9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9674B6B-67FF-4779-9B0F-41385AB1CE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9674B6B-67FF-4779-9B0F-41385AB1CE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9674B6B-67FF-4779-9B0F-41385AB1CE9E}.Release|Any CPU.Build.0 = Release|Any CPU
{2B994F33-16CF-4679-936A-5AEABC529D2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B994F33-16CF-4679-936A-5AEABC529D2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B994F33-16CF-4679-936A-5AEABC529D2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -693,6 +698,7 @@ Global
{8FC6457C-6273-4338-AD2A-ECAA8FE2C5D7} = {082D25DB-70CA-48F4-93E0-EC3455F494B8}
{F13247A0-70C9-4200-9CB1-2002CB8105E0} = {082D25DB-70CA-48F4-93E0-EC3455F494B8}
{A073C0EE-8732-42F9-A22E-D47034E25076} = {4CD3AA9E-D937-48CA-BB6C-158E12257D23}
{F9674B6B-67FF-4779-9B0F-41385AB1CE9E} = {70BCC54E-1618-4742-A079-07588065E361}
{2B994F33-16CF-4679-936A-5AEABC529D2C} = {EB2EDE59-5021-42EE-A97A-D59939B39C66}
{B8F43537-2D2E-42A0-BE67-5E07E4313AEA} = {2CAB7894-777C-42B1-8B1E-322868CE92C7}
EndGlobalSection
Expand Down
13 changes: 13 additions & 0 deletions test/Misc/TestSerializerExternalModels/Models.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Orleans;

namespace UnitTests.SerializerExternalModels;

[GenerateSerializer]
public record struct Person2External(int Age, string Name)
{
[Id(0)]
public string FavouriteColor { get; set; }

[Id(1)]
public string StarSign { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>UnitTests.SerializerExternalModels</RootNamespace>
<AssemblyName>SerializerExternalModels</AssemblyName>
<TargetFrameworks>$(TestTargetFrameworks);netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Orleans.Serialization.Abstractions\Orleans.Serialization.Abstractions.csproj" />
</ItemGroup>
</Project>
25 changes: 23 additions & 2 deletions test/Orleans.Serialization.UnitTests/GeneratedSerializerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Orleans;
using Orleans.Serialization.Buffers;
using Orleans.Serialization.Codecs;
using Orleans.Serialization.Serializers;
Expand All @@ -11,6 +12,9 @@
using System.IO.Pipelines;
using Xunit;
using System.Linq;
using UnitTests.SerializerExternalModels;

[assembly: GenerateCodeForDeclaringAssembly(typeof(Person2External))]

namespace Orleans.Serialization.UnitTests;

Expand Down Expand Up @@ -126,6 +130,23 @@ public void GeneratedRecordWithPCtorSerializersRoundTripThroughCodec()
Assert.Equal(original.StarSign, result.StarSign);
}

[Fact(Skip = "TODO: Fix")]
public void GeneratedLibExternalRecordWithPCtorSerializersRoundTripThroughCodec()
{
var original = new Person2External(2, "harry")
{
FavouriteColor = "redborine",
StarSign = "Aquaricorn"
};

var result = RoundTripThroughCodec(original);

Assert.Equal(original.Age, result.Age);
Assert.Equal(original.Name, result.Name);
Assert.Equal(original.FavouriteColor, result.FavouriteColor);
Assert.Equal(original.StarSign, result.StarSign);
}

#if NET6_0_OR_GREATER
[Fact]
public void RequiredMembersAreSupported()
Expand Down Expand Up @@ -200,7 +221,7 @@ public void RecordSerializedAsRegularClass()
// Note that this only works because we are serializing each object using the "expected type" optimization and
// therefore omitting the concrete type names.
var originalAsArray = _serializer.SerializeToArray(original);
var classVersion = new Person5_Class { Age = 2, Name = "harry", FavouriteColor = "redborine", StarSign = "Aquaricorn" };
var classVersion = new Person5_Class { Age = 2, Name = "harry", FavouriteColor = "redborine", StarSign = "Aquaricorn" };
var classAsArray = _serializer.SerializeToArray(classVersion);
Assert.Equal(originalAsArray, classAsArray);
}
Expand Down Expand Up @@ -231,7 +252,7 @@ public void GeneratedSerializersRoundTripThroughSerializer_ImmutableClass()
public void GeneratedSerializersRoundTripThroughSerializer_ImmutableStruct()
{
var original = new ImmutableStruct(30, 2);
var result = (ImmutableStruct)RoundTripThroughUntypedSerializer(original, out _);
var result = (ImmutableStruct)RoundTripThroughUntypedSerializer(original, out _);

Assert.Equal(original.GetIntField(), result.GetIntField());
Assert.Equal(original.IntProperty, result.IntProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ProjectReference Include="$(SourceRoot)src\Orleans.Serialization.SystemTextJson\Orleans.Serialization.SystemTextJson.csproj" />
<ProjectReference Include="$(SourceRoot)src\Orleans.Serialization.NewtonsoftJson\Orleans.Serialization.NewtonsoftJson.csproj" />
<ProjectReference Include="$(SourceRoot)src\Serializers\Orleans.Serialization.Protobuf\Orleans.Serialization.Protobuf.csproj" />
<ProjectReference Include="..\Misc\TestSerializerExternalModels\TestSerializerExternalModels.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading