-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathComplexJsonCollectionNpgsqlTest.cs
More file actions
249 lines (211 loc) · 6.89 KB
/
ComplexJsonCollectionNpgsqlTest.cs
File metadata and controls
249 lines (211 loc) · 6.89 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
namespace Microsoft.EntityFrameworkCore.Query.Associations.ComplexJson;
public class ComplexJsonCollectionNpgsqlTest(ComplexJsonNpgsqlFixture fixture, ITestOutputHelper testOutputHelper)
: ComplexJsonCollectionRelationalTestBase<ComplexJsonNpgsqlFixture>(fixture, testOutputHelper)
{
public override async Task Count()
{
await base.Count();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (
SELECT count(*)::int
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS (
"Id" integer,
"Int" integer,
"Ints" jsonb,
"Name" text,
"String" text,
"NestedCollection" jsonb,
"OptionalNestedAssociate" jsonb,
"RequiredNestedAssociate" jsonb
)) WITH ORDINALITY AS a) = 2
""");
}
public override async Task Where()
{
await base.Where();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (
SELECT count(*)::int
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS ("Int" integer)) WITH ORDINALITY AS a
WHERE a."Int" <> 8) = 2
""");
}
public override async Task OrderBy_ElementAt()
{
await base.OrderBy_ElementAt();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (
SELECT a."Int"
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS (
"Id" integer,
"Int" integer
)) WITH ORDINALITY AS a
ORDER BY a."Id" NULLS FIRST
LIMIT 1 OFFSET 0) = 8
""");
}
#region Distinct
public override async Task Distinct()
{
await base.Distinct();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (
SELECT count(*)::int
FROM (
SELECT DISTINCT a."Id", a."Int", a."Ints", a."Name", a."String", a."NestedCollection" AS c, a."OptionalNestedAssociate" AS c0, a."RequiredNestedAssociate" AS c1
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS (
"Id" integer,
"Int" integer,
"Ints" jsonb,
"Name" text,
"String" text,
"NestedCollection" jsonb,
"OptionalNestedAssociate" jsonb,
"RequiredNestedAssociate" jsonb
)) WITH ORDINALITY AS a
) AS a0) = 2
""");
}
public override async Task Distinct_projected(QueryTrackingBehavior queryTrackingBehavior)
{
await base.Distinct_projected(queryTrackingBehavior);
AssertSql();
}
public override async Task Distinct_over_projected_nested_collection()
{
await base.Distinct_over_projected_nested_collection();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (
SELECT count(*)::int
FROM (
SELECT DISTINCT a."NestedCollection" AS c
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS ("NestedCollection" jsonb)) WITH ORDINALITY AS a
) AS a0) = 2
""");
}
public override async Task Distinct_over_projected_filtered_nested_collection()
{
await base.Distinct_over_projected_filtered_nested_collection();
AssertSql();
}
#endregion Distinct
#region Index
public override async Task Index_constant()
{
await base.Index_constant();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (CAST(r."AssociateCollection" #>> '{0,Int}' AS integer)) = 8
""");
}
public override async Task Index_parameter()
{
await base.Index_parameter();
AssertSql(
"""
@i='0'
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (CAST(r."AssociateCollection" #>> ARRAY[@i,'Int']::text[] AS integer)) = 8
""");
}
public override async Task Index_column()
{
await base.Index_column();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (CAST(r."AssociateCollection" #>> ARRAY[r."Id" - 1,'Int']::text[] AS integer)) = 8
""");
}
public override async Task Index_out_of_bounds()
{
await base.Index_out_of_bounds();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (CAST(r."AssociateCollection" #>> '{9999,Int}' AS integer)) = 8
""");
}
#endregion Index
#region GroupBy
public override async Task GroupBy()
{
await base.GroupBy();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE 16 IN (
SELECT COALESCE(sum(a."Int"), 0)::int
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS (
"Int" integer,
"String" text
)) WITH ORDINALITY AS a
GROUP BY a."String"
)
""");
}
#endregion GroupBy
public override async Task Select_within_Select_within_Select_with_aggregates()
{
await base.Select_within_Select_within_Select_with_aggregates();
AssertSql(
"""
SELECT (
SELECT COALESCE(sum((
SELECT max(n."Int")
FROM ROWS FROM (jsonb_to_recordset(a."NestedCollection") AS ("Int" integer)) WITH ORDINALITY AS n)), 0)::int
FROM ROWS FROM (jsonb_to_recordset(r."AssociateCollection") AS ("NestedCollection" jsonb)) WITH ORDINALITY AS a)
FROM "RootEntity" AS r
""");
}
public override async Task Index_on_nested_collection()
{
await base.Index_on_nested_collection();
AssertSql(
"""
SELECT r."Id", r."Name", r."AssociateCollection", r."OptionalAssociate", r."RequiredAssociate"
FROM "RootEntity" AS r
WHERE (CAST(r."RequiredAssociate" #>> '{NestedCollection,0,Int}' AS integer)) = 8
""");
}
public override async Task Project_struct_complex_type_with_entity_collection_navigation()
{
await base.Project_struct_complex_type_with_entity_collection_navigation();
AssertSql(
"""
SELECT p0."Coords_X", p0."Coords_Y", p0."Id", c."Id", c."Name", c."ParentId"
FROM (
SELECT p."Coords_X", p."Coords_Y", p."Id"
FROM "Parent" AS p
ORDER BY p."Id" NULLS FIRST
LIMIT 1
) AS p0
LEFT JOIN "Child" AS c ON p0."Id" = c."ParentId"
ORDER BY p0."Id" NULLS FIRST
""");
}
[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
}