diff --git a/test/NetTopologySuite.IO.PostGis.Test/AbstractIOFixture.cs b/test/NetTopologySuite.IO.PostGis.Test/AbstractIOFixture.cs index 73e28df..5c5af0b 100644 --- a/test/NetTopologySuite.IO.PostGis.Test/AbstractIOFixture.cs +++ b/test/NetTopologySuite.IO.PostGis.Test/AbstractIOFixture.cs @@ -211,13 +211,13 @@ public void PerformTest(Geometry gIn) Geometry gParsed = null; Assert.DoesNotThrow(() => gParsed = Read(b), "Threw exception during read:\n{0}", writer.WriteFormatted(gIn)); - Assert.IsNotNull(gParsed, "Could not be parsed\n{0}", gIn); + Assert.That(gParsed, Is.Not.Null, $"Could not be parsed\n{gIn}"); CheckEquality(gIn, gParsed, writer); } protected virtual void CheckEquality(Geometry gIn, Geometry gParsed, WKTWriter writer) { - Assert.IsTrue(gIn.EqualsExact(gParsed), "Instances are not equal\n{0}\n\n{1}", gIn, gParsed); + Assert.That(gIn.EqualsExact(gParsed), Is.True, $"Instances are not equal\n{gIn}\n\n{gParsed}"); } protected abstract Geometry Read(byte[] b); diff --git a/test/NetTopologySuite.IO.PostGis.Test/Issue174.cs b/test/NetTopologySuite.IO.PostGis.Test/Issue174.cs index 2c04c7d..3e19e94 100644 --- a/test/NetTopologySuite.IO.PostGis.Test/Issue174.cs +++ b/test/NetTopologySuite.IO.PostGis.Test/Issue174.cs @@ -16,9 +16,9 @@ public void ensure_NetTopologySuite_IO_GeoJSON_assembly_is_strongly_named() private void AssertStronglyNamedAssembly(Type typeFromAssemblyToCheck) { - Assert.IsNotNull(typeFromAssemblyToCheck, "Cannot determine assembly from null"); + Assert.That(typeFromAssemblyToCheck, Is.Not.Null, "Cannot determine assembly from null"); var assembly = typeFromAssemblyToCheck.Assembly; - StringAssert.DoesNotContain("PublicKeyToken=null", assembly.FullName, "Strongly named assembly should have a PublicKeyToken in fully qualified name"); + Assert.That(assembly.FullName.Contains("PublicKeyToken=null"), Is.False, "Strongly named assembly should have a PublicKeyToken in fully qualified name"); } } } diff --git a/test/NetTopologySuite.IO.PostGis.Test/NetTopologySuite.IO.PostGis.Test.csproj b/test/NetTopologySuite.IO.PostGis.Test/NetTopologySuite.IO.PostGis.Test.csproj index d5022fd..cd71c00 100644 --- a/test/NetTopologySuite.IO.PostGis.Test/NetTopologySuite.IO.PostGis.Test.csproj +++ b/test/NetTopologySuite.IO.PostGis.Test/NetTopologySuite.IO.PostGis.Test.csproj @@ -1,12 +1,12 @@  - netcoreapp3.1 + net6.0 - - + + @@ -14,9 +14,9 @@ - - - + + + \ No newline at end of file diff --git a/test/NetTopologySuite.IO.PostGis.Test/PostGisTest.cs b/test/NetTopologySuite.IO.PostGis.Test/PostGisTest.cs index 564ca03..2624167 100644 --- a/test/NetTopologySuite.IO.PostGis.Test/PostGisTest.cs +++ b/test/NetTopologySuite.IO.PostGis.Test/PostGisTest.cs @@ -155,20 +155,20 @@ private static void General(GeometryFactory geomFactory, string wkt, int srid) geom.SRID = srid; regeom.SRID = srid; - Assert.IsTrue(geom.EqualsExact(regeom)); - Assert.AreEqual(parsed, reparsed); + Assert.That(geom.EqualsExact(regeom), Is.True); + Assert.That(reparsed, Is.EqualTo(parsed)); var pgr = new PostGisReader(geomFactory); byte[] bytesB = new PostGisWriter(ByteOrder.BigEndian).Write(regeom); var regeom2 = pgr.Read(bytesB); - Assert.IsTrue(geom.EqualsExact(regeom2)); + Assert.That(geom.EqualsExact(regeom2), Is.True); byte[] bytesL = new PostGisWriter(ByteOrder.LittleEndian).Write(regeom); var regeom3 = pgr.Read(bytesL); - Assert.IsTrue(geom.EqualsExact(regeom3)); - Assert.IsTrue(regeom2.EqualsExact(regeom3)); + Assert.That(geom.EqualsExact(regeom3), Is.True); + Assert.That(regeom2.EqualsExact(regeom3), Is.True); - Assert.AreEqual(bytesB.Length, bytesL.Length); + Assert.That(bytesB.Length, Is.EqualTo(bytesL.Length)); } [Test] @@ -176,19 +176,19 @@ public void Point3D() { // Warm up assertions: var point2D = new Point(1, 2); - Assert.IsTrue(double.IsNaN(point2D.Z)); + Assert.That(double.IsNaN(point2D.Z), Is.True); var point3D = new Point(1, 2, 3); - Assert.IsFalse(double.IsNaN(point3D.Z)); + Assert.That(double.IsNaN(point3D.Z), Is.False); // The real thing: var source = new Point(123, 456, 789); var pgWriter = new PostGisWriter { HandleOrdinates = Ordinates.XYZ }; byte[] bytes = pgWriter.Write(source); var target = (Point)new PostGisReader().Read(bytes); - Assert.AreEqual(source.X, target.X); - Assert.AreEqual(source.Y, target.Y); - Assert.AreEqual(source.Z, target.Z); + Assert.That(source.X, Is.EqualTo(target.X)); + Assert.That(source.Y, Is.EqualTo(target.Y)); + Assert.That(source.Z, Is.EqualTo(target.Z)); } [Test] @@ -207,9 +207,9 @@ public void LineString3D() var target = (LineString)new PostGisReader().Read(bytes); for (int i = 0; i < size; i++) { - Assert.AreEqual(source.Coordinates[i].X, target.Coordinates[i].X); - Assert.AreEqual(source.Coordinates[i].Y, target.Coordinates[i].Y); - Assert.AreEqual(source.Coordinates[i].Z, target.Coordinates[i].Z); + Assert.That(source.Coordinates[i].X, Is.EqualTo(target.Coordinates[i].X)); + Assert.That(source.Coordinates[i].Y, Is.EqualTo(target.Coordinates[i].Y)); + Assert.That(source.Coordinates[i].Z, Is.EqualTo(target.Coordinates[i].Z)); } } @@ -223,7 +223,7 @@ public void GeometryCollection_empty() var target = (GeometryCollection)new PostGisReader().Read(bytes); - Assert.AreEqual(source.Count, target.Count); + Assert.That(source.Count, Is.EqualTo(target.Count)); } [Test] @@ -246,14 +246,40 @@ public void OrdinatesContainXY(Ordinates ordinates) [Test, Combinatorial] public void WriteCoordinates( - [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.None)] Ordinates writerCoords, - [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.None)] Ordinates readerCoords, - [Values(Ordinates.XY, Ordinates.XYZ)] Ordinates pointCoords) + [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.XYM, Ordinates.XYZM, Ordinates.None)] Ordinates writerCoords, + [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.XYM, Ordinates.XYZM, Ordinates.None)] Ordinates readerCoords, + [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.XYM, Ordinates.XYZM)] Ordinates pointCoords) { + var gf = NtsGeometryServices.Instance.CreateGeometryFactory(); + var writer = new PostGisWriter { HandleOrdinates = writerCoords }; - var reader = new PostGisReader { HandleOrdinates = readerCoords }; + var reader = new PostGisReader(gf) { HandleOrdinates = readerCoords }; + + CoordinateSequence sequence; + switch (pointCoords) + { + case Ordinates.XY: + sequence = gf.CoordinateSequenceFactory.Create(1, 2, 0); + break; + case Ordinates.XYZ: + sequence = gf.CoordinateSequenceFactory.Create(1, 3, 0); + break; + case Ordinates.XYM: + sequence = gf.CoordinateSequenceFactory.Create(1, 3, 1); + break; + case Ordinates.XYZM: + sequence = gf.CoordinateSequenceFactory.Create(1, 4, 1); + break; + default: + throw new ArgumentOutOfRangeException(nameof(pointCoords)); + } + sequence.SetX(0, 1); + sequence.SetY(0, 2); + if (sequence.HasZ) sequence.SetZ(0, 3); + if (sequence.HasM) sequence.SetZ(0, 4); - byte[] bytes = writer.Write(pointCoords == Ordinates.XYZ ? new Point(1, 1, 1) : new Point(1, 1)); + var point = gf.CreatePoint(sequence); + byte[] bytes = writer.Write(point); var output = (Point)reader.Read(bytes); var expectedOutputCoords = pointCoords;