forked from npgsql/efcore.pg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNorthwindAggregateOperatorsQueryNpgsqlTest.cs
More file actions
174 lines (143 loc) · 5.78 KB
/
NorthwindAggregateOperatorsQueryNpgsqlTest.cs
File metadata and controls
174 lines (143 loc) · 5.78 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
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
namespace Microsoft.EntityFrameworkCore.Query;
public class NorthwindAggregateOperatorsQueryNpgsqlTest : NorthwindAggregateOperatorsQueryRelationalTestBase<
NorthwindQueryNpgsqlFixture<NoopModelCustomizer>>
{
// ReSharper disable once UnusedParameter.Local
public NorthwindAggregateOperatorsQueryNpgsqlTest(
NorthwindQueryNpgsqlFixture<NoopModelCustomizer> fixture,
ITestOutputHelper testOutputHelper)
: base(fixture)
{
ClearLog();
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}
// Overriding to add equality tolerance because of floating point precision
public override async Task Average_over_max_subquery(bool async)
{
await AssertAverage(
async,
ss => ss.Set<Customer>().OrderBy(c => c.CustomerID).Take(3),
selector: c => (decimal)c.Orders.Average(o => 5 + o.OrderDetails.Max(od => od.ProductID)),
asserter: (e, a) => Assert.Equal(e, a, 10));
AssertSql(
"""
@p='3'
SELECT avg((
SELECT avg(CAST(5 + (
SELECT max(o0."ProductID")
FROM "Order Details" AS o0
WHERE o."OrderID" = o0."OrderID") AS double precision))
FROM "Orders" AS o
WHERE c0."CustomerID" = o."CustomerID")::numeric)
FROM (
SELECT c."CustomerID"
FROM "Customers" AS c
ORDER BY c."CustomerID" NULLS FIRST
LIMIT @p
) AS c0
""");
}
public override async Task Contains_with_local_uint_array_closure(bool async)
{
await base.Contains_with_local_uint_array_closure(async);
// Note: PostgreSQL doesn't support uint, but value converters make this into bigint
AssertSql(
"""
@ids={ '0', '1' } (DbType = Object)
SELECT e."EmployeeID", e."City", e."Country", e."FirstName", e."ReportsTo", e."Title"
FROM "Employees" AS e
WHERE e."EmployeeID" = ANY (@ids)
""",
//
"""
@ids={ '0' } (DbType = Object)
SELECT e."EmployeeID", e."City", e."Country", e."FirstName", e."ReportsTo", e."Title"
FROM "Employees" AS e
WHERE e."EmployeeID" = ANY (@ids)
""");
}
public override async Task Contains_with_local_nullable_uint_array_closure(bool async)
{
await base.Contains_with_local_nullable_uint_array_closure(async);
// Note: PostgreSQL doesn't support uint, but value converters make this into bigint
AssertSql(
"""
@ids={ '0', '1' } (DbType = Object)
SELECT e."EmployeeID", e."City", e."Country", e."FirstName", e."ReportsTo", e."Title"
FROM "Employees" AS e
WHERE e."EmployeeID" = ANY (@ids)
""",
//
"""
@ids={ '0' } (DbType = Object)
SELECT e."EmployeeID", e."City", e."Country", e."FirstName", e."ReportsTo", e."Title"
FROM "Employees" AS e
WHERE e."EmployeeID" = ANY (@ids)
""");
}
public override Task Contains_with_local_anonymous_type_array_closure(bool async)
// Aggregates. Issue #15937.
=> AssertTranslationFailed(() => base.Contains_with_local_anonymous_type_array_closure(async));
public override Task Contains_with_local_tuple_array_closure(bool async)
=> Assert.ThrowsAsync<InvalidCastException>(() => base.Contains_with_local_tuple_array_closure(async: true));
public override async Task Contains_with_local_enumerable_inline(bool async)
{
// Issue #31776
await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
await base.Contains_with_local_enumerable_inline(async));
AssertSql();
}
public override async Task Contains_with_local_enumerable_inline_closure_mix(bool async)
{
await base.Contains_with_local_enumerable_inline_closure_mix(async);
AssertSql(
"""
@p={ 'ABCDE', 'ALFKI' } (DbType = Object)
SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region"
FROM "Customers" AS c
WHERE c."CustomerID" = ANY (array_remove(@p, NULL))
""",
//
"""
@p={ 'ABCDE', 'ANATR' } (DbType = Object)
SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region"
FROM "Customers" AS c
WHERE c."CustomerID" = ANY (array_remove(@p, NULL))
""");
}
public override async Task Contains_with_local_non_primitive_list_closure_mix(bool async)
{
await base.Contains_with_local_non_primitive_list_closure_mix(async);
AssertSql(
"""
@Select={ 'ABCDE', 'ALFKI' } (DbType = Object)
SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region"
FROM "Customers" AS c
WHERE c."CustomerID" = ANY (@Select)
""");
}
public override async Task Contains_with_local_non_primitive_list_inline_closure_mix(bool async)
{
await base.Contains_with_local_non_primitive_list_inline_closure_mix(async);
AssertSql(
"""
@Select={ 'ABCDE', 'ALFKI' } (DbType = Object)
SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region"
FROM "Customers" AS c
WHERE c."CustomerID" = ANY (@Select)
""",
//
"""
@Select={ 'ABCDE', 'ANATR' } (DbType = Object)
SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region"
FROM "Customers" AS c
WHERE c."CustomerID" = ANY (@Select)
""");
}
private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
protected override void ClearLog()
=> Fixture.TestSqlLoggerFactory.Clear();
}