-
-
Notifications
You must be signed in to change notification settings - Fork 416
Expand file tree
/
Copy pathTPTGearsOfWarQueryMySqlTest.cs
More file actions
327 lines (278 loc) · 16.6 KB
/
TPTGearsOfWarQueryMySqlTest.cs
File metadata and controls
327 lines (278 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel;
using Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Pomelo.EntityFrameworkCore.MySql.Tests.TestUtilities.Attributes;
using Xunit;
using Xunit.Abstractions;
namespace Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query
{
public class TPTGearsOfWarQueryMySqlTest : TPTGearsOfWarQueryRelationalTestBase<TPTGearsOfWarQueryMySqlFixture>
{
#pragma warning disable IDE0060 // Remove unused parameter
public TPTGearsOfWarQueryMySqlTest(TPTGearsOfWarQueryMySqlFixture fixture, ITestOutputHelper testOutputHelper)
#pragma warning restore IDE0060 // Remove unused parameter
: base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}
public override Task DateTimeOffset_Contains_Less_than_Greater_than(bool async)
{
var dto = MySqlTestHelpers.GetExpectedValue(new DateTimeOffset(599898024001234567, new TimeSpan(1, 30, 0)));
var start = dto.AddDays(-1);
var end = dto.AddDays(1);
// Use List to avoid ReadOnlySpan in expression tree (same as GearsOfWarQueryMySqlTest).
var dates = new List<DateTimeOffset> { dto };
return AssertQuery(
async,
ss => ss.Set<Mission>().Where(
m => start <= m.Timeline.Date && m.Timeline < end && dates.Contains(m.Timeline)));
}
public override Task Where_datetimeoffset_milliseconds_parameter_and_constant(bool async)
{
var dateTimeOffset = MySqlTestHelpers.GetExpectedValue(new DateTimeOffset(599898024001234567, new TimeSpan(1, 30, 0)));
// Literal where clause
var p = Expression.Parameter(typeof(Mission), "i");
var dynamicWhere = Expression.Lambda<Func<Mission, bool>>(
Expression.Equal(
Expression.Property(p, "Timeline"),
Expression.Constant(dateTimeOffset)
), p);
return AssertCount(
async,
ss => ss.Set<Mission>().Where(dynamicWhere),
ss => ss.Set<Mission>().Where(m => m.Timeline == dateTimeOffset));
}
[ConditionalTheory(Skip = "TODO: Does not work as expected, probably due to some test definition issues.")]
public override async Task DateTimeOffsetNow_minus_timespan(bool async)
{
var timeSpan = new TimeSpan(10000); // <-- changed from 1000 to 10000 ticks
await AssertQuery(
async,
ss => ss.Set<Mission>().Where(e => e.Timeline > DateTimeOffset.Now - timeSpan));
AssertSql(
"""
@__timeSpan_0='00:00:00.0010000' (DbType = DateTimeOffset)
SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline`
FROM `Missions` AS `m`
WHERE `m`.`Timeline` > (UTC_TIMESTAMP() - @__timeSpan_0)
""");
}
// TODO: Implement strategy as discussed with @roji (including emails) for EF Core 5.
[ConditionalTheory(Skip = "#996")]
public override Task Client_member_and_unsupported_string_Equals_in_the_same_query(bool async)
{
return base.Client_member_and_unsupported_string_Equals_in_the_same_query(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Select_subquery_distinct_firstordefault(bool async)
{
return base.Select_subquery_distinct_firstordefault(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Select_subquery_distinct_singleordefault_boolean1(bool async)
{
return base.Select_subquery_distinct_singleordefault_boolean1(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Select_subquery_distinct_singleordefault_boolean_empty1(bool async)
{
return base.Select_subquery_distinct_singleordefault_boolean_empty1(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Select_subquery_distinct_singleordefault_boolean_with_pushdown(bool async)
{
return base.Select_subquery_distinct_singleordefault_boolean_with_pushdown(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Select_subquery_distinct_singleordefault_boolean_empty_with_pushdown(bool async)
{
return base.Select_subquery_distinct_singleordefault_boolean_empty_with_pushdown(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Where_subquery_distinct_first_boolean(bool async)
{
return base.Where_subquery_distinct_first_boolean(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Where_subquery_distinct_singleordefault_boolean1(bool async)
{
return base.Where_subquery_distinct_singleordefault_boolean1(async);
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.OuterReferenceInMultiLevelSubquery))]
public override Task Where_subquery_distinct_singleordefault_boolean_with_pushdown(bool async)
{
return base.Where_subquery_distinct_singleordefault_boolean_with_pushdown(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_firstordefault_boolean(bool async)
{
return base.Where_subquery_distinct_firstordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_firstordefault_boolean_with_pushdown(bool async)
{
return base.Where_subquery_distinct_firstordefault_boolean_with_pushdown(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_lastordefault_boolean(bool async)
{
return base.Where_subquery_distinct_lastordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_last_boolean(bool async)
{
return base.Where_subquery_distinct_last_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_orderby_firstordefault_boolean(bool async)
{
return base.Where_subquery_distinct_orderby_firstordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_distinct_orderby_firstordefault_boolean_with_pushdown(bool async)
{
return base.Where_subquery_distinct_orderby_firstordefault_boolean_with_pushdown(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Concat_with_collection_navigations(bool async)
{
return base.Concat_with_collection_navigations(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Select_navigation_with_concat_and_count(bool async)
{
return base.Select_navigation_with_concat_and_count(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Union_with_collection_navigations(bool async)
{
return base.Union_with_collection_navigations(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_concat_firstordefault_boolean(bool async)
{
return base.Where_subquery_concat_firstordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_join_firstordefault_boolean(bool async)
{
return base.Where_subquery_join_firstordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_left_join_firstordefault_boolean(bool async)
{
return base.Where_subquery_left_join_firstordefault_boolean(async);
}
[SupportedServerVersionCondition("8.0.18-mysql", Skip = "TODO: Pinpoint exact version number! Referencing outer column from WHERE subquery does not work in previous versions. Inverse of #573")]
public override Task Where_subquery_union_firstordefault_boolean(bool async)
{
return base.Where_subquery_union_firstordefault_boolean(async);
}
[ConditionalTheory(Skip = "MySQL does not support LIMIT with a parameterized argument, unless the statement was prepared. The argument needs to be a numeric constant.")]
public override Task Take_without_orderby_followed_by_orderBy_is_pushed_down1(bool async)
{
return base.Take_without_orderby_followed_by_orderBy_is_pushed_down1(async);
}
[ConditionalTheory(Skip = "MySQL does not support LIMIT with a parameterized argument, unless the statement was prepared. The argument needs to be a numeric constant.")]
public override Task Take_without_orderby_followed_by_orderBy_is_pushed_down2(bool async)
{
return base.Take_without_orderby_followed_by_orderBy_is_pushed_down2(async);
}
[SupportedServerVersionCondition("8.0.22-mysql")]
public override Task Subquery_projecting_nullable_scalar_contains_nullable_value_needs_null_expansion(bool async)
{
return base.Subquery_projecting_nullable_scalar_contains_nullable_value_needs_null_expansion(async);
}
[SupportedServerVersionCondition("8.0.22-mysql")]
public override Task Subquery_projecting_non_nullable_scalar_contains_non_nullable_value_doesnt_need_null_expansion(bool async)
{
return base.Subquery_projecting_non_nullable_scalar_contains_non_nullable_value_doesnt_need_null_expansion(async);
}
[ConditionalTheory(Skip = "Another LATERAL JOIN bug in MySQL. Grouping leads to unexpected result set.")]
[MemberData(nameof(IsAsyncData))]
public override Task Correlated_collection_with_groupby_with_complex_grouping_key_not_projecting_identifier_column_with_group_aggregate_in_final_projection(bool async)
{
return base.Correlated_collection_with_groupby_with_complex_grouping_key_not_projecting_identifier_column_with_group_aggregate_in_final_projection(async);
}
public override async Task DateTimeOffset_to_unix_time_milliseconds(bool async)
{
await base.DateTimeOffset_to_unix_time_milliseconds(async);
AssertSql(
"""
@__unixEpochMilliseconds_0='0'
SELECT `g`.`Nickname`, `g`.`SquadId`, `g`.`AssignedCityName`, `g`.`CityOfBirthName`, `g`.`FullName`, `g`.`HasSoulPatch`, `g`.`LeaderNickname`, `g`.`LeaderSquadId`, `g`.`Rank`, CASE
WHEN `o`.`Nickname` IS NOT NULL THEN 'Officer'
END AS `Discriminator`, `s`.`Id`, `s`.`Banner`, `s`.`Banner5`, `s`.`InternalNumber`, `s`.`Name`, `s1`.`SquadId`, `s1`.`MissionId`
FROM `Gears` AS `g`
LEFT JOIN `Officers` AS `o` ON (`g`.`Nickname` = `o`.`Nickname`) AND (`g`.`SquadId` = `o`.`SquadId`)
INNER JOIN `Squads` AS `s` ON `g`.`SquadId` = `s`.`Id`
LEFT JOIN `SquadMissions` AS `s1` ON `s`.`Id` = `s1`.`SquadId`
WHERE NOT EXISTS (
SELECT 1
FROM `SquadMissions` AS `s0`
INNER JOIN `Missions` AS `m` ON `s0`.`MissionId` = `m`.`Id`
WHERE (`s`.`Id` = `s0`.`SquadId`) AND (@__unixEpochMilliseconds_0 = (TIMESTAMPDIFF(microsecond, TIMESTAMP '1970-01-01 00:00:00', `m`.`Timeline`)) DIV (1000)))
ORDER BY `g`.`Nickname`, `g`.`SquadId`, `s`.`Id`, `s1`.`SquadId`
""");
}
public override async Task DateTimeOffset_to_unix_time_seconds(bool async)
{
await base.DateTimeOffset_to_unix_time_seconds(async);
AssertSql(
"""
@__unixEpochSeconds_0='0'
SELECT `g`.`Nickname`, `g`.`SquadId`, `g`.`AssignedCityName`, `g`.`CityOfBirthName`, `g`.`FullName`, `g`.`HasSoulPatch`, `g`.`LeaderNickname`, `g`.`LeaderSquadId`, `g`.`Rank`, CASE
WHEN `o`.`Nickname` IS NOT NULL THEN 'Officer'
END AS `Discriminator`, `s`.`Id`, `s`.`Banner`, `s`.`Banner5`, `s`.`InternalNumber`, `s`.`Name`, `s1`.`SquadId`, `s1`.`MissionId`
FROM `Gears` AS `g`
LEFT JOIN `Officers` AS `o` ON (`g`.`Nickname` = `o`.`Nickname`) AND (`g`.`SquadId` = `o`.`SquadId`)
INNER JOIN `Squads` AS `s` ON `g`.`SquadId` = `s`.`Id`
LEFT JOIN `SquadMissions` AS `s1` ON `s`.`Id` = `s1`.`SquadId`
WHERE NOT EXISTS (
SELECT 1
FROM `SquadMissions` AS `s0`
INNER JOIN `Missions` AS `m` ON `s0`.`MissionId` = `m`.`Id`
WHERE (`s`.`Id` = `s0`.`SquadId`) AND (@__unixEpochSeconds_0 = TIMESTAMPDIFF(second, TIMESTAMP '1970-01-01 00:00:00', `m`.`Timeline`)))
ORDER BY `g`.`Nickname`, `g`.`SquadId`, `s`.`Id`, `s1`.`SquadId`
""");
}
[SupportedServerVersionCondition(nameof(ServerVersionSupport.LimitWithNonConstantValue))]
public override async Task Where_subquery_with_ElementAt_using_column_as_index(bool async)
{
await base.Where_subquery_with_ElementAt_using_column_as_index(async);
AssertSql("");
}
public override async Task Where_datetimeoffset_hour_component(bool async)
{
await AssertQuery(
async,
ss => from m in ss.Set<Mission>()
where m.Timeline.Hour == /* 10 */ 8
select m);
AssertSql(
"""
SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline`
FROM `Missions` AS `m`
WHERE EXTRACT(hour FROM `m`.`Timeline`) = 8
""");
}
// TODO: Implement once TimeSpan is translated as ticks instead of TIME.
public override async Task Non_string_concat_uses_appropriate_type_mapping(bool async)
{
var exception = await Assert.ThrowsAsync<InvalidCastException>(() => base.Non_string_concat_uses_appropriate_type_mapping(async));
Assert.Equal("Unable to cast object of type 'System.Decimal' to type 'System.TimeSpan'.", exception.Message);
}
private string AssertSql(string expected)
{
Fixture.TestSqlLoggerFactory.AssertBaseline(new[] {expected});
return expected;
}
}
}