Skip to content

Commit 97f7387

Browse files
Copilotrenemadsen
andcommitted
Add database-aware test for nullable UInt64 enum serialization
Added Can_read_write_nullable_ulong_enum_JSON_values override with the same database-aware logic as the non-nullable version to handle MariaDB's different UInt64.MaxValue serialization. The test: 1. Includes all 7 test cases matching the base class (0, Min, Max enum, Default, One, 8, Max numeric literal) 2. Uses runtime adjustment to change expectation from {"Prop":-1} to {"Prop":18446744073709551615} for MariaDB 3. Checks numeric value (ulong)value == 18446744073709551615 to catch both representations Both nullable and non-nullable UInt64 enum tests now pass on MySQL and MariaDB. Co-authored-by: renemadsen <[email protected]>
1 parent b5a8561 commit 97f7387

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ public override Task Can_read_write_collection_of_ulong_enum_JSON_values()
7575
await base.Can_read_write_ulong_enum_JSON_values(value, json);
7676
}
7777

78+
// Provide database-aware test for nullable UInt64 enum serialization
79+
// Same as above but for nullable enums
80+
[Theory]
81+
[InlineData((EnumU64)0, """{"Prop":0}""")]
82+
[InlineData(EnumU64.Min, """{"Prop":0}""")]
83+
[InlineData(EnumU64.Max, """{"Prop":-1}""")] // This will be adjusted for MariaDB at runtime
84+
[InlineData(EnumU64.Default, """{"Prop":0}""")]
85+
[InlineData(EnumU64.One, """{"Prop":1}""")]
86+
[InlineData((EnumU64)8, """{"Prop":8}""")]
87+
[InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - will be adjusted for MariaDB at runtime
88+
public new async Task Can_read_write_nullable_ulong_enum_JSON_values(EnumU64 value, string json)
89+
{
90+
// MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1"
91+
// Adjust the expected JSON value for MariaDB to match its actual behavior
92+
// Check for both EnumU64.Max and the numeric literal (both represent UInt64.MaxValue)
93+
if (AppConfig.ServerVersion.Type == ServerType.MariaDb && (ulong)value == 18446744073709551615)
94+
{
95+
json = """{"Prop":18446744073709551615}""";
96+
}
97+
98+
await base.Can_read_write_nullable_ulong_enum_JSON_values(value, json);
99+
}
100+
78101
protected override ITestStoreFactory TestStoreFactory
79102
=> MySqlTestStoreFactory.Instance;
80103
}

0 commit comments

Comments
 (0)