Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 64b65bd

Browse files
committedFeb 24, 2025·
Navigation test refactoring:
- using common model for entity, owned, json and complex type navigations - 4 levels: root, trunk, branch, leaf - optional reference, required reference (dependent to principal), collection - for now just testing projection scenarios as proof of concept (tracking / notracking) TODO: - fix owned sqlite model, - add model with inheritance, - move actual tests from existing test suites, - add migration check (that model can be migrated to from scratch and that noop is actual noop), - implement InMemory tests. - added include stub - added cosmos stub
1 parent 5d879e3 commit 64b65bd

File tree

71 files changed

+4086
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4086
-244
lines changed
 

‎test/EFCore.Cosmos.FunctionalTests/Query/JsonQueryCosmosTest.cs

+63-74
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ FROM root c
3434
""");
3535
});
3636

37-
public override async Task Basic_json_projection_owned_collection_branch(bool async)
38-
{
39-
// Always throws for sync.
40-
if (async)
41-
{
42-
//issue #31696
43-
await Assert.ThrowsAsync<NullReferenceException>(
44-
() => base.Basic_json_projection_owned_collection_branch(async));
45-
}
46-
}
47-
4837
public override async Task Basic_json_projection_owned_collection_branch_NoTrackingWithIdentityResolution(bool async)
4938
{
5039
// Always throws for sync.
@@ -67,20 +56,20 @@ await Assert.ThrowsAsync<NullReferenceException>(
6756
}
6857
}
6958

70-
public override Task Basic_json_projection_owned_collection_root(bool async)
71-
=> Fixture.NoSyncTest(
72-
async, async a =>
73-
{
74-
await base.Basic_json_projection_owned_collection_root(a);
75-
76-
// TODO: issue #34067 (?)
77-
AssertSql(
78-
"""
79-
SELECT VALUE c
80-
FROM root c
81-
WHERE (c["Discriminator"] = "Basic")
82-
""");
83-
});
59+
// public override Task Basic_json_projection_owned_collection_root(bool async)
60+
// => Fixture.NoSyncTest(
61+
// async, async a =>
62+
// {
63+
// await base.Basic_json_projection_owned_collection_root(a);
64+
65+
// // TODO: issue #34067 (?)
66+
// AssertSql(
67+
// """
68+
//SELECT VALUE c
69+
//FROM root c
70+
//WHERE (c["Discriminator"] = "Basic")
71+
//""");
72+
// });
8473

8574
public override Task Basic_json_projection_owned_collection_root_NoTrackingWithIdentityResolution(bool async)
8675
=> Fixture.NoSyncTest(
@@ -97,19 +86,19 @@ FROM root c
9786
""");
9887
});
9988

100-
public override Task Basic_json_projection_owned_reference_branch(bool async)
101-
=> Fixture.NoSyncTest(
102-
async, async a =>
103-
{
104-
await base.Basic_json_projection_owned_reference_branch(async);
89+
// public override Task Basic_json_projection_owned_reference_branch(bool async)
90+
// => Fixture.NoSyncTest(
91+
// async, async a =>
92+
// {
93+
// await base.Basic_json_projection_owned_reference_branch(async);
10594

106-
AssertSql(
107-
"""
108-
SELECT VALUE c
109-
FROM root c
110-
WHERE (c["Discriminator"] = "Basic")
111-
""");
112-
});
95+
// AssertSql(
96+
// """
97+
//SELECT VALUE c
98+
//FROM root c
99+
//WHERE (c["Discriminator"] = "Basic")
100+
//""");
101+
// });
113102

114103
public override Task Basic_json_projection_owned_reference_branch_NoTrackingWithIdentityResolution(bool async)
115104
=> Fixture.NoSyncTest(
@@ -199,20 +188,20 @@ FROM root c
199188
""");
200189
});
201190

202-
public override Task Basic_json_projection_owned_reference_root(bool async)
203-
=> Fixture.NoSyncTest(
204-
async, async a =>
205-
{
206-
await base.Basic_json_projection_owned_reference_root(a);
191+
// public override Task Basic_json_projection_owned_reference_root(bool async)
192+
// => Fixture.NoSyncTest(
193+
// async, async a =>
194+
// {
195+
// await base.Basic_json_projection_owned_reference_root(a);
207196

208-
// TODO: issue #34067 (?)
209-
AssertSql(
210-
"""
211-
SELECT VALUE c
212-
FROM root c
213-
WHERE (c["Discriminator"] = "Basic")
214-
""");
215-
});
197+
// // TODO: issue #34067 (?)
198+
// AssertSql(
199+
// """
200+
//SELECT VALUE c
201+
//FROM root c
202+
//WHERE (c["Discriminator"] = "Basic")
203+
//""");
204+
// });
216205

217206
public override Task Basic_json_projection_owned_reference_root_NoTrackingWithIdentityResolution(bool async)
218207
=> Fixture.NoSyncTest(
@@ -229,19 +218,19 @@ FROM root c
229218
""");
230219
});
231220

232-
public override Task Basic_json_projection_owner_entity(bool async)
233-
=> Fixture.NoSyncTest(
234-
async, async a =>
235-
{
236-
await base.Basic_json_projection_owner_entity(a);
221+
// public override Task Basic_json_projection_owner_entity(bool async)
222+
// => Fixture.NoSyncTest(
223+
// async, async a =>
224+
// {
225+
// await base.Basic_json_projection_owner_entity(a);
237226

238-
AssertSql(
239-
"""
240-
SELECT VALUE c
241-
FROM root c
242-
WHERE (c["Discriminator"] = "Basic")
243-
""");
244-
});
227+
// AssertSql(
228+
// """
229+
//SELECT VALUE c
230+
//FROM root c
231+
//WHERE (c["Discriminator"] = "Basic")
232+
//""");
233+
// });
245234

246235
public override Task Basic_json_projection_owner_entity_duplicated(bool async)
247236
=> Fixture.NoSyncTest(
@@ -285,19 +274,19 @@ FROM root c
285274
""");
286275
});
287276

288-
public override Task Basic_json_projection_owner_entity_NoTracking(bool async)
289-
=> Fixture.NoSyncTest(
290-
async, async a =>
291-
{
292-
await base.Basic_json_projection_owner_entity_NoTracking(a);
277+
// public override Task Basic_json_projection_owner_entity_NoTracking(bool async)
278+
// => Fixture.NoSyncTest(
279+
// async, async a =>
280+
// {
281+
// await base.Basic_json_projection_owner_entity_NoTracking(a);
293282

294-
AssertSql(
295-
"""
296-
SELECT VALUE c
297-
FROM root c
298-
WHERE (c["Discriminator"] = "Basic")
299-
""");
300-
});
283+
// AssertSql(
284+
// """
285+
//SELECT VALUE c
286+
//FROM root c
287+
//WHERE (c["Discriminator"] = "Basic")
288+
//""");
289+
// });
301290

302291
public override Task Basic_json_projection_owner_entity_NoTrackingWithIdentityResolution(bool async)
303292
=> Fixture.NoSyncTest(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public class JsonRelationshipsInProjectionNoTrackingQueryCosmosTest : JsonRelationshipsInProjectionQueryTestBase<JsonRelationshipsQueryCosmosFixture>
7+
{
8+
private readonly NoTrackingRewriter _noTrackingRewriter = new();
9+
10+
public JsonRelationshipsInProjectionNoTrackingQueryCosmosTest(JsonRelationshipsQueryCosmosFixture fixture, ITestOutputHelper testOutputHelper)
11+
: base(fixture)
12+
{
13+
Fixture.TestSqlLoggerFactory.Clear();
14+
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
15+
}
16+
17+
protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
18+
{
19+
var rewritten = _noTrackingRewriter.Visit(serverQueryExpression);
20+
21+
return rewritten;
22+
}
23+
24+
public override Task Project_root(bool async)
25+
=> Fixture.NoSyncTest(
26+
async, async a =>
27+
{
28+
await base.Project_root(a);
29+
30+
AssertSql(
31+
"""
32+
SELECT VALUE c
33+
FROM root c
34+
""");
35+
});
36+
37+
public override Task Project_trunk_optional(bool async)
38+
=> Fixture.NoSyncTest(
39+
async, async a =>
40+
{
41+
await base.Project_trunk_optional(a);
42+
43+
AssertSql(
44+
"""
45+
SELECT VALUE c
46+
FROM root c
47+
ORDER BY c["Id"]
48+
""");
49+
});
50+
51+
public override Task Project_trunk_required(bool async)
52+
=> Fixture.NoSyncTest(
53+
async, async a =>
54+
{
55+
await base.Project_trunk_required(a);
56+
57+
AssertSql(
58+
"""
59+
SELECT VALUE c
60+
FROM root c
61+
ORDER BY c["Id"]
62+
""");
63+
});
64+
65+
public override Task Project_trunk_collection(bool async)
66+
=> Fixture.NoSyncTest(
67+
async, async a =>
68+
{
69+
await base.Project_trunk_collection(a);
70+
71+
AssertSql(
72+
"""
73+
SELECT VALUE c
74+
FROM root c
75+
ORDER BY c["Id"]
76+
""");
77+
});
78+
79+
public override Task Project_branch_required_required(bool async)
80+
=> Fixture.NoSyncTest(
81+
async, async a =>
82+
{
83+
await base.Project_branch_required_required(a);
84+
85+
AssertSql(
86+
"""
87+
SELECT VALUE c
88+
FROM root c
89+
ORDER BY c["Id"]
90+
""");
91+
});
92+
93+
public override Task Project_branch_required_optional(bool async)
94+
=> Fixture.NoSyncTest(
95+
async, async a =>
96+
{
97+
await base.Project_branch_required_optional(a);
98+
99+
AssertSql(
100+
"""
101+
SELECT VALUE c
102+
FROM root c
103+
ORDER BY c["Id"]
104+
""");
105+
});
106+
107+
public override async Task Project_branch_required_collection(bool async)
108+
{
109+
if (async)
110+
{
111+
//issue #31696
112+
await Assert.ThrowsAsync<NullReferenceException>(
113+
() => base.Project_branch_required_collection(async));
114+
115+
AssertSql(
116+
"""
117+
SELECT VALUE c
118+
FROM root c
119+
ORDER BY c["Id"]
120+
""");
121+
}
122+
}
123+
124+
public override Task Project_branch_optional_required(bool async)
125+
=> Fixture.NoSyncTest(
126+
async, async a =>
127+
{
128+
await base.Project_branch_optional_required(a);
129+
130+
AssertSql(
131+
"""
132+
SELECT VALUE c
133+
FROM root c
134+
ORDER BY c["Id"]
135+
""");
136+
});
137+
138+
public override Task Project_branch_optional_optional(bool async)
139+
=> Fixture.NoSyncTest(
140+
async, async a =>
141+
{
142+
await base.Project_branch_optional_optional(a);
143+
144+
AssertSql(
145+
"""
146+
SELECT VALUE c
147+
FROM root c
148+
ORDER BY c["Id"]
149+
""");
150+
});
151+
152+
public override async Task Project_branch_optional_collection(bool async)
153+
{
154+
if (async)
155+
{
156+
//issue #31696
157+
await Assert.ThrowsAsync<NullReferenceException>(
158+
() => base.Project_branch_optional_collection(async));
159+
160+
AssertSql(
161+
"""
162+
SELECT VALUE c
163+
FROM root c
164+
ORDER BY c["Id"]
165+
""");
166+
}
167+
}
168+
169+
public override async Task Project_branch_collection_element_using_indexer_constant(bool async)
170+
{
171+
if (async)
172+
{
173+
//issue #31696
174+
await Assert.ThrowsAsync<NullReferenceException>(
175+
() => base.Project_branch_collection_element_using_indexer_constant(async));
176+
177+
AssertSql(
178+
"""
179+
SELECT VALUE c
180+
FROM root c
181+
ORDER BY c["Id"]
182+
""");
183+
}
184+
}
185+
186+
private void AssertSql(params string[] expected)
187+
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
188+
}

0 commit comments

Comments
 (0)
Please sign in to comment.