forked from CirrusRedOrg/EntityFrameworkCore.Jet
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAdHocAdvancedMappingsQueryJetTest.cs
More file actions
304 lines (262 loc) · 9.29 KB
/
Copy pathAdHocAdvancedMappingsQueryJetTest.cs
File metadata and controls
304 lines (262 loc) · 9.29 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Threading.Tasks;
using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.TestUtilities;
namespace EntityFrameworkCore.Jet.FunctionalTests.Query;
#nullable disable
public class AdHocAdvancedMappingsQueryJetTest : AdHocAdvancedMappingsQueryRelationalTestBase
{
protected override ITestStoreFactory TestStoreFactory
=> JetTestStoreFactory.Instance;
public override async Task Setting_IsUnicode_generates_unicode_literal_in_SQL()
{
await base.Setting_IsUnicode_generates_unicode_literal_in_SQL();
AssertSql(
"""
SELECT `t`.`Id`, `t`.`Nombre`
FROM `TipoServicio` AS `t`
WHERE `t`.`Nombre` LIKE '%lla%'
""");
}
public override async Task Projecting_correlated_collection_along_with_non_mapped_property()
{
await base.Projecting_correlated_collection_along_with_non_mapped_property();
AssertSql(
"""
SELECT `b`.`Id`, `p0`.`Id`, `p0`.`BlogId`, `p0`.`Name`
FROM `Blogs` AS `b`
LEFT JOIN (
SELECT `p`.`Id`, `p`.`BlogId`, `p`.`Name`
FROM `Posts` AS `p`
WHERE `p`.`Name` LIKE '%2%'
) AS `p0` ON `b`.`Id` = `p0`.`BlogId`
ORDER BY `b`.`Id`
""",
//
"""
SELECT `b`.`Id`, (
SELECT TOP 1 `p`.`Name`
FROM `Posts` AS `p`
WHERE `b`.`Id` = `p`.`BlogId`
ORDER BY `p`.`Id`)
FROM `Blogs` AS `b`
""");
}
public override async Task Projection_failing_with_EnumToStringConverter()
{
await base.Projection_failing_with_EnumToStringConverter();
AssertSql(
"""
SELECT `p`.`Id`, `p`.`Name`, IIF(`c`.`Id` IS NULL, 'Other', `c`.`Name`) AS `CategoryName`, IIF(`c`.`Id` IS NULL, 'Active', `c`.`Status`) AS `CategoryStatus`
FROM `Products` AS `p`
LEFT JOIN `Categories` AS `c` ON `p`.`CategoryId` = `c`.`Id`
""");
}
public override async Task Expression_tree_constructed_via_interface_works()
{
await base.Expression_tree_constructed_via_interface_works();
AssertSql(
"""
SELECT `r`.`Id`, `r`.`IsRemoved`, `r`.`Removed`, `r`.`RemovedByUser`, `r`.`OwnedEntity_Exists`, `r`.`OwnedEntity_OwnedValue`
FROM `RemovableEntities` AS `r`
WHERE `r`.`IsRemoved` = FALSE
""",
//
"""
SELECT `p`.`Id`, `p`.`RemovableEntityId`
FROM `Parents` AS `p`
LEFT JOIN `RemovableEntities` AS `r` ON `p`.`RemovableEntityId` = `r`.`Id`
WHERE `r`.`IsRemoved` = TRUE
""",
//
"""
SELECT `r`.`Id`, `r`.`IsRemoved`, `r`.`Removed`, `r`.`RemovedByUser`, `r`.`OwnedEntity_Exists`, `r`.`OwnedEntity_OwnedValue`
FROM `RemovableEntities` AS `r`
WHERE `r`.`OwnedEntity_OwnedValue` = 'Abc'
""",
//
"""
@__id_0='1'
SELECT `p`.`Id`, `p`.`RemovableEntityId`
FROM `Parents` AS `p`
WHERE `p`.`Id` = @__id_0
""");
}
public override async Task Double_convert_interface_created_expression_tree()
{
await base.Double_convert_interface_created_expression_tree();
AssertSql(
"""
@__action_0='1'
SELECT COUNT(*)
FROM `Offers` AS `o`
WHERE EXISTS (
SELECT 1
FROM `OfferActions` AS `o0`
WHERE `o`.`Id` = `o0`.`OfferId` AND `o0`.`Action` = @__action_0)
""");
}
public override async Task Casts_are_removed_from_expression_tree_when_redundant()
{
await base.Casts_are_removed_from_expression_tree_when_redundant();
AssertSql(
"""
@__id_0='1'
SELECT TOP 1 `m`.`Id`, `m`.`Name`, `m`.`NavigationEntityId`
FROM `MockEntities` AS `m`
WHERE `m`.`Id` = @__id_0
""",
//
"""
SELECT COUNT(*)
FROM `MockEntities` AS `m`
""");
}
public override async Task Can_query_hierarchy_with_non_nullable_property_on_derived()
{
await base.Can_query_hierarchy_with_non_nullable_property_on_derived();
AssertSql(
"""
SELECT `b`.`Id`, `b`.`Name`, `b`.`Type`, `b`.`IsOnline`
FROM `Businesses` AS `b`
""");
}
public override async Task Query_generates_correct_datetime2_parameter_definition(int? fractionalSeconds, string postfix)
{
await base.Query_generates_correct_datetime2_parameter_definition(fractionalSeconds, postfix);
AssertSql(
"""
@__parameter_0='2021-11-12T13:14:15.0000000' (DbType = DateTime)
SELECT TOP 1 `e`.`DateTime`
FROM `Entities` AS `e`
WHERE `e`.`DateTime` = CDATE(@__parameter_0)
""");
}
public override async Task Query_generates_correct_datetimeoffset_parameter_definition(int? fractionalSeconds, string postfix)
{
await base.Query_generates_correct_datetimeoffset_parameter_definition(fractionalSeconds, postfix);
AssertSql(
"""
@__parameter_0='2021-11-12T03:14:15.0000000Z' (DbType = DateTime)
SELECT TOP 1 `e`.`DateTimeOffset`
FROM `Entities` AS `e`
WHERE `e`.`DateTimeOffset` = @__parameter_0
""");
}
public override async Task Query_generates_correct_timespan_parameter_definition(int? fractionalSeconds, string postfix)
{
await base.Query_generates_correct_timespan_parameter_definition(fractionalSeconds, postfix);
AssertSql(
"""
@__parameter_0='12:34:56.7890123'
SELECT TOP 1 `e`.`TimeSpan`
FROM `Entities` AS `e`
WHERE `e`.`TimeSpan` = @__parameter_0
""");
}
public override async Task Hierarchy_query_with_abstract_type_sibling(bool async)
{
await base.Hierarchy_query_with_abstract_type_sibling(async);
AssertSql(
"""
SELECT `a`.`Id`, `a`.`Discriminator`, `a`.`Species`, `a`.`Name`, `a`.`EdcuationLevel`, `a`.`FavoriteToy`
FROM `Animals` AS `a`
WHERE `a`.`Discriminator` IN ('Cat', 'Dog') AND (`a`.`Species` LIKE 'F%')
""");
}
public override async Task Hierarchy_query_with_abstract_type_sibling_TPT(bool async)
{
await base.Hierarchy_query_with_abstract_type_sibling_TPT(async);
AssertSql(
"""
SELECT `a`.`Id`, `a`.`Species`, `p`.`Name`, `c`.`EdcuationLevel`, `d`.`FavoriteToy`, IIF(`d`.`Id` IS NOT NULL, 'Dog', IIF(`c`.`Id` IS NOT NULL, 'Cat', NULL)) AS `Discriminator`
FROM ((`Animals` AS `a`
LEFT JOIN `Pets` AS `p` ON `a`.`Id` = `p`.`Id`)
LEFT JOIN `Cats` AS `c` ON `a`.`Id` = `c`.`Id`)
LEFT JOIN `Dogs` AS `d` ON `a`.`Id` = `d`.`Id`
WHERE (`d`.`Id` IS NOT NULL OR `c`.`Id` IS NOT NULL) AND (`a`.`Species` LIKE 'F%')
""");
}
public override async Task Hierarchy_query_with_abstract_type_sibling_TPC(bool async)
{
await base.Hierarchy_query_with_abstract_type_sibling_TPC(async);
AssertSql(
"""
SELECT `u`.`Id`, `u`.`Species`, `u`.`Name`, `u`.`EdcuationLevel`, `u`.`FavoriteToy`, `u`.`Discriminator`
FROM (
SELECT `c`.`Id`, `c`.`Species`, `c`.`Name`, `c`.`EdcuationLevel`, NULL AS `FavoriteToy`, 'Cat' AS `Discriminator`
FROM `Cats` AS `c`
UNION ALL
SELECT `d`.`Id`, `d`.`Species`, `d`.`Name`, NULL AS `EdcuationLevel`, `d`.`FavoriteToy`, 'Dog' AS `Discriminator`
FROM `Dogs` AS `d`
) AS `u`
WHERE `u`.`Species` LIKE 'F%'
""");
}
public override async Task Two_similar_complex_properties_projected_with_split_query1()
{
await base.Two_similar_complex_properties_projected_with_split_query1();
AssertSql(
"""
SELECT `o`.`Id`
FROM `Offers` AS `o`
ORDER BY `o`.`Id`
""",
//
"""
SELECT `s`.`Id`, `s`.`NestedId`, `s`.`OfferId`, `s`.`payment_brutto`, `s`.`payment_netto`, `s`.`Id0`, `s`.`payment_brutto0`, `s`.`payment_netto0`, `o`.`Id`
FROM `Offers` AS `o`
INNER JOIN (
SELECT `v`.`Id`, `v`.`NestedId`, `v`.`OfferId`, `v`.`payment_brutto`, `v`.`payment_netto`, `n`.`Id` AS `Id0`, `n`.`payment_brutto` AS `payment_brutto0`, `n`.`payment_netto` AS `payment_netto0`
FROM `Variation` AS `v`
LEFT JOIN `NestedEntity` AS `n` ON `v`.`NestedId` = `n`.`Id`
) AS `s` ON `o`.`Id` = `s`.`OfferId`
ORDER BY `o`.`Id`
""");
}
public override async Task Two_similar_complex_properties_projected_with_split_query2()
{
await base.Two_similar_complex_properties_projected_with_split_query2();
AssertSql(
"""
SELECT TOP 2 `o`.`Id`
FROM `Offers` AS `o`
WHERE `o`.`Id` = 1
ORDER BY `o`.`Id`
""",
//
"""
SELECT `s`.`Id`, `s`.`NestedId`, `s`.`OfferId`, `s`.`payment_brutto`, `s`.`payment_netto`, `s`.`Id0`, `s`.`payment_brutto0`, `s`.`payment_netto0`, `o0`.`Id`
FROM (
SELECT TOP 1 `o`.`Id`
FROM `Offers` AS `o`
WHERE `o`.`Id` = 1
) AS `o0`
INNER JOIN (
SELECT `v`.`Id`, `v`.`NestedId`, `v`.`OfferId`, `v`.`payment_brutto`, `v`.`payment_netto`, `n`.`Id` AS `Id0`, `n`.`payment_brutto` AS `payment_brutto0`, `n`.`payment_netto` AS `payment_netto0`
FROM `Variation` AS `v`
LEFT JOIN `NestedEntity` AS `n` ON `v`.`NestedId` = `n`.`Id`
) AS `s` ON `o0`.`Id` = `s`.`OfferId`
ORDER BY `o0`.`Id`
""");
}
public override async Task Projecting_one_of_two_similar_complex_types_picks_the_correct_one()
{
await base.Projecting_one_of_two_similar_complex_types_picks_the_correct_one();
AssertSql(
"""
SELECT `a`.`Id`, `s`.`Info_Created0` AS `Created`
FROM (
SELECT TOP 10 `c`.`Id`, `b`.`AId`, `b`.`Info_Created` AS `Info_Created0`
FROM `Cs` AS `c`
INNER JOIN `Bs` AS `b` ON `c`.`BId` = `b`.`Id`
WHERE `b`.`AId` = 1
ORDER BY `c`.`Id`
) AS `s`
LEFT JOIN `As` AS `a` ON `s`.`AId` = `a`.`Id`
ORDER BY `s`.`Id`
""");
}
}