Skip to content

Commit 91bfe62

Browse files
committed
Moved common function for reading current PostGIS version into tests base class
1 parent 36bb127 commit 91bfe62

12 files changed

+124
-164
lines changed

LinqToDBPostGisNetTopologySuite.Tests/GeometryAccessorsTests.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1313
[TestFixture]
1414
class GeometryAccessorsTests : TestsBase
1515
{
16-
private Version CurrentVersion;
17-
1816
[SetUp]
1917
public void Setup()
2018
{
2119
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
2220
{
23-
this.CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2421
db.TestGeometries.Delete();
2522
db.TestGeographies.Delete();
2623
}
@@ -90,7 +87,7 @@ public void TestSTBoundary()
9087
Assert.AreEqual(Expected2, result2);
9188

9289
//See https://postgis.net/docs/ST_Boundary.html. Result is different based on postgis version
93-
if (this.CurrentVersion < base.Version320)
90+
if (base.CurrentVersion < base.Version320)
9491
{
9592
Assert.AreEqual(Expected3V1, result3);
9693
}
@@ -217,7 +214,7 @@ public void TestSTEnvelope()
217214
Assert.AreEqual("POLYGON((0 0,0 3,1 3,1 0,0 0))", envelope);
218215

219216
// TODO: need explicit cast text to geometry
220-
if (this.CurrentVersion >= base.Version300)
217+
if (base.CurrentVersion >= base.Version300)
221218
{
222219
Assert.AreEqual(
223220
"POLYGON((0 0,0 3,1 3,1 0,0 0))",
@@ -567,7 +564,7 @@ public void TestSTIsEmpty()
567564

568565
// TODO: Need some research for reason of error:
569566
// function st_isempty(unknown) is not unique. Could not choose a best candidate function. You might need to add explicit type casts.
570-
if (this.CurrentVersion >= base.Version300)
567+
if (base.CurrentVersion >= base.Version300)
571568
{
572569
Assert.IsNull(db.Select(() => GeometryAccessors.STIsEmpty((NTSG)null)));
573570
Assert.IsTrue(db.Select(() => GeometryAccessors.STIsEmpty("CIRCULARSTRING EMPTY")));
@@ -644,7 +641,7 @@ public void TestSTMemSize()
644641
.Single());
645642

646643
// TODO: need explicit cast text to geometry
647-
if (this.CurrentVersion >= base.Version300)
644+
if (base.CurrentVersion >= base.Version300)
648645
{
649646
Assert.AreEqual(32, db.Select(() => GeometryAccessors.STMemSize("POINT(0 0)")));
650647
Assert.IsNull(db.Select(() => GeometryAccessors.STMemSize((NTSG)null)));
@@ -924,7 +921,7 @@ public void TestSTStartPoint()
924921

925922
Assert.IsNull(actual2);
926923

927-
if (this.CurrentVersion < base.Version320)
924+
if (base.CurrentVersion < base.Version320)
928925
{
929926
Assert.IsNull(actual31);
930927
Assert.IsNull(actual32);

LinqToDBPostGisNetTopologySuite.Tests/GeometryConstructorsTests.cs

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1212
[TestFixture]
1313
class GeometryConstructorsTests : TestsBase
1414
{
15-
private Version CurrentVersion;
16-
1715
[SetUp]
1816
public void Setup()
1917
{
2018
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
2119
{
22-
this.CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2320
db.TestGeometries.Delete();
2421
db.TestGeographies.Delete();
2522
}
@@ -299,100 +296,103 @@ public void TestSTPoint()
299296
[Test]
300297
public void TestSTPointZ()
301298
{
302-
if (CurrentVersion < new Version("3.2.0")) return;
299+
if (base.CurrentVersion >= base.Version320)
300+
{
301+
const double X = 1;
302+
const double Y = 2;
303+
const double Z = 3;
304+
const int Srid = 4326;
303305

304-
const double X = 1;
305-
const double Y = 2;
306-
const double Z = 3;
307-
const int Srid = 4326;
306+
NTSG res1;
307+
NTSG res2;
308308

309-
NTSG res1;
310-
NTSG res2;
309+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
310+
{
311+
res1 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z, Srid));
312+
res2 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z));
313+
}
311314

312-
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
313-
{
314-
res1 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z, Srid));
315-
res2 = db.Select(() => GeometryConstructors.STPointZ(X, Y, Z));
315+
Assert.IsNotNull(res1);
316+
Assert.AreEqual(X, res1.Coordinates[0].X);
317+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
318+
Assert.AreEqual(Z, res1.Coordinates[0].Z);
319+
Assert.AreEqual(Srid, res1.SRID);
320+
321+
Assert.IsNotNull(res2);
322+
Assert.AreEqual(X, res2.Coordinates[0].X);
323+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
324+
Assert.AreEqual(Z, res2.Coordinates[0].Z);
325+
Assert.AreEqual(-1, res2.SRID);
316326
}
317-
318-
Assert.IsNotNull(res1);
319-
Assert.AreEqual(X, res1.Coordinates[0].X);
320-
Assert.AreEqual(Y, res1.Coordinates[0].Y);
321-
Assert.AreEqual(Z, res1.Coordinates[0].Z);
322-
Assert.AreEqual(Srid, res1.SRID);
323-
324-
Assert.IsNotNull(res2);
325-
Assert.AreEqual(X, res2.Coordinates[0].X);
326-
Assert.AreEqual(Y, res2.Coordinates[0].Y);
327-
Assert.AreEqual(Z, res2.Coordinates[0].Z);
328-
Assert.AreEqual(-1, res2.SRID);
329327
}
330328

331329
[Test]
332330
public void TestSTPointM()
333331
{
334-
if (CurrentVersion < Version320) return;
332+
if (base.CurrentVersion >= base.Version320)
333+
{
334+
const double X = 4;
335+
const double Y = 5;
336+
const double M = 6;
337+
const int Srid = 4326;
335338

336-
const double X = 4;
337-
const double Y = 5;
338-
const double M = 6;
339-
const int Srid = 4326;
339+
NTSG res1;
340+
NTSG res2;
340341

341-
NTSG res1;
342-
NTSG res2;
342+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
343+
{
344+
res1 = db.Select(() => GeometryConstructors.STPointM(X, Y, M, Srid));
345+
res2 = db.Select(() => GeometryConstructors.STPointM(X, Y, M));
346+
}
343347

344-
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
345-
{
346-
res1 = db.Select(() => GeometryConstructors.STPointM(X, Y, M, Srid));
347-
res2 = db.Select(() => GeometryConstructors.STPointM(X, Y, M));
348+
Assert.IsNotNull(res1);
349+
Assert.AreEqual(X, res1.Coordinates[0].X);
350+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
351+
Assert.AreEqual(M, res1.Coordinates[0].M);
352+
Assert.AreEqual(Srid, res1.SRID);
353+
354+
Assert.IsNotNull(res2);
355+
Assert.AreEqual(X, res2.Coordinates[0].X);
356+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
357+
Assert.AreEqual(M, res2.Coordinates[0].M);
358+
Assert.AreEqual(-1, res2.SRID);
348359
}
349-
350-
Assert.IsNotNull(res1);
351-
Assert.AreEqual(X, res1.Coordinates[0].X);
352-
Assert.AreEqual(Y, res1.Coordinates[0].Y);
353-
Assert.AreEqual(M, res1.Coordinates[0].M);
354-
Assert.AreEqual(Srid, res1.SRID);
355-
356-
Assert.IsNotNull(res2);
357-
Assert.AreEqual(X, res2.Coordinates[0].X);
358-
Assert.AreEqual(Y, res2.Coordinates[0].Y);
359-
Assert.AreEqual(M, res2.Coordinates[0].M);
360-
Assert.AreEqual(-1, res2.SRID);
361360
}
362361

363362
[Test]
364363
public void TestSTPointZM()
365364
{
366-
if (CurrentVersion < Version320) return;
365+
if (base.CurrentVersion >= base.Version320)
366+
{
367+
const double X = 23.0;
368+
const double Y = 41.1;
369+
const double Z = 2.1;
370+
const double M = 1;
371+
const int Srid = 4326;
367372

368-
const double X = 23.0;
369-
const double Y = 41.1;
370-
const double Z = 2.1;
371-
const double M = 1;
372-
const int Srid = 4326;
373+
NTSG res1;
374+
NTSG res2;
373375

374-
NTSG res1;
375-
NTSG res2;
376+
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
377+
{
378+
res1 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M, Srid));
379+
res2 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M));
380+
}
376381

377-
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
378-
{
379-
res1 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M, Srid));
380-
res2 = db.Select(() => GeometryConstructors.STPointZM(X, Y, Z, M));
382+
Assert.IsNotNull(res1);
383+
Assert.AreEqual(X, res1.Coordinates[0].X);
384+
Assert.AreEqual(Y, res1.Coordinates[0].Y);
385+
Assert.AreEqual(Z, res1.Coordinates[0].Z);
386+
Assert.AreEqual(M, res1.Coordinates[0].M);
387+
Assert.AreEqual(Srid, res1.SRID);
388+
389+
Assert.IsNotNull(res2);
390+
Assert.AreEqual(X, res2.Coordinates[0].X);
391+
Assert.AreEqual(Y, res2.Coordinates[0].Y);
392+
Assert.AreEqual(Z, res2.Coordinates[0].Z);
393+
Assert.AreEqual(M, res2.Coordinates[0].M);
394+
Assert.AreEqual(-1, res2.SRID);
381395
}
382-
383-
Assert.IsNotNull(res1);
384-
Assert.AreEqual(X, res1.Coordinates[0].X);
385-
Assert.AreEqual(Y, res1.Coordinates[0].Y);
386-
Assert.AreEqual(Z, res1.Coordinates[0].Z);
387-
Assert.AreEqual(M, res1.Coordinates[0].M);
388-
Assert.AreEqual(Srid, res1.SRID);
389-
390-
Assert.IsNotNull(res2);
391-
Assert.AreEqual(X, res2.Coordinates[0].X);
392-
Assert.AreEqual(Y, res2.Coordinates[0].Y);
393-
Assert.AreEqual(Z, res2.Coordinates[0].Z);
394-
Assert.AreEqual(M, res2.Coordinates[0].M);
395-
Assert.AreEqual(-1, res2.SRID);
396396
}
397397

398398
[Test]
@@ -428,7 +428,7 @@ public void TestSTPolygon()
428428
.Single());
429429

430430
// TODO: ? reason of error? ST_Polygon(text) not works in 2.5 ?
431-
if (this.CurrentVersion >= base.Version300)
431+
if (base.CurrentVersion >= base.Version300)
432432
{
433433
db.TestGeometries
434434
.Value(g => g.Id, 3)
@@ -449,7 +449,7 @@ public void TestSTTileEnvelope()
449449
{
450450
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
451451
{
452-
if (this.CurrentVersion >= base.Version300)
452+
if (base.CurrentVersion >= base.Version300)
453453
{
454454
db.TestGeometries
455455
.Value(g => g.Id, 1)
@@ -508,7 +508,7 @@ public void TestSTHexagon()
508508
{
509509
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
510510
{
511-
if (this.CurrentVersion >= base.Version310)
511+
if (base.CurrentVersion >= base.Version310)
512512
{
513513
var origin = db.Select(() => GeometryConstructors.STMakePoint(0, 0));
514514

@@ -528,7 +528,7 @@ public void TestSTSquare()
528528
{
529529
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
530530
{
531-
if (this.CurrentVersion >= Version310)
531+
if (base.CurrentVersion >= Version310)
532532
{
533533
var origin = db.Select(() => GeometryConstructors.STMakePoint(0, 0));
534534

LinqToDBPostGisNetTopologySuite.Tests/GeometryEditorsTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1212
[TestFixture]
1313
class GeometryEditorsTests : TestsBase
1414
{
15-
private Version CurrentVersion { get; set; }
16-
1715
[SetUp]
1816
public void Setup()
1917
{
2018
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
2119
{
2220
db.TestGeometries.Delete();
2321
db.TestGeographies.Delete();
24-
CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2522
}
2623
}
2724

LinqToDBPostGisNetTopologySuite.Tests/GeometryOutputTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1414
[TestFixture]
1515
class GeometryOutputTests : TestsBase
1616
{
17-
private Version CurrentVersion;
18-
1917
[SetUp]
2018
public void Setup()
2119
{
2220
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
2321
{
24-
this.CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2522
db.TestGeometries.Delete();
2623
db.TestGeographies.Delete();
2724
}
@@ -231,7 +228,7 @@ public void TestSTAsGeoJSON()
231228
.Select(g => g.Geometry.STAsGeoJSON())
232229
.Single();
233230

234-
if (this.CurrentVersion >= base.Version300)
231+
if (base.CurrentVersion >= base.Version300)
235232
{
236233
Assert.AreEqual(
237234
"{\"type\":\"Point\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:3857\"}},\"coordinates\":[2.48,4.75]}",

LinqToDBPostGisNetTopologySuite.Tests/GeometryProcessingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ namespace LinqToDBPostGisNetTopologySuite.Tests
1212
[TestFixture]
1313
class GeometryProcessingTests : TestsBase
1414
{
15-
private Version CurrentVersion;
16-
1715
[SetUp]
1816
public void Setup()
1917
{
2018
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
2119
{
22-
this.CurrentVersion = new Version(db.Select(() => VersionFunctions.PostGISLibVersion()));
2320
db.TestGeometries.Delete();
2421
db.TestGeographies.Delete();
2522
}
@@ -113,7 +110,7 @@ public void TestSTConvexHull()
113110
.Single();
114111

115112
// TODO: need explicit cast text to geometry
116-
if (this.CurrentVersion >= base.Version300)
113+
if (base.CurrentVersion >= base.Version300)
117114
{
118115
Assert.AreEqual("POLYGON((50 5,10 8,10 10,100 190,150 30,150 10,50 5))", convexHull1);
119116
Assert.IsNull(db.Select(() => GeometryProcessing.STConvexHull((NTSG)null)));
@@ -158,7 +155,7 @@ public void TestSTGeneratePoints()
158155
{
159156
using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
160157
{
161-
if (this.CurrentVersion >= base.Version300)
158+
if (base.CurrentVersion >= base.Version300)
162159
{
163160
// TODO: Test for 2.3.0
164161

@@ -377,7 +374,7 @@ public void TestSTReducePrecision()
377374
? new Version(geos.Substring(0, geos.IndexOf('-')))
378375
: null;
379376

380-
if ((this.CurrentVersion >= base.Version310) &&
377+
if ((base.CurrentVersion >= base.Version310) &&
381378
(geosVersion != null) && (geosVersion >= new Version("3.9"))) // TODO: ? const
382379
{
383380
const string Wkt = "POINT(1.412 19.323)";

0 commit comments

Comments
 (0)