forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNorthwindWhereQuerySqliteTest.cs
352 lines (280 loc) · 11.8 KB
/
NorthwindWhereQuerySqliteTest.cs
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.EntityFrameworkCore.Query;
#nullable disable
public class NorthwindWhereQuerySqliteTest : NorthwindWhereQueryRelationalTestBase<NorthwindQuerySqliteFixture<NoopModelCustomizer>>
{
public NorthwindWhereQuerySqliteTest(NorthwindQuerySqliteFixture<NoopModelCustomizer> fixture, ITestOutputHelper testOutputHelper)
: base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}
public override Task Where_datetimeoffset_now_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_now_component(async));
public override Task Where_datetimeoffset_utcnow_component(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_utcnow_component(async));
public override Task Where_datetimeoffset_utcnow(bool async)
=> AssertTranslationFailed(() => base.Where_datetimeoffset_utcnow_component(async));
public override async Task<string> Where_simple_closure(bool async)
{
var queryString = await base.Where_simple_closure(async);
AssertSql(
"""
@__city_0='London' (Size = 6)
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE "c"."City" = @__city_0
""");
Assert.Equal(
@".param set @__city_0 'London'
SELECT ""c"".""CustomerID"", ""c"".""Address"", ""c"".""City"", ""c"".""CompanyName"", ""c"".""ContactName"", ""c"".""ContactTitle"", ""c"".""Country"", ""c"".""Fax"", ""c"".""Phone"", ""c"".""PostalCode"", ""c"".""Region""
FROM ""Customers"" AS ""c""
WHERE ""c"".""City"" = @__city_0", queryString, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
return null;
}
public override async Task Where_datetime_now(bool async)
{
await base.Where_datetime_now(async);
AssertSql(
"""
@__myDatetime_0='2015-04-10T00:00:00.0000000' (DbType = DateTime)
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime'), '0'), '.') <> @__myDatetime_0
""");
}
public override async Task Where_datetime_utcnow(bool async)
{
await base.Where_datetime_utcnow(async);
AssertSql(
"""
@__myDatetime_0='2015-04-10T00:00:00.0000000' (DbType = DateTime)
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', 'now'), '0'), '.') <> @__myDatetime_0
""");
}
public override async Task Where_datetime_today(bool async)
{
await base.Where_datetime_today(async);
AssertSql(
"""
SELECT "e"."EmployeeID", "e"."City", "e"."Country", "e"."FirstName", "e"."ReportsTo", "e"."Title"
FROM "Employees" AS "e"
""");
}
public override async Task Where_datetime_date_component(bool async)
{
await base.Where_datetime_date_component(async);
AssertSql(
"""
@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime)
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', "o"."OrderDate", 'start of day'), '0'), '.') = @__myDatetime_0
""");
}
public override async Task Where_datetime_year_component(bool async)
{
await base.Where_datetime_year_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%Y', "o"."OrderDate") AS INTEGER) = 1998
""");
}
public override async Task Where_datetime_month_component(bool async)
{
await base.Where_datetime_month_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%m', "o"."OrderDate") AS INTEGER) = 4
""");
}
public override async Task Where_datetime_dayOfYear_component(bool async)
{
await base.Where_datetime_dayOfYear_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%j', "o"."OrderDate") AS INTEGER) = 68
""");
}
public override async Task Where_datetime_day_component(bool async)
{
await base.Where_datetime_day_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%d', "o"."OrderDate") AS INTEGER) = 4
""");
}
public override async Task Where_datetime_hour_component(bool async)
{
await base.Where_datetime_hour_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%H', "o"."OrderDate") AS INTEGER) = 0
""");
}
public override async Task Where_datetime_minute_component(bool async)
{
await base.Where_datetime_minute_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%M', "o"."OrderDate") AS INTEGER) = 0
""");
}
public override async Task Where_datetime_second_component(bool async)
{
await base.Where_datetime_second_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST(strftime('%S', "o"."OrderDate") AS INTEGER) = 0
""");
}
public override async Task Where_datetime_millisecond_component(bool async)
{
await base.Where_datetime_millisecond_component(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE (CAST(strftime('%f', "o"."OrderDate") AS REAL) * 1000.0) % 1000.0 = 0.0
""");
}
public override async Task Where_string_length(bool async)
{
await base.Where_string_length(async);
AssertSql(
"""
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE length("c"."City") = 6
""");
}
public override async Task Where_string_indexof(bool async)
{
await base.Where_string_indexof(async);
AssertSql(
"""
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE instr("c"."City", 'Sea') - 1 <> -1 OR "c"."City" IS NULL
""");
}
public override async Task Where_string_replace(bool async)
{
await base.Where_string_replace(async);
AssertSql(
"""
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE replace("c"."City", 'Sea', 'Rea') = 'Reattle'
""");
}
public override async Task Where_string_substring(bool async)
{
await base.Where_string_substring(async);
AssertSql(
"""
SELECT "c"."CustomerID", "c"."Address", "c"."City", "c"."CompanyName", "c"."ContactName", "c"."ContactTitle", "c"."Country", "c"."Fax", "c"."Phone", "c"."PostalCode", "c"."Region"
FROM "Customers" AS "c"
WHERE substr("c"."City", 1 + 1, 2) = 'ea'
""");
}
public override async Task Decimal_cast_to_double_works(bool async)
{
await base.Decimal_cast_to_double_works(async);
AssertSql(
"""
SELECT "p"."ProductID", "p"."Discontinued", "p"."ProductName", "p"."SupplierID", "p"."UnitPrice", "p"."UnitsInStock"
FROM "Products" AS "p"
WHERE CAST("p"."UnitPrice" AS REAL) > 100.0
""");
}
public override async Task Like_with_non_string_column_using_ToString(bool async)
{
await base.Like_with_non_string_column_using_ToString(async);
AssertSql(
"""
SELECT "o"."OrderID", "o"."CustomerID", "o"."EmployeeID", "o"."OrderDate"
FROM "Orders" AS "o"
WHERE CAST("o"."OrderID" AS TEXT) LIKE '%20%'
""");
}
public override async Task Where_bitwise_xor(bool async)
{
// Cannot eval 'where (([c].CustomerID == \"ALFKI\") ^ True)'. Issue #16645.
await AssertTranslationFailed(() => base.Where_bitwise_xor(async));
AssertSql();
}
public override async Task Where_compare_constructed_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_constructed_equal(async));
AssertSql();
}
public override async Task Where_compare_constructed_multi_value_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_constructed_multi_value_equal(async));
AssertSql();
}
public override async Task Where_compare_constructed_multi_value_not_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_constructed_multi_value_not_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_constructed_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_constructed_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_constructed_multi_value_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_constructed_multi_value_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_constructed_multi_value_not_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_constructed_multi_value_not_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_create_constructed_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_create_constructed_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_create_constructed_multi_value_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_create_constructed_multi_value_equal(async));
AssertSql();
}
public override async Task Where_compare_tuple_create_constructed_multi_value_not_equal(bool async)
{
// Anonymous type to constant comparison. Issue #14672.
await AssertTranslationFailed(() => base.Where_compare_tuple_create_constructed_multi_value_not_equal(async));
AssertSql();
}
private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}