Skip to content

Commit 82f06b2

Browse files
rojiCopilot
andauthored
Override Seed21006 for Npgsql timestamptz UTC requirement (#3818)
EF Core 9.0.14 added AdHocJsonQueryTestBase tests (region #21006) that seed DateTime values with DateTimeKind.Unspecified. Npgsql's NpgsqlTimestampTzTypeMapping throws for non-default Unspecified DateTimes during JSON serialization. Override Seed21006 in AdHocJsonQueryNpgsqlTest to use UTC DateTimes for entity 1 and insert entities 2-6 via raw SQL (matching the pattern used by SQL Server's test class). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 15982e5 commit 82f06b2

1 file changed

Lines changed: 173 additions & 0 deletions

File tree

test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,179 @@ public class AdHocJsonQueryNpgsqlTest : AdHocJsonQueryRelationalTestBase
77
protected override ITestStoreFactory TestStoreFactory
88
=> NpgsqlTestStoreFactory.Instance;
99

10+
protected override async Task Seed21006(Context21006 context)
11+
{
12+
// Npgsql maps DateTime in JSON to timestamptz, which requires UTC.
13+
// Override the base seed to use UTC DateTimes and insert entities 2-6 via raw SQL.
14+
var e1 = new Context21006.Entity
15+
{
16+
Id = 1,
17+
Name = "e1",
18+
OptionalReference = new Context21006.JsonEntity
19+
{
20+
Number = 7,
21+
Text = "e1 or",
22+
NestedOptionalReference = new Context21006.JsonEntityNested
23+
{
24+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 or nor"
25+
},
26+
NestedRequiredReference = new Context21006.JsonEntityNested
27+
{
28+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 or nrr"
29+
},
30+
NestedCollection =
31+
[
32+
new Context21006.JsonEntityNested
33+
{
34+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 or c1"
35+
},
36+
new Context21006.JsonEntityNested
37+
{
38+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 or c2"
39+
}
40+
]
41+
},
42+
RequiredReference = new Context21006.JsonEntity
43+
{
44+
Number = 7,
45+
Text = "e1 rr",
46+
NestedOptionalReference = new Context21006.JsonEntityNested
47+
{
48+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 rr nor"
49+
},
50+
NestedRequiredReference = new Context21006.JsonEntityNested
51+
{
52+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 rr nrr"
53+
},
54+
NestedCollection =
55+
[
56+
new Context21006.JsonEntityNested
57+
{
58+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 rr c1"
59+
},
60+
new Context21006.JsonEntityNested
61+
{
62+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 rr c2"
63+
}
64+
]
65+
},
66+
Collection =
67+
[
68+
new Context21006.JsonEntity
69+
{
70+
Number = 7,
71+
Text = "e1 c1",
72+
NestedOptionalReference = new Context21006.JsonEntityNested
73+
{
74+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c1 nor"
75+
},
76+
NestedRequiredReference = new Context21006.JsonEntityNested
77+
{
78+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c1 nrr"
79+
},
80+
NestedCollection =
81+
[
82+
new Context21006.JsonEntityNested
83+
{
84+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c1 c1"
85+
},
86+
new Context21006.JsonEntityNested
87+
{
88+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c1 c2"
89+
}
90+
]
91+
},
92+
new Context21006.JsonEntity
93+
{
94+
Number = 7,
95+
Text = "e1 c2",
96+
NestedOptionalReference = new Context21006.JsonEntityNested
97+
{
98+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c2 nor"
99+
},
100+
NestedRequiredReference = new Context21006.JsonEntityNested
101+
{
102+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c2 nrr"
103+
},
104+
NestedCollection =
105+
[
106+
new Context21006.JsonEntityNested
107+
{
108+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c2 c1"
109+
},
110+
new Context21006.JsonEntityNested
111+
{
112+
DoB = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), Text = "e1 c2 c2"
113+
}
114+
]
115+
}
116+
]
117+
};
118+
119+
context.Add(e1);
120+
await context.SaveChangesAsync();
121+
122+
// missing scalar on top level
123+
await context.Database.ExecuteSqlAsync(
124+
$$$"""
125+
INSERT INTO "Entities" ("Collection", "OptionalReference", "RequiredReference", "Id", "Name")
126+
VALUES (
127+
'[{"Text":"e2 c1","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c1 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c1 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c1 nor"},"NestedRequiredReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c1 nrr"}},{"Text":"e2 c2","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c2 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c2 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c2 nor"},"NestedRequiredReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 c2 nrr"}}]',
128+
'{"Text":"e2 or","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e2 or c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e2 or c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 or nor"},"NestedRequiredReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 or nrr"}}',
129+
'{"Text":"e2 rr","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e2 rr c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e2 rr c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 rr nor"},"NestedRequiredReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e2 rr nrr"}}',
130+
2,
131+
'e2')
132+
""");
133+
134+
// missing scalar on nested level
135+
await context.Database.ExecuteSqlAsync(
136+
$$$"""
137+
INSERT INTO "Entities" ("Collection", "OptionalReference", "RequiredReference", "Id", "Name")
138+
VALUES (
139+
'[{"Number":7,"Text":"e3 c1","NestedCollection":[{"Text":"e3 c1 c1"},{"Text":"e3 c1 c2"}],"NestedOptionalReference":{"Text":"e3 c1 nor"},"NestedRequiredReference":{"Text":"e3 c1 nrr"}},{"Number":7,"Text":"e3 c2","NestedCollection":[{"Text":"e3 c2 c1"},{"Text":"e3 c2 c2"}],"NestedOptionalReference":{"Text":"e3 c2 nor"},"NestedRequiredReference":{"Text":"e3 c2 nrr"}}]',
140+
'{"Number":7,"Text":"e3 or","NestedCollection":[{"Text":"e3 or c1"},{"Text":"e3 or c2"}],"NestedOptionalReference":{"Text":"e3 or nor"},"NestedRequiredReference":{"Text":"e3 or nrr"}}',
141+
'{"Number":7,"Text":"e3 rr","NestedCollection":[{"Text":"e3 rr c1"},{"Text":"e3 rr c2"}],"NestedOptionalReference":{"Text":"e3 rr nor"},"NestedRequiredReference":{"Text":"e3 rr nrr"}}',
142+
3,
143+
'e3')
144+
""");
145+
146+
// null scalar on top level
147+
await context.Database.ExecuteSqlAsync(
148+
$$$"""
149+
INSERT INTO "Entities" ("Collection", "OptionalReference", "RequiredReference", "Id", "Name")
150+
VALUES (
151+
'[{"Number":null,"Text":"e4 c1","NestedCollection":[{"Text":"e4 c1 c1"},{"Text":"e4 c1 c2"}],"NestedOptionalReference":{"Text":"e4 c1 nor"},"NestedRequiredReference":{"Text":"e4 c1 nrr"}},{"Number":null,"Text":"e4 c2","NestedCollection":[{"Text":"e4 c2 c1"},{"Text":"e4 c2 c2"}],"NestedOptionalReference":{"Text":"e4 c2 nor"},"NestedRequiredReference":{"Text":"e4 c2 nrr"}}]',
152+
'{"Number":null,"Text":"e4 or","NestedCollection":[{"Text":"e4 or c1"},{"Text":"e4 or c2"}],"NestedOptionalReference":{"Text":"e4 or nor"},"NestedRequiredReference":{"Text":"e4 or nrr"}}',
153+
'{"Number":null,"Text":"e4 rr","NestedCollection":[{"Text":"e4 rr c1"},{"Text":"e4 rr c2"}],"NestedOptionalReference":{"Text":"e4 rr nor"},"NestedRequiredReference":{"Text":"e4 rr nrr"}}',
154+
4,
155+
'e4')
156+
""");
157+
158+
// missing required navigation
159+
await context.Database.ExecuteSqlAsync(
160+
$$$"""
161+
INSERT INTO "Entities" ("Collection", "OptionalReference", "RequiredReference", "Id", "Name")
162+
VALUES (
163+
'[{"Number":7,"Text":"e5 c1","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c1 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c1 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c1 nor"}},{"Number":7,"Text":"e5 c2","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c2 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c2 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e5 c2 nor"}}]',
164+
'{"Number":7,"Text":"e5 or","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e5 or c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e5 or c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e5 or nor"}}',
165+
'{"Number":7,"Text":"e5 rr","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e5 rr c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e5 rr c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e5 rr nor"}}',
166+
5,
167+
'e5')
168+
""");
169+
170+
// null required navigation
171+
await context.Database.ExecuteSqlAsync(
172+
$$$"""
173+
INSERT INTO "Entities" ("Collection", "OptionalReference", "RequiredReference", "Id", "Name")
174+
VALUES (
175+
'[{"Number":7,"Text":"e6 c1","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c1 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c1 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c1 nor"},"NestedRequiredReference":null},{"Number":7,"Text":"e6 c2","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c2 c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c2 c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e6 c2 nor"},"NestedRequiredReference":null}]',
176+
'{"Number":7,"Text":"e6 or","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e6 or c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e6 or c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e6 or nor"},"NestedRequiredReference":null}',
177+
'{"Number":7,"Text":"e6 rr","NestedCollection":[{"DoB":"2000-01-01T00:00:00Z","Text":"e6 rr c1"},{"DoB":"2000-01-01T00:00:00Z","Text":"e6 rr c2"}],"NestedOptionalReference":{"DoB":"2000-01-01T00:00:00Z","Text":"e6 rr nor"},"NestedRequiredReference":null}',
178+
6,
179+
'e6')
180+
""");
181+
}
182+
10183
protected override async Task Seed29219(DbContext ctx)
11184
{
12185
var entity1 = new MyEntity29219

0 commit comments

Comments
 (0)