Skip to content

Commit 7be2162

Browse files
Copilotrenemadsen
andcommitted
Fix UInt64 MaxValue JSON expectation for both MySQL and MariaDB
Changed InlineData for numeric literal (EnumU64)18446744073709551615 to start with MariaDB's format {"Prop":18446744073709551615} and added bidirectional runtime adjustment: - On MariaDB: Adjusts EnumU64.Max from {"Prop":-1} to {"Prop":18446744073709551615} - On MySQL: Adjusts numeric literal from {"Prop":18446744073709551615} to {"Prop":-1} This ensures all 7 test cases pass correctly on both database platforms: - MySQL expects -1 for UInt64.MaxValue (both symbolic and numeric forms) - MariaDB expects 18446744073709551615 for UInt64.MaxValue (both forms) Applied to both nullable and non-nullable test methods. Co-authored-by: renemadsen <[email protected]>
1 parent 492ec23 commit 7be2162

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

test/EFCore.MySql.FunctionalTests/Query/JsonTypesRelationalMySqlTest.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,27 @@ public override Task Can_read_write_collection_of_ulong_enum_JSON_values()
6161
[InlineData(EnumU64.Default, """{"Prop":0}""")]
6262
[InlineData(EnumU64.One, """{"Prop":1}""")]
6363
[InlineData((EnumU64)8, """{"Prop":8}""")]
64-
[InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - will be adjusted for MariaDB at runtime
64+
[InlineData((EnumU64)18446744073709551615, """{"Prop":18446744073709551615}""")] // UInt64.MaxValue as numeric literal - MariaDB format
6565
public new async Task Can_read_write_ulong_enum_JSON_values(EnumU64 value, string json)
6666
{
6767
// MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1"
68-
// Adjust the expected JSON value for MariaDB to match its actual behavior
68+
// For MySQL, we need to adjust the numeric literal case to expect "-1"
6969
// Check if the value is UInt64.MaxValue (works for both enum and numeric literal)
70-
if (AppConfig.ServerVersion.Type == ServerType.MariaDb && value == EnumU64.Max)
70+
if (AppConfig.ServerVersion.Type == ServerType.MariaDb)
7171
{
72-
json = """{"Prop":18446744073709551615}""";
72+
// On MariaDB, both EnumU64.Max and the numeric literal should use the full number format
73+
if (value == EnumU64.Max)
74+
{
75+
json = """{"Prop":18446744073709551615}""";
76+
}
77+
}
78+
else
79+
{
80+
// On MySQL, the numeric literal test case expects the full number but should be -1
81+
if (value == EnumU64.Max && json == """{"Prop":18446744073709551615}""")
82+
{
83+
json = """{"Prop":-1}""";
84+
}
7385
}
7486

7587
await base.Can_read_write_ulong_enum_JSON_values(value, json);
@@ -84,15 +96,27 @@ public override Task Can_read_write_collection_of_ulong_enum_JSON_values()
8496
[InlineData(EnumU64.Default, """{"Prop":0}""")]
8597
[InlineData(EnumU64.One, """{"Prop":1}""")]
8698
[InlineData((EnumU64)8, """{"Prop":8}""")]
87-
[InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - will be adjusted for MariaDB at runtime
99+
[InlineData((EnumU64)18446744073709551615, """{"Prop":18446744073709551615}""")] // UInt64.MaxValue as numeric literal - MariaDB format
88100
public async Task Can_read_write_nullable_ulong_enum_JSON_values(EnumU64? value, string json)
89101
{
90102
// MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1"
91-
// Adjust the expected JSON value for MariaDB to match its actual behavior
103+
// For MySQL, we need to adjust the numeric literal case to expect "-1"
92104
// Check if the value is UInt64.MaxValue (works for both enum and numeric literal)
93-
if (AppConfig.ServerVersion.Type == ServerType.MariaDb && value.HasValue && value.Value == EnumU64.Max)
105+
if (AppConfig.ServerVersion.Type == ServerType.MariaDb)
106+
{
107+
// On MariaDB, both EnumU64.Max and the numeric literal should use the full number format
108+
if (value.HasValue && value.Value == EnumU64.Max)
109+
{
110+
json = """{"Prop":18446744073709551615}""";
111+
}
112+
}
113+
else
94114
{
95-
json = """{"Prop":18446744073709551615}""";
115+
// On MySQL, the numeric literal test case expects the full number but should be -1
116+
if (value.HasValue && value.Value == EnumU64.Max && json == """{"Prop":18446744073709551615}""")
117+
{
118+
json = """{"Prop":-1}""";
119+
}
96120
}
97121

98122
await base.Can_read_write_nullable_ulong_enum_JSON_values(value, json);

0 commit comments

Comments
 (0)