Skip to content

Commit 667bf6e

Browse files
Copilotrenemadsen
andcommitted
Fix UInt64 enum tests to use consistent MySQL format with MariaDB runtime adjustment
Simplified the test approach: 1. Non-nullable test: Both Max test cases now start with MySQL format {"Prop":-1} and adjust to {"Prop":18446744073709551615} only on MariaDB 2. Nullable test: Changed InlineData from ulong literals to EnumU64 enum values to fix xUnit type conversion error The key changes: - Line 64: Changed numeric literal from MariaDB format to MySQL format {"Prop":-1} - Line 68-77: Simplified logic to only adjust when on MariaDB and JSON is "-1" - Lines 93-100: Changed from UL literals to EnumU64 enum values (xUnit can convert these to EnumU64?) - Line 107-111: Simplified condition to match non-nullable version All 14 test cases (7 for each method) now pass on both MySQL and MariaDB. Co-authored-by: renemadsen <[email protected]>
1 parent 3ab914b commit 667bf6e

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

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

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,67 +57,49 @@ public override Task Can_read_write_collection_of_ulong_enum_JSON_values()
5757
[Theory]
5858
[InlineData((EnumU64)0, """{"Prop":0}""")]
5959
[InlineData(EnumU64.Min, """{"Prop":0}""")]
60-
[InlineData(EnumU64.Max, """{"Prop":-1}""")] // This will be adjusted for MariaDB at runtime
60+
[InlineData(EnumU64.Max, """{"Prop":-1}""")] // MySQL format - This will be adjusted for MariaDB at runtime
6161
[InlineData(EnumU64.Default, """{"Prop":0}""")]
6262
[InlineData(EnumU64.One, """{"Prop":1}""")]
6363
[InlineData((EnumU64)8, """{"Prop":8}""")]
64-
[InlineData((EnumU64)18446744073709551615, """{"Prop":18446744073709551615}""")] // UInt64.MaxValue as numeric literal - MariaDB format
64+
[InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - MySQL 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-
// For MySQL, we need to adjust the numeric literal case to expect "-1"
69-
// Check if the value is UInt64.MaxValue (works for both enum and numeric literal)
68+
// Adjust expectation based on database type
7069
if (AppConfig.ServerVersion.Type == ServerType.MariaDb)
7170
{
72-
// On MariaDB, both EnumU64.Max and the numeric literal should use the full number format
73-
if (value == EnumU64.Max)
71+
// On MariaDB, adjust both test cases with -1 to use the full number
72+
if (value == EnumU64.Max && json == """{"Prop":-1}""")
7473
{
7574
json = """{"Prop":18446744073709551615}""";
7675
}
7776
}
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-
}
85-
}
8677

8778
await base.Can_read_write_ulong_enum_JSON_values(value, json);
8879
}
8980

9081
// Provide database-aware test for nullable UInt64 enum serialization
9182
// Same as above but for nullable enums
9283
[Theory]
93-
[InlineData(0UL, """{"Prop":0}""")]
94-
[InlineData(0UL, """{"Prop":0}""")] // Min
95-
[InlineData(18446744073709551615UL, """{"Prop":-1}""")] // Max - This will be adjusted for MariaDB at runtime
96-
[InlineData(0UL, """{"Prop":0}""")] // Default
97-
[InlineData(1UL, """{"Prop":1}""")] // One
98-
[InlineData(8UL, """{"Prop":8}""")]
99-
[InlineData(18446744073709551615UL, """{"Prop":18446744073709551615}""")] // UInt64.MaxValue as numeric literal - MariaDB format
84+
[InlineData(EnumU64.Min, """{"Prop":0}""")]
85+
[InlineData((EnumU64)0, """{"Prop":0}""")]
86+
[InlineData(EnumU64.Max, """{"Prop":-1}""")] // MySQL format - This will be adjusted for MariaDB at runtime
87+
[InlineData(EnumU64.Default, """{"Prop":0}""")]
88+
[InlineData(EnumU64.One, """{"Prop":1}""")]
89+
[InlineData((EnumU64)8, """{"Prop":8}""")]
90+
[InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - MySQL format
10091
public async Task Can_read_write_nullable_ulong_enum_JSON_values(EnumU64? value, string json)
10192
{
10293
// MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1"
103-
// For MySQL, we need to adjust the numeric literal case to expect "-1"
104-
// Check if the value is UInt64.MaxValue (works for both enum and numeric literal)
94+
// Adjust expectation based on database type
10595
if (AppConfig.ServerVersion.Type == ServerType.MariaDb)
10696
{
107-
// On MariaDB, both EnumU64.Max and the numeric literal should use the full number format
108-
if (value.HasValue && (ulong)value.Value == 18446744073709551615UL)
97+
// On MariaDB, adjust both test cases with -1 to use the full number
98+
if (value.HasValue && value.Value == EnumU64.Max && json == """{"Prop":-1}""")
10999
{
110100
json = """{"Prop":18446744073709551615}""";
111101
}
112102
}
113-
else
114-
{
115-
// On MySQL, the numeric literal test case expects the full number but should be -1
116-
if (value.HasValue && (ulong)value.Value == 18446744073709551615UL && json == """{"Prop":18446744073709551615}""")
117-
{
118-
json = """{"Prop":-1}""";
119-
}
120-
}
121103

122104
await base.Can_read_write_nullable_ulong_enum_JSON_values(value, json);
123105
}

0 commit comments

Comments
 (0)