Skip to content

Commit

Permalink
Add additional test cases for generic & readonly scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Sep 30, 2024
1 parent 7b48cc2 commit f0ca3a4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/Misc/TestSerializerExternalModels/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ public record struct Person2ExternalStruct(int Age, string Name)
public string StarSign { get; set; }
}

[GenerateSerializer]
public record struct GenericPersonExternalStruct<T>(T CtorParam, string Name)
{
[Id(0)]
public T BodyParam { get; set; }

[Id(1)]
public string StarSign { get; set; }
}

#if NET6_0_OR_GREATER
[GenerateSerializer]
public record Person2External(int Age, string Name)
Expand All @@ -22,4 +32,14 @@ public record Person2External(int Age, string Name)
[Id(1)]
public string StarSign { get; set; }
}

[GenerateSerializer]
public record GenericPersonExternal<T>(T CtorParam, string Name)
{
[Id(0)]
public T BodyParam { get; set; }

[Id(1)]
public string StarSign { get; set; }
}
#endif
50 changes: 49 additions & 1 deletion test/Orleans.Serialization.UnitTests/GeneratedSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public void GeneratedLibExternalRecordStructWithPCtorSerializersRoundTripThrough
}

#if NET6_0_OR_GREATER

[Fact]
public void GeneratedLibExternalRecordWithPCtorSerializersRoundTripThroughCodec()
{
Expand All @@ -169,6 +168,55 @@ public void GeneratedLibExternalRecordWithPCtorSerializersRoundTripThroughCodec(
Assert.Equal(original.StarSign, result.StarSign);
}

[Fact]
public void GeneratedLibExternalGenericRecordStructWithPCtorSerializersRoundTripThroughCodec()
{
var originalInner = new Person2External(2, "harry")
{
FavouriteColor = "redborine",
StarSign = "Aquaricorn"
};

var original = new GenericPersonExternalStruct<Person2External>(originalInner, "harry")
{
BodyParam = originalInner,
StarSign = "Aquaricorn"
};

var result = RoundTripThroughCodec(original);

Assert.Equal(original.CtorParam, result.CtorParam);
Assert.Equal(original.Name, result.Name);
Assert.Equal(original.BodyParam, result.BodyParam);
Assert.Equal(original.StarSign, result.StarSign);
Assert.Same(result.CtorParam, result.BodyParam);
}
#endif

#if NET9_0_OR_GREATER
[Fact]
public void GeneratedLibExternalGenericRecordWithPCtorSerializersRoundTripThroughCodec()
{
var originalInner = new Person2External(2, "harry")
{
FavouriteColor = "redborine",
StarSign = "Aquaricorn"
};

var original = new GenericPersonExternal<Person2External>(originalInner, "harry")
{
BodyParam = originalInner,
StarSign = "Aquaricorn"
};

var result = RoundTripThroughCodec(original);

Assert.Equal(original.CtorParam, result.CtorParam);
Assert.Equal(original.Name, result.Name);
Assert.Equal(original.BodyParam, result.BodyParam);
Assert.Equal(original.StarSign, result.StarSign);
Assert.Same(result.CtorParam, result.BodyParam);
}
#endif

#if NET6_0_OR_GREATER
Expand Down

0 comments on commit f0ca3a4

Please sign in to comment.