Skip to content

Commit 2736323

Browse files
Added github workflow for tests on PostGIS 3.2 (#24)
1 parent 9fdcaae commit 2736323

File tree

5 files changed

+195
-170
lines changed

5 files changed

+195
-170
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: PostGIS_3.2
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
test_on_postgis_32:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
dotnet-version: [ '2.1.x' ]
12+
postgis-version: [ 'postgis/postgis:14-3.2-alpine', 'postgis/postgis:13-3.2-alpine', 'postgis/postgis:12-3.2-alpine','postgis/postgis:11-3.2-alpine','postgis/postgis:10-3.2-alpine', 'postgis/postgis:9.6-3.2-alpine' ]
13+
services:
14+
postgis:
15+
image: ${{ matrix.postgis-version }}
16+
env:
17+
POSTGRES_USER: reader
18+
POSTGRES_PASSWORD: reader
19+
POSTGRES_DB: postgistest
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
28+
steps:
29+
- name: init database table owm_cities
30+
run: psql -h localhost -p 5432 -d postgistest -U reader -c "CREATE TABLE IF NOT EXISTS owm_cities(id integer primary key, city_name varchar not null, geom geometry not null);"
31+
env:
32+
PGPASSWORD: reader
33+
34+
- name: init database table test_geometry
35+
run: psql -h localhost -p 5432 -d postgistest -U reader -c "CREATE TABLE test_geometry(id integer primary key, geom geometry);"
36+
env:
37+
PGPASSWORD: reader
38+
39+
- name: init database table test_geography
40+
run: psql -h localhost -p 5432 -d postgistest -U reader -c "CREATE TABLE test_geography(id integer primary key, geog geography);"
41+
env:
42+
PGPASSWORD: reader
43+
44+
- name: get source
45+
uses: actions/checkout@v2
46+
47+
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
48+
uses: actions/setup-dotnet@v1.7.2
49+
with:
50+
dotnet-version: ${{ matrix.dotnet-version }}
51+
52+
- name: Install dependencies
53+
run: dotnet restore
54+
55+
- name: Build
56+
run: dotnet build --configuration Release --no-restore
57+
- name: Test
58+
run: dotnet test --no-restore --verbosity normal

LinqToDBPostGisNetTopologySuite.Tests/GeometryAccessorsTests.cs

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33

44
using LinqToDB;
5+
using LinqToDB.Data;
56
using NUnit.Framework;
67

78
using NTSGS = NetTopologySuite.Geometries;
@@ -72,47 +73,35 @@ public void TestSTBoundary()
7273
{
7374
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
7475
{
75-
const string wkt1 = "LINESTRING(100 150,50 60, 70 80, 160 170)";
76-
db.TestGeometries
77-
.Value(g => g.Id, 1)
78-
.Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt1))
79-
.Insert();
80-
81-
const string wkt2 = "POLYGON ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))";
82-
db.TestGeometries
83-
.Value(g => g.Id, 2)
84-
.Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt2))
85-
.Insert();
86-
87-
const string wkt3 = "MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )";
88-
db.TestGeometries
89-
.Value(g => g.Id, 3)
90-
.Value(g => g.Geometry, () => GeometryInput.STGeomFromText(wkt3))
91-
.Insert();
92-
93-
Assert.AreEqual(
94-
"MULTIPOINT(100 150,160 170)",
95-
db.TestGeometries
96-
.Where(g => g.Id == 1)
97-
.Select(g => g.Geometry.STBoundary().STAsText())
98-
.Single());
99-
100-
Assert.AreEqual(
101-
"MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),(70 40,100 50,120 80,80 110,50 90,70 40))",
102-
db.TestGeometries
103-
.Where(g => g.Id == 2)
104-
.Select(g => g.Geometry.STBoundary().STAsText())
105-
.Single());
106-
107-
Assert.AreEqual(
108-
"MULTIPOINT Z (-1 1 1,1 1 0.75)",
109-
db.TestGeometries
110-
.Where(g => g.Id == 3)
111-
.Select(g => g.Geometry.STBoundary().STAsText())
112-
.Single());
76+
const string Wkt1 = "LINESTRING(100 150,50 60, 70 80, 160 170)";
77+
const string Wkt2 =
78+
"POLYGON ((10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130), (70 40, 100 50, 120 80, 80 110, 50 90, 70 40))";
79+
const string Wkt3 = "MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )";
80+
81+
const string Expected1 = "MULTIPOINT(100 150,160 170)";
82+
const string Expected2 =
83+
"MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),(70 40,100 50,120 80,80 110,50 90,70 40))";
84+
const string Expected3V1 = "MULTIPOINT Z (-1 1 1,1 1 0.75)";
85+
const string Expected3V2 = "MULTIPOINT Z (1 1 1,-1 1 1)";
86+
87+
var result1 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt1).STBoundary().STAsText());
88+
var result2 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt2).STBoundary().STAsText());
89+
var result3 = db.Select(() => GeometryInput.STGeomFromEWKT(Wkt3).STBoundary().STAsText());
90+
91+
Assert.AreEqual(Expected1, result1);
92+
Assert.AreEqual(Expected2, result2);
93+
if (CurrentVersion <
94+
new Version(
95+
"3.2.0")) //See https://postgis.net/docs/ST_Boundary.html. Result is different based on postgis version
96+
{
97+
Assert.AreEqual(Expected3V1, result3);
98+
}
99+
else
100+
{
101+
Assert.AreEqual(Expected3V2, result3);
102+
}
113103

114104
Assert.IsNull(db.Select(() => GeometryAccessors.STBoundary((NTSG)null)));
115-
Assert.AreEqual("MULTIPOINT(100 150,160 170)", db.Select(() => GeometryAccessors.STBoundary(wkt1).STAsText()));
116105
}
117106
}
118107

@@ -355,16 +344,9 @@ public void TestSTGeometryType()
355344
db.Select(() => GeometryInput.STGeomFromText(Wkt)
356345
.STGeometryType()));
357346

358-
// TODO: Need some research for reason of error:
359-
// function st_geometrytype(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts.
360-
if (this.CurrentVersion >= new Version("3.0.0"))
361-
{
362-
Assert.AreEqual(
363-
"ST_LineString",
364-
db.Select(() => GeometryAccessors.STGeometryType(Wkt)));
365-
366-
Assert.IsNull(db.Select(() => GeometryAccessors.STGeometryType((NTSG)null)));
367-
}
347+
Assert.AreEqual(
348+
"ST_LineString",
349+
db.Select(() => GeometryAccessors.STGeometryType(Wkt)));
368350
}
369351
}
370352

@@ -923,26 +905,40 @@ public void TestSTStartPoint()
923905
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
924906
{
925907
const string Wkt1 = "LINESTRING(0 1, 0 2)";
926-
db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();
927-
928908
const string Wkt2 = "POINT(0 1)";
929-
db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();
930909

931-
Assert.AreEqual(
932-
"POINT(0 1)",
933-
db.TestGeometries
934-
.Where(g => g.Id == 1)
935-
.Select(g => g.Geometry.STStartPoint().STAsText())
936-
.Single());
910+
const double ExpectedX = 0;
911+
const double ExpectedY = 1;
937912

938-
Assert.IsNull(db.TestGeometries
939-
.Where(g => g.Id == 2)
940-
.Select(g => g.Geometry.STStartPoint())
941-
.Single());
913+
var actual11 = db.Select(() => GeometryInput.STGeomFromText(Wkt1).STStartPoint());
914+
var actual12 = db.Select(() => GeometryAccessors.STStartPoint(Wkt1));
915+
916+
var actual2 = db.Select(() => GeometryAccessors.STStartPoint((NTSG)null));
917+
918+
var actual31 = db.Select(() => GeometryInput.STGeomFromText(Wkt2).STStartPoint());
919+
var actual32 = db.Select(() => GeometryAccessors.STStartPoint(Wkt2));
920+
921+
922+
Assert.AreEqual(ExpectedX, actual11.Coordinates[0].X);
923+
Assert.AreEqual(ExpectedY, actual11.Coordinates[0].Y);
942924

943-
Assert.AreEqual("POINT(0 1)", db.Select(() => GeometryAccessors.STStartPoint(Wkt1).STAsText()));
944-
Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint(Wkt2)));
945-
Assert.IsNull(db.Select(() => GeometryAccessors.STStartPoint((NTSG)null)));
925+
Assert.AreEqual(ExpectedX, actual12.Coordinates[0].X);
926+
Assert.AreEqual(ExpectedY, actual12.Coordinates[0].Y);
927+
928+
Assert.IsNull(actual2);
929+
930+
if (CurrentVersion < new Version("3.2.0"))
931+
{
932+
Assert.IsNull(actual31);
933+
Assert.IsNull(actual32);
934+
}
935+
else
936+
{
937+
Assert.AreEqual(ExpectedX, actual31.Coordinates[0].X);
938+
Assert.AreEqual(ExpectedY, actual31.Coordinates[0].Y);
939+
Assert.AreEqual(ExpectedX, actual32.Coordinates[0].X);
940+
Assert.AreEqual(ExpectedY, actual32.Coordinates[0].Y);
941+
}
946942
}
947943
}
948944

LinqToDBPostGisNetTopologySuite.Tests/GeometryEditorsTests.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -672,36 +672,37 @@ public void TestSTLineMerge()
672672

673673
Assert.AreEqual(
674674
"LINESTRING(-29 -27,-30 -29.7,-36 -31,-45 -33,-46 -32)",
675-
db.Select(() => GeometryEditors.STLineMerge("MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))").STAsText()));
675+
db.Select(() =>
676+
GeometryEditors
677+
.STLineMerge("MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))")
678+
.STAsText()));
676679
}
677680
}
678681

679-
680682
[Test]
681683
public void TestSTLineToCurve()
682684
{
685+
const string Wkt = "POINT(1 3)";
683686
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
684687
{
685-
const string Wkt = "POINT(1 3)";
686-
db.TestGeometries
687-
.Value(g => g.Id, 1)
688-
.Value(g => g.Geometry, () =>
689-
GeometryInput.STGeomFromText(Wkt).STBuffer(3.0))
690-
.Insert();
688+
var itemQuery = db.SelectQuery(() => GeometryInput.STGeomFromText(Wkt).STBuffer(3.0));
691689

692690
// NTS error: 'Geometry type not recognized. GeometryCode: 10'
693-
var curvePolygon = db.TestGeometries
694-
.Where(g => g.Id == 1)
695-
.Select(g => g.Geometry.STLineToCurve().STAsText())
696-
.Single();
697-
698-
Assert.AreEqual("CURVEPOLYGON(CIRCULARSTRING(4 3,-2 2.99999999999999,4 3))", curvePolygon);
699-
700-
Assert.IsNull(db.Select(() => GeometryEditors.STLineToCurve((NTSG)null)));
691+
var actual1 = itemQuery
692+
.Select(item => item.STLineToCurve().STPoints()).Single();
693+
var actual2 = db.Select(() => GeometryEditors.STLineToCurve((NTSG)null));
694+
695+
Assert.AreEqual(4, actual1.Coordinates[0].X, 5);
696+
Assert.AreEqual(3, actual1.Coordinates[0].Y, 5);
697+
Assert.AreEqual(-2, actual1.Coordinates[1].X, 5);
698+
Assert.AreEqual(3, actual1.Coordinates[1].Y, 5);
699+
Assert.AreEqual(4, actual1.Coordinates[2].X, 5);
700+
Assert.AreEqual(3, actual1.Coordinates[2].Y, 5);
701+
702+
Assert.IsNull(actual2);
701703
}
702704
}
703705

704-
705706
[Test]
706707
public void TestSTMulti()
707708
{

0 commit comments

Comments
 (0)