-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathPrimitiveCollectionsQueryOldSqlServerTest.cs
More file actions
822 lines (668 loc) · 35.7 KB
/
PrimitiveCollectionsQueryOldSqlServerTest.cs
File metadata and controls
822 lines (668 loc) · 35.7 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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.EntityFrameworkCore.SqlServer.Internal;
using Xunit.Sdk;
namespace Microsoft.EntityFrameworkCore.Query;
/// <summary>
/// Runs all primitive collection tests with SQL Server compatibility level 120 (SQL Server 2014), which doesn't support OPENJSON.
/// This exercises the older translation paths for e.g. Contains, to make sure things work for providers with no queryable constant/
/// parameter support.
/// </summary>
public class PrimitiveCollectionsQueryOldSqlServerTest : PrimitiveCollectionsQueryRelationalTestBase<
PrimitiveCollectionsQueryOldSqlServerTest.PrimitiveCollectionsQueryOldSqlServerFixture>
{
public PrimitiveCollectionsQueryOldSqlServerTest(
PrimitiveCollectionsQueryOldSqlServerFixture fixture,
ITestOutputHelper testOutputHelper)
: base(fixture)
{
Fixture.TestSqlLoggerFactory.Clear();
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}
public override async Task Inline_collection_of_ints_Contains(bool async)
{
await base.Inline_collection_of_ints_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""");
}
public override async Task Inline_collection_of_nullable_ints_Contains(bool async)
{
await base.Inline_collection_of_nullable_ints_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] IN (10, 999)
""");
}
public override async Task Inline_collection_of_nullable_ints_Contains_null(bool async)
{
await base.Inline_collection_of_nullable_ints_Contains_null(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] IS NULL OR [p].[NullableInt] = 999
""");
}
public override async Task Inline_collection_Count_with_zero_values(bool async)
{
await base.Inline_collection_Count_with_zero_values(async);
AssertSql();
}
public override async Task Inline_collection_Count_with_one_value(bool async)
{
await base.Inline_collection_Count_with_one_value(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT COUNT(*)
FROM (VALUES (CAST(2 AS int))) AS [v]([Value])
WHERE [v].[Value] > [p].[Id]) = 1
""");
}
public override async Task Inline_collection_Count_with_two_values(bool async)
{
await base.Inline_collection_Count_with_two_values(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT COUNT(*)
FROM (VALUES (CAST(2 AS int)), (999)) AS [v]([Value])
WHERE [v].[Value] > [p].[Id]) = 1
""");
}
public override async Task Inline_collection_Count_with_three_values(bool async)
{
await base.Inline_collection_Count_with_three_values(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT COUNT(*)
FROM (VALUES (CAST(2 AS int)), (999), (1000)) AS [v]([Value])
WHERE [v].[Value] > [p].[Id]) = 2
""");
}
public override async Task Inline_collection_Contains_with_zero_values(bool async)
{
await base.Inline_collection_Contains_with_zero_values(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE 0 = 1
""");
}
public override async Task Inline_collection_Contains_with_one_value(bool async)
{
await base.Inline_collection_Contains_with_one_value(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] = 2
""");
}
public override async Task Inline_collection_Contains_with_two_values(bool async)
{
await base.Inline_collection_Contains_with_two_values(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (2, 999)
""");
}
public override async Task Inline_collection_Contains_with_three_values(bool async)
{
await base.Inline_collection_Contains_with_three_values(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (2, 999, 1000)
""");
}
public override async Task Inline_collection_Contains_with_EF_Constant(bool async)
{
await base.Inline_collection_Contains_with_EF_Constant(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (2, 999, 1000)
""");
}
public override async Task Inline_collection_Contains_with_all_parameters(bool async)
{
await base.Inline_collection_Contains_with_all_parameters(async);
AssertSql(
"""
@__i_0='2'
@__j_1='999'
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (@__i_0, @__j_1)
""");
}
public override async Task Inline_collection_Contains_with_constant_and_parameter(bool async)
{
await base.Inline_collection_Contains_with_constant_and_parameter(async);
AssertSql(
"""
@__j_0='999'
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (2, @__j_0)
""");
}
public override async Task Inline_collection_Contains_with_mixed_value_types(bool async)
{
await base.Inline_collection_Contains_with_mixed_value_types(async);
AssertSql(
"""
@__i_0='11'
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (999, @__i_0, [p].[Id], [p].[Id] + [p].[Int])
""");
}
public override async Task Inline_collection_Contains_as_Any_with_predicate(bool async)
{
await base.Inline_collection_Contains_as_Any_with_predicate(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] IN (2, 999)
""");
}
public override async Task Inline_collection_negated_Contains_as_All(bool async)
{
await base.Inline_collection_negated_Contains_as_All(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] NOT IN (2, 999)
""");
}
public override Task Parameter_collection_Count(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_Count(async));
public override async Task Parameter_collection_of_ints_Contains_int(bool async)
{
await base.Parameter_collection_of_ints_Contains_int(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] NOT IN (10, 999)
""");
}
public override async Task Parameter_collection_of_ints_Contains_nullable_int(bool async)
{
await base.Parameter_collection_of_ints_Contains_nullable_int(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] IN (10, 999)
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] NOT IN (10, 999) OR [p].[NullableInt] IS NULL
""");
}
public override async Task Parameter_collection_of_nullable_ints_Contains_int(bool async)
{
await base.Parameter_collection_of_nullable_ints_Contains_int(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] NOT IN (10, 999)
""");
}
public override async Task Parameter_collection_of_nullable_ints_Contains_nullable_int(bool async)
{
await base.Parameter_collection_of_nullable_ints_Contains_nullable_int(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] IS NULL OR [p].[NullableInt] = 999
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableInt] IS NOT NULL AND [p].[NullableInt] <> 999
""");
}
public override async Task Parameter_collection_of_strings_Contains_string(bool async)
{
await base.Parameter_collection_of_strings_Contains_string(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[String] IN (N'10', N'999')
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[String] NOT IN (N'10', N'999')
""");
}
public override async Task Parameter_collection_of_strings_Contains_nullable_string(bool async)
{
await base.Parameter_collection_of_strings_Contains_nullable_string(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableString] IN (N'10', N'999')
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableString] NOT IN (N'10', N'999') OR [p].[NullableString] IS NULL
""");
}
public override async Task Parameter_collection_of_nullable_strings_Contains_string(bool async)
{
await base.Parameter_collection_of_nullable_strings_Contains_string(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[String] = N'10'
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[String] <> N'10'
""");
}
public override async Task Parameter_collection_of_nullable_strings_Contains_nullable_string(bool async)
{
await base.Parameter_collection_of_nullable_strings_Contains_nullable_string(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableString] IS NULL OR [p].[NullableString] = N'999'
""",
//
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[NullableString] IS NOT NULL AND [p].[NullableString] <> N'999'
""");
}
public override async Task Parameter_collection_of_DateTimes_Contains(bool async)
{
await base.Parameter_collection_of_DateTimes_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[DateTime] IN ('2020-01-10T12:30:00.0000000Z', '9999-01-01T00:00:00.0000000Z')
""");
}
public override async Task Parameter_collection_of_bools_Contains(bool async)
{
await base.Parameter_collection_of_bools_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Bool] = CAST(1 AS bit)
""");
}
public override async Task Parameter_collection_of_enums_Contains(bool async)
{
await base.Parameter_collection_of_enums_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Enum] IN (0, 3)
""");
}
public override async Task Parameter_collection_null_Contains(bool async)
{
await base.Parameter_collection_null_Contains(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE 0 = 1
""");
}
public override Task Column_collection_of_ints_Contains(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_of_ints_Contains(async));
public override Task Column_collection_of_nullable_ints_Contains(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_of_nullable_ints_Contains(async));
public override Task Column_collection_of_nullable_ints_Contains_null(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_of_nullable_ints_Contains_null(async));
public override Task Column_collection_of_strings_contains_null(bool async)
=> AssertTranslationFailed(() => base.Column_collection_of_strings_contains_null(async));
public override Task Column_collection_of_nullable_strings_contains_null(bool async)
=> AssertTranslationFailed(() => base.Column_collection_of_strings_contains_null(async));
public override Task Column_collection_of_bools_Contains(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_of_bools_Contains(async));
[ConditionalFact]
public virtual async Task Json_representation_of_bool_array()
{
await using var context = CreateContext();
Assert.Equal(
"[true,false]",
await context.Database.SqlQuery<string>($"SELECT [Bools] AS [Value] FROM [PrimitiveCollectionsEntity] WHERE [Id] = 1")
.SingleAsync());
}
public override async Task Contains_on_Enumerable(bool async)
{
await base.Contains_on_Enumerable(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""");
}
public override async Task Contains_on_MemoryExtensions(bool async)
{
await base.Contains_on_MemoryExtensions(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""");
}
#if NET10_0_OR_GREATER
public override async Task Contains_with_MemoryExtensions_with_null_comparer(bool async)
{
await base.Contains_with_MemoryExtensions_with_null_comparer(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Int] IN (10, 999)
""");
}
#endif
public override Task Column_collection_Count_method(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Count_method(async));
public override Task Column_collection_Length(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Length(async));
public override Task Column_collection_Count_with_predicate(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Count_with_predicate(async));
public override Task Column_collection_Where_Count(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Where_Count(async));
public override Task Column_collection_index_int(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_int(async));
public override Task Column_collection_index_string(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_string(async));
public override Task Column_collection_index_datetime(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_datetime(async));
public override Task Column_collection_index_beyond_end(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_beyond_end(async));
public override Task Nullable_reference_column_collection_index_equals_nullable_column(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_beyond_end(async));
public override Task Non_nullable_reference_column_collection_index_equals_nullable_column(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_index_beyond_end(async));
public override async Task Inline_collection_index_Column(bool async)
{
await base.Inline_collection_index_Column(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT [v].[Value]
FROM (VALUES (0, CAST(1 AS int)), (1, 2), (2, 3)) AS [v]([_ord], [Value])
ORDER BY [v].[_ord]
OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1
""");
}
public override Task Parameter_collection_index_Column_equal_Column(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_index_Column_equal_Column(async));
public override Task Parameter_collection_index_Column_equal_constant(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_index_Column_equal_constant(async));
public override Task Column_collection_ElementAt(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_ElementAt(async));
public override Task Column_collection_Skip(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Skip(async));
public override Task Column_collection_Take(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Take(async));
public override Task Column_collection_Skip_Take(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Skip_Take(async));
public override Task Column_collection_OrderByDescending_ElementAt(bool async)
=> AssertTranslationFailed(() => base.Column_collection_OrderByDescending_ElementAt(async));
public override Task Column_collection_Any(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Any(async));
public override Task Column_collection_Distinct(bool async)
=> AssertTranslationFailed(() => base.Column_collection_Distinct(async));
public override async Task Column_collection_projection_from_top_level(bool async)
{
await base.Column_collection_projection_from_top_level(async);
AssertSql(
"""
SELECT [p].[Ints]
FROM [PrimitiveCollectionsEntity] AS [p]
ORDER BY [p].[Id]
""");
}
public override Task Column_collection_Join_parameter_collection(bool async)
=> AssertTranslationFailed(() => base.Column_collection_Join_parameter_collection(async));
public override Task Inline_collection_Join_ordered_column_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Inline_collection_Join_ordered_column_collection(async));
public override Task Parameter_collection_Concat_column_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_Concat_column_collection(async));
public override Task Column_collection_Union_parameter_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Union_parameter_collection(async));
public override Task Column_collection_Intersect_inline_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_Intersect_inline_collection(async));
public override Task Inline_collection_Except_column_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Inline_collection_Except_column_collection(async));
public override async Task Column_collection_equality_parameter_collection(bool async)
{
await base.Column_collection_equality_parameter_collection(async);
AssertSql(
"""
@__ints_0='[1,10]' (Size = 4000)
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Ints] = @__ints_0
""");
}
public override async Task Column_collection_Concat_parameter_collection_equality_inline_collection(bool async)
{
await base.Column_collection_Concat_parameter_collection_equality_inline_collection(async);
AssertSql();
}
public override async Task Column_collection_equality_inline_collection(bool async)
{
await base.Column_collection_equality_inline_collection(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Ints] = N'[1,10]'
""");
}
public override async Task Column_collection_equality_inline_collection_with_parameters(bool async)
{
await base.Column_collection_equality_inline_collection_with_parameters(async);
AssertSql();
}
public override Task Parameter_collection_in_subquery_Union_column_collection_as_compiled_query(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_in_subquery_Union_column_collection_as_compiled_query(async));
public override Task Parameter_collection_in_subquery_Union_column_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_in_subquery_Union_column_collection(async));
public override Task Parameter_collection_in_subquery_Union_column_collection_nested(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Parameter_collection_in_subquery_Union_column_collection_nested(async));
public override void Parameter_collection_in_subquery_and_Convert_as_compiled_query()
{
// Base implementation asserts that a different exception is thrown
}
public override Task Parameter_collection_in_subquery_Count_as_compiled_query(bool async)
=> AssertTranslationFailed(() => base.Parameter_collection_in_subquery_Count_as_compiled_query(async));
public override Task Column_collection_in_subquery_Union_parameter_collection(bool async)
=> AssertCompatibilityLevelTooLow(() => base.Column_collection_in_subquery_Union_parameter_collection(async));
// Base implementation asserts that a different exception is thrown
public override Task Parameter_collection_in_subquery_Union_another_parameter_collection_as_compiled_query(bool async)
=> Assert.ThrowsAsync<EqualException>(
() => base.Parameter_collection_in_subquery_Union_another_parameter_collection_as_compiled_query(async));
public override async Task Project_collection_of_ints_simple(bool async)
{
await base.Project_collection_of_ints_simple(async);
AssertSql(
"""
SELECT [p].[Ints]
FROM [PrimitiveCollectionsEntity] AS [p]
ORDER BY [p].[Id]
""");
}
public override Task Project_collection_of_ints_ordered(bool async)
// we don't propagate error details from projection
=> AssertTranslationFailed(() => base.Project_collection_of_ints_ordered(async));
public override Task Project_collection_of_datetimes_filtered(bool async)
// we don't propagate error details from projection
=> AssertTranslationFailed(() => base.Project_collection_of_datetimes_filtered(async));
public override async Task Project_collection_of_nullable_ints_with_paging(bool async)
{
await base.Project_collection_of_nullable_ints_with_paging(async);
// client eval
AssertSql(
"""
SELECT [p].[NullableInts]
FROM [PrimitiveCollectionsEntity] AS [p]
ORDER BY [p].[Id]
""");
}
public override Task Project_collection_of_nullable_ints_with_paging2(bool async)
// we don't propagate error details from projection
=> AssertTranslationFailed(() => base.Project_collection_of_nullable_ints_with_paging2(async));
public override async Task Project_collection_of_nullable_ints_with_paging3(bool async)
{
await base.Project_collection_of_nullable_ints_with_paging3(async);
// client eval
AssertSql(
"""
SELECT [p].[NullableInts]
FROM [PrimitiveCollectionsEntity] AS [p]
ORDER BY [p].[Id]
""");
}
public override async Task Project_collection_of_ints_with_distinct(bool async)
{
await base.Project_collection_of_ints_with_distinct(async);
// client eval
AssertSql(
"""
SELECT [p].[Ints]
FROM [PrimitiveCollectionsEntity] AS [p]
ORDER BY [p].[Id]
""");
}
public override async Task Project_collection_of_nullable_ints_with_distinct(bool async)
{
await base.Project_collection_of_nullable_ints_with_distinct(async);
AssertSql("");
}
public override Task Project_multiple_collections(bool async)
// we don't propagate error details from projection
=> AssertTranslationFailed(() => base.Project_multiple_collections(async));
public override Task Project_empty_collection_of_nullables_and_collection_only_containing_nulls(bool async)
// we don't propagate error details from projection
=> AssertTranslationFailed(() => base.Project_empty_collection_of_nullables_and_collection_only_containing_nulls(async));
public override async Task Project_primitive_collections_element(bool async)
{
await base.Project_primitive_collections_element(async);
AssertSql(
"""
SELECT [p].[Ints], [p].[DateTimes], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] < 4
ORDER BY [p].[Id]
""");
}
public override async Task Nested_contains_with_Lists_and_no_inferred_type_mapping(bool async)
{
await base.Nested_contains_with_Lists_and_no_inferred_type_mapping(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CASE
WHEN [p].[Int] IN (1, 2, 3) THEN N'one'
ELSE N'two'
END IN (N'one', N'two', N'three')
""");
}
public override async Task Nested_contains_with_arrays_and_no_inferred_type_mapping(bool async)
{
await base.Nested_contains_with_arrays_and_no_inferred_type_mapping(async);
AssertSql(
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CASE
WHEN [p].[Int] IN (1, 2, 3) THEN N'one'
ELSE N'two'
END IN (N'one', N'two', N'three')
""");
}
[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
private Task AssertCompatibilityLevelTooLow(Func<Task> query)
=> AssertTranslationFailedWithDetails(query, SqlServerStrings.CompatibilityLevelTooLowForScalarCollections(120));
private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
private PrimitiveCollectionsContext CreateContext()
=> Fixture.CreateContext();
public class PrimitiveCollectionsQueryOldSqlServerFixture : PrimitiveCollectionsQueryFixtureBase
{
// Use a different store name to prevent concurrency issues with the non-old PrimitiveCollectionsQuerySqlServerTest
protected override string StoreName
=> "OldPrimitiveCollectionsTest";
public TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;
protected override ITestStoreFactory TestStoreFactory
=> SqlServerTestStoreFactory.Instance;
// Compatibility level 120 (SQL Server 2014) doesn't support OPENJSON
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(o => o.UseCompatibilityLevel(120));
}
}