Skip to content

Commit c099cef

Browse files
authored
Refactor method/member translation tests into their own suite (#35319)
Closes #34872
1 parent 3d40dc3 commit c099cef

File tree

64 files changed

+30840
-34956
lines changed

Some content is hidden

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

64 files changed

+30840
-34956
lines changed

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs

Lines changed: 36 additions & 1995 deletions
Large diffs are not rendered by default.

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs

Lines changed: 0 additions & 421 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
using Microsoft.EntityFrameworkCore.TestModels.BasicTypesModel;
5+
6+
namespace Microsoft.EntityFrameworkCore.Query.Translations;
7+
8+
public class BasicTypesQueryCosmosFixture : BasicTypesQueryFixtureBase
9+
{
10+
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
11+
12+
public TestSqlLoggerFactory TestSqlLoggerFactory
13+
=> (TestSqlLoggerFactory)ListLoggerFactory;
14+
15+
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
16+
=> builder.ConfigureWarnings(o => o.Ignore(CosmosEventId.NoPartitionKeyDefined));
17+
18+
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
19+
{
20+
base.OnModelCreating(modelBuilder, context);
21+
22+
modelBuilder.Entity<BasicTypesEntity>(
23+
builder =>
24+
{
25+
builder.ToContainer(nameof(BasicTypesEntity));
26+
builder.HasPartitionKey(b => b.Id);
27+
});
28+
modelBuilder.Entity<NullableBasicTypesEntity>(
29+
builder =>
30+
{
31+
builder.ToContainer(nameof(NullableBasicTypesEntity));
32+
builder.HasPartitionKey(n => n.Id);
33+
});
34+
}
35+
36+
public Task NoSyncTest(bool async, Func<bool, Task> testCode)
37+
=> CosmosTestHelpers.Instance.NoSyncTest(async, testCode);
38+
}
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
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.Translations;
5+
6+
public class EnumTranslationsCosmosTest : EnumTranslationsTestBase<BasicTypesQueryCosmosFixture>
7+
{
8+
public EnumTranslationsCosmosTest(BasicTypesQueryCosmosFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture)
9+
{
10+
Fixture.TestSqlLoggerFactory.Clear();
11+
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
12+
}
13+
14+
#region Equality
15+
16+
public override Task Equality_to_constant(bool async)
17+
=> Fixture.NoSyncTest(
18+
async, async a =>
19+
{
20+
await base.Equality_to_constant(a);
21+
22+
AssertSql(
23+
"""
24+
SELECT VALUE c
25+
FROM root c
26+
WHERE (c["Enum"] = 0)
27+
""");
28+
});
29+
30+
public override Task Equality_to_parameter(bool async)
31+
=> Fixture.NoSyncTest(
32+
async, async a =>
33+
{
34+
await base.Equality_to_parameter(a);
35+
36+
AssertSql(
37+
"""
38+
@basicEnum=?
39+
40+
SELECT VALUE c
41+
FROM root c
42+
WHERE (c["Enum"] = @basicEnum)
43+
""");
44+
});
45+
46+
public override Task Equality_nullable_enum_to_constant(bool async)
47+
=> Fixture.NoSyncTest(
48+
async, async a =>
49+
{
50+
await base.Equality_nullable_enum_to_constant(a);
51+
52+
AssertSql(
53+
"""
54+
SELECT VALUE c
55+
FROM root c
56+
WHERE (c["Enum"] = 0)
57+
""");
58+
});
59+
60+
public override Task Equality_nullable_enum_to_parameter(bool async)
61+
=> Fixture.NoSyncTest(
62+
async, async a =>
63+
{
64+
await base.Equality_nullable_enum_to_parameter(a);
65+
66+
AssertSql(
67+
"""
68+
@basicEnum=?
69+
70+
SELECT VALUE c
71+
FROM root c
72+
WHERE (c["Enum"] = @basicEnum)
73+
""");
74+
});
75+
76+
public override Task Equality_nullable_enum_to_null_constant(bool async)
77+
=> Fixture.NoSyncTest(
78+
async, async a =>
79+
{
80+
await base.Equality_nullable_enum_to_null_constant(a);
81+
82+
AssertSql(
83+
"""
84+
SELECT VALUE c
85+
FROM root c
86+
WHERE (c["Enum"] = null)
87+
""");
88+
});
89+
90+
public override Task Equality_nullable_enum_to_null_parameter(bool async)
91+
=> Fixture.NoSyncTest(
92+
async, async a =>
93+
{
94+
await base.Equality_nullable_enum_to_null_parameter(a);
95+
96+
AssertSql(
97+
"""
98+
@basicEnum=?
99+
100+
SELECT VALUE c
101+
FROM root c
102+
WHERE (c["Enum"] = @basicEnum)
103+
""");
104+
});
105+
106+
public override Task Equality_nullable_enum_to_nullable_parameter(bool async)
107+
=> Fixture.NoSyncTest(
108+
async, async a =>
109+
{
110+
await base.Equality_nullable_enum_to_nullable_parameter(a);
111+
112+
AssertSql(
113+
"""
114+
@basicEnum=?
115+
116+
SELECT VALUE c
117+
FROM root c
118+
WHERE (c["Enum"] = @basicEnum)
119+
""");
120+
});
121+
122+
#endregion Equality
123+
124+
public override Task Bitwise_and_enum_constant(bool async)
125+
=> Fixture.NoSyncTest(
126+
async, async a =>
127+
{
128+
await base.Bitwise_and_enum_constant(a);
129+
130+
AssertSql(
131+
"""
132+
SELECT VALUE c
133+
FROM root c
134+
WHERE ((c["FlagsEnum"] & 1) > 0)
135+
""",
136+
//
137+
"""
138+
SELECT VALUE c
139+
FROM root c
140+
WHERE ((c["FlagsEnum"] & 1) = 1)
141+
""");
142+
});
143+
144+
public override async Task Bitwise_and_integral_constant(bool async)
145+
{
146+
// Always throws for sync.
147+
if (async)
148+
{
149+
// Cosmos client evaluation. Issue #17246.
150+
await AssertTranslationFailed(() => base.Bitwise_and_integral_constant(async));
151+
152+
AssertSql(
153+
"""
154+
SELECT VALUE c
155+
FROM root c
156+
WHERE ((c["FlagsEnum"] & 8) = 8)
157+
""");
158+
}
159+
}
160+
161+
public override Task Bitwise_and_nullable_enum_with_constant(bool async)
162+
=> Fixture.NoSyncTest(
163+
async, async a =>
164+
{
165+
await base.Bitwise_and_nullable_enum_with_constant(a);
166+
167+
AssertSql(
168+
"""
169+
SELECT VALUE c
170+
FROM root c
171+
WHERE ((c["FlagsEnum"] & 8) > 0)
172+
""");
173+
});
174+
175+
public override Task Where_bitwise_and_nullable_enum_with_null_constant(bool async)
176+
=> Fixture.NoSyncTest(
177+
async, async a =>
178+
{
179+
await base.Where_bitwise_and_nullable_enum_with_null_constant(a);
180+
181+
AssertSql(
182+
"""
183+
SELECT VALUE c
184+
FROM root c
185+
WHERE ((c["FlagsEnum"] & null) > 0)
186+
""");
187+
});
188+
189+
public override Task Where_bitwise_and_nullable_enum_with_non_nullable_parameter(bool async)
190+
=> Fixture.NoSyncTest(
191+
async, async a =>
192+
{
193+
await base.Where_bitwise_and_nullable_enum_with_non_nullable_parameter(a);
194+
195+
AssertSql(
196+
"""
197+
@flagsEnum=?
198+
199+
SELECT VALUE c
200+
FROM root c
201+
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
202+
""");
203+
});
204+
205+
public override Task Where_bitwise_and_nullable_enum_with_nullable_parameter(bool async)
206+
=> Fixture.NoSyncTest(
207+
async, async a =>
208+
{
209+
await base.Where_bitwise_and_nullable_enum_with_nullable_parameter(a);
210+
211+
AssertSql(
212+
"""
213+
@flagsEnum=?
214+
215+
SELECT VALUE c
216+
FROM root c
217+
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
218+
""",
219+
//
220+
"""
221+
@flagsEnum=?
222+
223+
SELECT VALUE c
224+
FROM root c
225+
WHERE ((c["FlagsEnum"] & @flagsEnum) > 0)
226+
""");
227+
});
228+
229+
public override Task Bitwise_or(bool async)
230+
=> Fixture.NoSyncTest(
231+
async, async a =>
232+
{
233+
await base.Bitwise_or(a);
234+
235+
AssertSql(
236+
"""
237+
SELECT VALUE c
238+
FROM root c
239+
WHERE ((c["FlagsEnum"] | 8) > 0)
240+
""");
241+
});
242+
243+
public override Task Bitwise_projects_values_in_select(bool async)
244+
=> Fixture.NoSyncTest(
245+
async, async a =>
246+
{
247+
await base.Bitwise_projects_values_in_select(a);
248+
249+
AssertSql(
250+
"""
251+
SELECT VALUE
252+
{
253+
"BitwiseTrue" : ((c["FlagsEnum"] & 8) = 8),
254+
"BitwiseFalse" : ((c["FlagsEnum"] & 8) = 4),
255+
"BitwiseValue" : (c["FlagsEnum"] & 8)
256+
}
257+
FROM root c
258+
WHERE ((c["FlagsEnum"] & 8) = 8)
259+
OFFSET 0 LIMIT 1
260+
""");
261+
});
262+
263+
// #35317
264+
public override Task HasFlag(bool async)
265+
=> AssertTranslationFailed(() => base.HasFlag(async));
266+
267+
// #35317
268+
public override Task HasFlag_with_non_nullable_parameter(bool async)
269+
=> AssertTranslationFailed(() => base.HasFlag(async));
270+
271+
// #35317
272+
public override Task HasFlag_with_nullable_parameter(bool async)
273+
=> AssertTranslationFailed(() => base.HasFlag(async));
274+
275+
[ConditionalFact]
276+
public virtual void Check_all_tests_overridden()
277+
=> TestHelpers.AssertAllMethodsOverridden(GetType());
278+
279+
private void AssertSql(params string[] expected)
280+
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
281+
}

0 commit comments

Comments
 (0)