From f4857afc33d8d8d9c45ac15adfa93e186658a976 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Sat, 9 Jul 2022 16:10:41 -0400 Subject: [PATCH] Updated tests to work better for nodatime/newtonsoftjson and wkt (#1195) --- ...tJsonNetTopologySuiteWellKnownTextTests.cs | 125 +++++++++-------- ...tJsonNetTopologySuiteWellKnownTextTests.cs | 131 ++++++++++-------- 2 files changed, 139 insertions(+), 117 deletions(-) diff --git a/test/Extensions.Tests/NewtonsoftJsonNetTopologySuiteWellKnownTextTests.cs b/test/Extensions.Tests/NewtonsoftJsonNetTopologySuiteWellKnownTextTests.cs index 12629d9ce..456ce813c 100644 --- a/test/Extensions.Tests/NewtonsoftJsonNetTopologySuiteWellKnownTextTests.cs +++ b/test/Extensions.Tests/NewtonsoftJsonNetTopologySuiteWellKnownTextTests.cs @@ -13,6 +13,11 @@ private static T DeserializeObject(string geom, JsonSerializerSettings settin return JsonConvert.DeserializeObject>("{\"value\":\"" + geom + "\"}", settings)!.Value; } + private static string SerializeObject(T geom, JsonSerializerSettings settings) + { + return JsonConvert.SerializeObject(geom, settings).Trim('"'); + } + private readonly JsonSerializerSettings _settings; public NewtonsoftJsonNetTopologySuiteWellKnownTextTests(ITestOutputHelper outputHelper) : base(outputHelper) @@ -26,96 +31,100 @@ public NewtonsoftJsonNetTopologySuiteWellKnownTextTests(ITestOutputHelper output // typeof(MultiPolygon), // typeof(GeometryCollection) [Theory] - [InlineData("POINT(30 10)")] + [InlineData("POINT (30 10)")] public void Geometry_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be(new Point(30, 10)); + var value = DeserializeObject(geom, _settings) + .Should() + .Be(new Point(30, 10)) + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("LINESTRING(30 10, 10 30, 40 40)")] + [InlineData("LINESTRING (30 10, 10 30, 40 40)")] public void LineString_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be( - new LineString( - new[] - { - new Coordinate(30, 10), - new Coordinate(10, 30), - new Coordinate(40, 40), - } - ) - ); + var value = DeserializeObject(geom, _settings) + .Should() + .Be( + new LineString( + new[] + { + new Coordinate(30, 10), + new Coordinate(10, 30), + new Coordinate(40, 40), + } + ) + ).And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))")] + [InlineData("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))")] public void Polygon_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be( - new Polygon( - new LinearRing( - new[] - { - new Coordinate(30, 10), new Coordinate(40, 40), new Coordinate(20, 40), new Coordinate(10, 20), new Coordinate(30, 10) - } - ) - ) - ); + var value = DeserializeObject(geom, _settings) + .Should() + .Be( + new Polygon( + new LinearRing( + new[] + { + new Coordinate(30, 10), new Coordinate(40, 40), new Coordinate(20, 40), new Coordinate(10, 20), new Coordinate(30, 10) + } + ) + ) + ).And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTIPOINT(10 40, 40 30, 20 20, 30 10)")] + [InlineData("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")] public void MultiPoint_Tests(string geom) { - new ObjectAssertions(DeserializeObject(geom, _settings)) - .Be( - new MultiPoint( - new[] - { - new Point(10, 40), - new Point(40, 30), - new Point(20, 20), - new Point(30, 10) - } - ) - ); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .Be( + new MultiPoint( + new[] + { + new Point(10, 40), + new Point(40, 30), + new Point(20, 20), + new Point(30, 10) + } + ) + ).And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTILINESTRING((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))")] + [InlineData("MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))")] public void MultiLineString_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions( + DeserializeObject(geom, _settings) + ) + .BeOfType().Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)), ((30 20, 20 15, 20 25, 30 20)))")] + [InlineData("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)), ((30 20, 20 15, 20 25, 30 20)))")] public void MultiPolygon_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .BeOfType().Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("GEOMETRYCOLLECTION(POINT(40 10), LINESTRING(10 10, 20 20, 10 40), POLYGON((40 40, 20 45, 45 30, 40 40)))")] + [InlineData("GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON ((40 40, 20 45, 45 30, 40 40)))")] public void GeometryCollection_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .BeOfType().Subject; + SerializeObject(value, _settings).Should().Be(geom); } public class ValueOf diff --git a/test/Extensions.Tests/SystemTextJsonNetTopologySuiteWellKnownTextTests.cs b/test/Extensions.Tests/SystemTextJsonNetTopologySuiteWellKnownTextTests.cs index ebea77d75..2166bbc58 100644 --- a/test/Extensions.Tests/SystemTextJsonNetTopologySuiteWellKnownTextTests.cs +++ b/test/Extensions.Tests/SystemTextJsonNetTopologySuiteWellKnownTextTests.cs @@ -14,6 +14,11 @@ private static T DeserializeObject(string geom, JsonSerializerOptions setting return JsonSerializer.Deserialize("\"" + geom + "\"", settings); } + private static string SerializeObject(object geom, JsonSerializerOptions settings) + { + return JsonSerializer.Serialize(geom, settings).Trim('"'); + } + private readonly JsonSerializerOptions _settings; public SystemTextJsonNetTopologySuiteWellKnownTextTests(ITestOutputHelper outputHelper) : base(outputHelper) @@ -27,98 +32,106 @@ public SystemTextJsonNetTopologySuiteWellKnownTextTests(ITestOutputHelper output // typeof(MultiPolygon), // typeof(GeometryCollection) [Theory] - [InlineData("POINT(30 10)")] + [InlineData("POINT (30 10)")] public void Geometry_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be(new Point(30, 10)); + var value = DeserializeObject(geom, _settings) + .Should() + .Be(new Point(30, 10)) + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("LINESTRING(30 10, 10 30, 40 40)")] + [InlineData("LINESTRING (30 10, 10 30, 40 40)")] public void LineString_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be( - new LineString( - new[] - { - new Coordinate(30, 10), - new Coordinate(10, 30), - new Coordinate(40, 40), - } - ) - ); + var value = DeserializeObject(geom, _settings) + .Should() + .Be( + new LineString( + new[] + { + new Coordinate(30, 10), + new Coordinate(10, 30), + new Coordinate(40, 40), + } + ) + ) + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))")] + [InlineData("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))")] public void Polygon_Tests(string geom) { - DeserializeObject(geom, _settings) - .Should() - .Be( - new Polygon( - new LinearRing( - new[] - { - new Coordinate(30, 10), new Coordinate(40, 40), new Coordinate(20, 40), new Coordinate(10, 20), new Coordinate(30, 10) - } + var value = DeserializeObject(geom, _settings) + .Should() + .Be( + new Polygon( + new LinearRing( + new[] + { + new Coordinate(30, 10), new Coordinate(40, 40), new Coordinate(20, 40), new Coordinate(10, 20), new Coordinate(30, 10) + } + ) + ) ) - ) - ); + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTIPOINT(10 40, 40 30, 20 20, 30 10)")] + [InlineData("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")] public void MultiPoint_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .Be( - new MultiPoint( - new[] - { - new Point(10, 40), - new Point(40, 30), - new Point(20, 20), - new Point(30, 10) - } - ) - ); + var value = new ObjectAssertions( + DeserializeObject(geom, _settings) + ) + .Be( + new MultiPoint( + new[] + { + new Point(10, 40), + new Point(40, 30), + new Point(20, 20), + new Point(30, 10) + } + ) + ) + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTILINESTRING((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))")] + [InlineData("MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))")] public void MultiLineString_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .BeOfType() + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)), ((30 20, 20 15, 20 25, 30 20)))")] + [InlineData("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)), ((30 20, 20 15, 20 25, 30 20)))")] public void MultiPolygon_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .BeOfType() + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } [Theory] - [InlineData("GEOMETRYCOLLECTION(POINT(40 10), LINESTRING(10 10, 20 20, 10 40), POLYGON((40 40, 20 45, 45 30, 40 40)))")] + [InlineData("GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON ((40 40, 20 45, 45 30, 40 40)))")] public void GeometryCollection_Tests(string geom) { - new ObjectAssertions( - DeserializeObject(geom, _settings) - ) - .BeOfType(); + var value = new ObjectAssertions(DeserializeObject(geom, _settings)) + .BeOfType() + .And.Subject; + SerializeObject(value, _settings).Should().Be(geom); } public class ValueOf