Skip to content

Commit 31a8b0d

Browse files
feat: add tests for :copyfrom geo types in Postgres
1 parent 50d30d9 commit 31a8b0d

19 files changed

Lines changed: 950 additions & 35 deletions

File tree

end2end/EndToEndScaffold/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum KnownTestType
4949
PostgresDateTimeCopyFrom,
5050
PostgresArrayCopyFrom,
5151
PostgresGeoDataTypes,
52+
PostgresGeoCopyFrom,
5253
PostgresJsonDataTypes,
5354
PostgresInvalidJson,
5455

@@ -191,6 +192,7 @@ internal static class Config
191192
KnownTestType.PostgresDateTimeDataTypes,
192193
KnownTestType.PostgresArrayDataTypes,
193194
KnownTestType.PostgresGeoDataTypes,
195+
KnownTestType.PostgresGeoCopyFrom,
194196
KnownTestType.PostgresDataTypesOverride,
195197
KnownTestType.PostgresJsonDataTypes,
196198
KnownTestType.PostgresInvalidJson,
@@ -229,6 +231,7 @@ internal static class Config
229231
KnownTestType.PostgresDateTimeDataTypes,
230232
KnownTestType.PostgresArrayDataTypes,
231233
KnownTestType.PostgresGeoDataTypes,
234+
KnownTestType.PostgresGeoCopyFrom,
232235
KnownTestType.PostgresDataTypesOverride,
233236
KnownTestType.PostgresJsonDataTypes,
234237
KnownTestType.PostgresInvalidJson,

end2end/EndToEndScaffold/Templates/PostgresTests.cs

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,100 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
524524
CCircle = cCircle
525525
};
526526
var actual = await QuerySql.GetPostgresGeoTypes();
527-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CPoint, Is.EqualTo(expected.CPoint));
528-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CLine, Is.EqualTo(expected.CLine));
529-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CLseg, Is.EqualTo(expected.CLseg));
530-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CBox, Is.EqualTo(expected.CBox));
531-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CPath, Is.EqualTo(expected.CPath));
532-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CPolygon, Is.EqualTo(expected.CPolygon));
533-
Assert.That(actual{{Consts.UnknownRecordValuePlaceholder}}.CCircle, Is.EqualTo(expected.CCircle));
527+
AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}});
528+
529+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
530+
{
531+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
532+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
533+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
534+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
535+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
536+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
537+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
538+
}
539+
}
540+
"""
541+
},
542+
[KnownTestType.PostgresGeoCopyFrom] = new TestImpl
543+
{
544+
Impl = $$"""
545+
public static IEnumerable<TestCaseData> PostgresGeoCopyFromTestCases
546+
{
547+
get
548+
{
549+
yield return new TestCaseData(
550+
200,
551+
new NpgsqlPoint(1, 2),
552+
new NpgsqlLine(3, 4, 5),
553+
new NpgsqlLSeg(1, 2, 3, 4),
554+
new NpgsqlBox(1, 2, 3, 4),
555+
new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }),
556+
new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }),
557+
new NpgsqlCircle(1, 2, 3)
558+
).SetName("Valid Geo Types Copy From");
559+
560+
yield return new TestCaseData(
561+
10,
562+
null,
563+
null,
564+
null,
565+
null,
566+
null,
567+
null,
568+
null
569+
).SetName("Null Geo Types Copy From");
570+
}
571+
}
572+
573+
[Test]
574+
[TestCaseSource(nameof(PostgresGeoCopyFromTestCases))]
575+
public async Task TestPostgresGeoCopyFrom(
576+
int batchSize,
577+
NpgsqlPoint? cPoint,
578+
NpgsqlLine? cLine,
579+
NpgsqlLSeg? cLSeg,
580+
NpgsqlBox? cBox,
581+
NpgsqlPath? cPath,
582+
NpgsqlPolygon? cPolygon,
583+
NpgsqlCircle? cCircle)
584+
{
585+
var batchArgs = Enumerable.Range(0, batchSize)
586+
.Select(_ => new QuerySql.InsertPostgresGeoTypesBatchArgs
587+
{
588+
CPoint = cPoint,
589+
CLine = cLine,
590+
CLseg = cLSeg,
591+
CBox = cBox,
592+
CPath = cPath,
593+
CPolygon = cPolygon,
594+
CCircle = cCircle
595+
})
596+
.ToList();
597+
await QuerySql.InsertPostgresGeoTypesBatch(batchArgs);
598+
var expected = new QuerySql.GetPostgresGeoTypesRow
599+
{
600+
CPoint = cPoint,
601+
CLine = cLine,
602+
CLseg = cLSeg,
603+
CBox = cBox,
604+
CPath = cPath,
605+
CPolygon = cPolygon,
606+
CCircle = cCircle
607+
};
608+
var actual = await QuerySql.GetPostgresGeoTypes();
609+
AssertSingularEquals(expected, actual{{Consts.UnknownRecordValuePlaceholder}});
610+
611+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
612+
{
613+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
614+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
615+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
616+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
617+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
618+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
619+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
620+
}
534621
}
535622
"""
536623
},

end2end/EndToEndTests/NpgsqlDapperTester.generated.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,56 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
592592
CCircle = cCircle
593593
};
594594
var actual = await QuerySql.GetPostgresGeoTypes();
595-
Assert.That(actual.CPoint, Is.EqualTo(expected.CPoint));
596-
Assert.That(actual.CLine, Is.EqualTo(expected.CLine));
597-
Assert.That(actual.CLseg, Is.EqualTo(expected.CLseg));
598-
Assert.That(actual.CBox, Is.EqualTo(expected.CBox));
599-
Assert.That(actual.CPath, Is.EqualTo(expected.CPath));
600-
Assert.That(actual.CPolygon, Is.EqualTo(expected.CPolygon));
601-
Assert.That(actual.CCircle, Is.EqualTo(expected.CCircle));
595+
AssertSingularEquals(expected, actual);
596+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
597+
{
598+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
599+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
600+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
601+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
602+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
603+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
604+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
605+
}
606+
}
607+
608+
public static IEnumerable<TestCaseData> PostgresGeoCopyFromTestCases
609+
{
610+
get
611+
{
612+
yield return new TestCaseData(200, new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types Copy From");
613+
yield return new TestCaseData(10, null, null, null, null, null, null, null).SetName("Null Geo Types Copy From");
614+
}
615+
}
616+
617+
[Test]
618+
[TestCaseSource(nameof(PostgresGeoCopyFromTestCases))]
619+
public async Task TestPostgresGeoCopyFrom(int batchSize, NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle)
620+
{
621+
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresGeoTypesBatchArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }).ToList();
622+
await QuerySql.InsertPostgresGeoTypesBatch(batchArgs);
623+
var expected = new QuerySql.GetPostgresGeoTypesRow
624+
{
625+
CPoint = cPoint,
626+
CLine = cLine,
627+
CLseg = cLSeg,
628+
CBox = cBox,
629+
CPath = cPath,
630+
CPolygon = cPolygon,
631+
CCircle = cCircle
632+
};
633+
var actual = await QuerySql.GetPostgresGeoTypes();
634+
AssertSingularEquals(expected, actual);
635+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
636+
{
637+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
638+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
639+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
640+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
641+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
642+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
643+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
644+
}
602645
}
603646

604647
[Test]

end2end/EndToEndTests/NpgsqlTester.generated.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,56 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
592592
CCircle = cCircle
593593
};
594594
var actual = await QuerySql.GetPostgresGeoTypes();
595-
Assert.That(actual.Value.CPoint, Is.EqualTo(expected.CPoint));
596-
Assert.That(actual.Value.CLine, Is.EqualTo(expected.CLine));
597-
Assert.That(actual.Value.CLseg, Is.EqualTo(expected.CLseg));
598-
Assert.That(actual.Value.CBox, Is.EqualTo(expected.CBox));
599-
Assert.That(actual.Value.CPath, Is.EqualTo(expected.CPath));
600-
Assert.That(actual.Value.CPolygon, Is.EqualTo(expected.CPolygon));
601-
Assert.That(actual.Value.CCircle, Is.EqualTo(expected.CCircle));
595+
AssertSingularEquals(expected, actual.Value);
596+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
597+
{
598+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
599+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
600+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
601+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
602+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
603+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
604+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
605+
}
606+
}
607+
608+
public static IEnumerable<TestCaseData> PostgresGeoCopyFromTestCases
609+
{
610+
get
611+
{
612+
yield return new TestCaseData(200, new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types Copy From");
613+
yield return new TestCaseData(10, null, null, null, null, null, null, null).SetName("Null Geo Types Copy From");
614+
}
615+
}
616+
617+
[Test]
618+
[TestCaseSource(nameof(PostgresGeoCopyFromTestCases))]
619+
public async Task TestPostgresGeoCopyFrom(int batchSize, NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle)
620+
{
621+
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresGeoTypesBatchArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }).ToList();
622+
await QuerySql.InsertPostgresGeoTypesBatch(batchArgs);
623+
var expected = new QuerySql.GetPostgresGeoTypesRow
624+
{
625+
CPoint = cPoint,
626+
CLine = cLine,
627+
CLseg = cLSeg,
628+
CBox = cBox,
629+
CPath = cPath,
630+
CPolygon = cPolygon,
631+
CCircle = cCircle
632+
};
633+
var actual = await QuerySql.GetPostgresGeoTypes();
634+
AssertSingularEquals(expected, actual.Value);
635+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
636+
{
637+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
638+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
639+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
640+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
641+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
642+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
643+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
644+
}
602645
}
603646

604647
[Test]

end2end/EndToEndTestsLegacy/NpgsqlDapperTester.generated.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,56 @@ public async Task TestPostgresGeoTypes(NpgsqlPoint? cPoint, NpgsqlLine? cLine, N
592592
CCircle = cCircle
593593
};
594594
var actual = await QuerySql.GetPostgresGeoTypes();
595-
Assert.That(actual.CPoint, Is.EqualTo(expected.CPoint));
596-
Assert.That(actual.CLine, Is.EqualTo(expected.CLine));
597-
Assert.That(actual.CLseg, Is.EqualTo(expected.CLseg));
598-
Assert.That(actual.CBox, Is.EqualTo(expected.CBox));
599-
Assert.That(actual.CPath, Is.EqualTo(expected.CPath));
600-
Assert.That(actual.CPolygon, Is.EqualTo(expected.CPolygon));
601-
Assert.That(actual.CCircle, Is.EqualTo(expected.CCircle));
595+
AssertSingularEquals(expected, actual);
596+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
597+
{
598+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
599+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
600+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
601+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
602+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
603+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
604+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
605+
}
606+
}
607+
608+
public static IEnumerable<TestCaseData> PostgresGeoCopyFromTestCases
609+
{
610+
get
611+
{
612+
yield return new TestCaseData(200, new NpgsqlPoint(1, 2), new NpgsqlLine(3, 4, 5), new NpgsqlLSeg(1, 2, 3, 4), new NpgsqlBox(1, 2, 3, 4), new NpgsqlPath(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlPolygon(new NpgsqlPoint[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }), new NpgsqlCircle(1, 2, 3)).SetName("Valid Geo Types Copy From");
613+
yield return new TestCaseData(10, null, null, null, null, null, null, null).SetName("Null Geo Types Copy From");
614+
}
615+
}
616+
617+
[Test]
618+
[TestCaseSource(nameof(PostgresGeoCopyFromTestCases))]
619+
public async Task TestPostgresGeoCopyFrom(int batchSize, NpgsqlPoint? cPoint, NpgsqlLine? cLine, NpgsqlLSeg? cLSeg, NpgsqlBox? cBox, NpgsqlPath? cPath, NpgsqlPolygon? cPolygon, NpgsqlCircle? cCircle)
620+
{
621+
var batchArgs = Enumerable.Range(0, batchSize).Select(_ => new QuerySql.InsertPostgresGeoTypesBatchArgs { CPoint = cPoint, CLine = cLine, CLseg = cLSeg, CBox = cBox, CPath = cPath, CPolygon = cPolygon, CCircle = cCircle }).ToList();
622+
await QuerySql.InsertPostgresGeoTypesBatch(batchArgs);
623+
var expected = new QuerySql.GetPostgresGeoTypesRow
624+
{
625+
CPoint = cPoint,
626+
CLine = cLine,
627+
CLseg = cLSeg,
628+
CBox = cBox,
629+
CPath = cPath,
630+
CPolygon = cPolygon,
631+
CCircle = cCircle
632+
};
633+
var actual = await QuerySql.GetPostgresGeoTypes();
634+
AssertSingularEquals(expected, actual);
635+
void AssertSingularEquals(QuerySql.GetPostgresGeoTypesRow x, QuerySql.GetPostgresGeoTypesRow y)
636+
{
637+
Assert.That(x.CPoint, Is.EqualTo(y.CPoint));
638+
Assert.That(x.CLine, Is.EqualTo(y.CLine));
639+
Assert.That(x.CLseg, Is.EqualTo(y.CLseg));
640+
Assert.That(x.CBox, Is.EqualTo(y.CBox));
641+
Assert.That(x.CPath, Is.EqualTo(y.CPath));
642+
Assert.That(x.CPolygon, Is.EqualTo(y.CPolygon));
643+
Assert.That(x.CCircle, Is.EqualTo(y.CCircle));
644+
}
602645
}
603646

604647
[Test]

0 commit comments

Comments
 (0)