|
| 1 | +using System; |
1 | 2 | using System.Threading.Tasks; |
2 | 3 | using Microsoft.EntityFrameworkCore; |
3 | 4 | using Microsoft.EntityFrameworkCore.TestUtilities; |
@@ -51,59 +52,29 @@ public override Task Can_read_write_collection_of_nullable_ulong_enum_JSON_value |
51 | 52 | public override Task Can_read_write_collection_of_ulong_enum_JSON_values() |
52 | 53 | => Task.CompletedTask; |
53 | 54 |
|
54 | | - // Provide database-aware test for UInt64 enum serialization |
55 | | - // MariaDB serializes UInt64.MaxValue differently than MySQL |
56 | | - // MySQL expects -1, MariaDB expects the full number 18446744073709551615 |
57 | | - [Theory] |
58 | | - [InlineData((EnumU64)0, """{"Prop":0}""")] |
59 | | - [InlineData(EnumU64.Min, """{"Prop":0}""")] |
60 | | - [InlineData(EnumU64.Max, """{"Prop":-1}""")] // MySQL format - This will be adjusted for MariaDB at runtime |
61 | | - [InlineData(EnumU64.Default, """{"Prop":0}""")] |
62 | | - [InlineData(EnumU64.One, """{"Prop":1}""")] |
63 | | - [InlineData((EnumU64)8, """{"Prop":8}""")] |
64 | | - [InlineData((EnumU64)18446744073709551615, """{"Prop":-1}""")] // UInt64.MaxValue as numeric literal - MySQL format |
65 | | - public new async Task Can_read_write_ulong_enum_JSON_values(EnumU64 value, string json) |
| 55 | + // Override to handle database-specific serialization of UInt64.MaxValue |
| 56 | + // MariaDB serializes UInt64.MaxValue as "18446744073709551615" while MySQL uses "-1" |
| 57 | + public override async Task Can_read_write_ulong_enum_JSON_values(EnumU64 value, string json) |
66 | 58 | { |
67 | | - // MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1" |
68 | | - // Adjust expectation based on database type |
69 | | - if (AppConfig.ServerVersion.Type == ServerType.MariaDb) |
| 59 | + // Adjust expectation based on database type for UInt64.MaxValue |
| 60 | + // The base class has test cases with both MySQL format (-1) and MariaDB format (full number) |
| 61 | + // We need to ensure the correct format is used for each database |
| 62 | + if (value == EnumU64.Max) |
70 | 63 | { |
71 | | - // On MariaDB, adjust both test cases with -1 to use the full number |
72 | | - if (value == EnumU64.Max && json == """{"Prop":-1}""") |
73 | | - { |
74 | | - json = """{"Prop":18446744073709551615}"""; |
75 | | - } |
| 64 | + // Check if we're running on MariaDB by checking the config |
| 65 | + // AppConfig is initialized by the test infrastructure |
| 66 | + var serverVersion = AppConfig.ServerVersion; |
| 67 | + var isMariaDb = serverVersion.Type == ServerType.MariaDb; |
| 68 | + |
| 69 | + // Normalize the json to match the database we're running on |
| 70 | + json = isMariaDb |
| 71 | + ? """{"Prop":18446744073709551615}""" // MariaDB format |
| 72 | + : """{"Prop":-1}"""; // MySQL format |
76 | 73 | } |
77 | 74 |
|
78 | 75 | await base.Can_read_write_ulong_enum_JSON_values(value, json); |
79 | 76 | } |
80 | 77 |
|
81 | | - // Provide database-aware test for nullable UInt64 enum serialization |
82 | | - // Same as above but for nullable enums |
83 | | - [Theory] |
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 |
91 | | - public async Task Can_read_write_nullable_ulong_enum_JSON_values(EnumU64? value, string json) |
92 | | - { |
93 | | - // MariaDB serializes UInt64.MaxValue as "18446744073709551615" instead of "-1" |
94 | | - // Adjust expectation based on database type |
95 | | - if (AppConfig.ServerVersion.Type == ServerType.MariaDb) |
96 | | - { |
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}""") |
99 | | - { |
100 | | - json = """{"Prop":18446744073709551615}"""; |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - await base.Can_read_write_nullable_ulong_enum_JSON_values(value, json); |
105 | | - } |
106 | | - |
107 | 78 | protected override ITestStoreFactory TestStoreFactory |
108 | 79 | => MySqlTestStoreFactory.Instance; |
109 | 80 | } |
|
0 commit comments