|
| 1 | +namespace AzureMapsControl.Components.Tests.Atlas |
| 2 | +{ |
| 3 | + using System.Text.Json; |
| 4 | + |
| 5 | + using AzureMapsControl.Components.Atlas; |
| 6 | + using AzureMapsControl.Components.Tests.Json; |
| 7 | + |
| 8 | + using Xunit; |
| 9 | + |
| 10 | + public class GeometryJsonConverterTests : JsonConverterTests<Geometry> |
| 11 | + { |
| 12 | + public GeometryJsonConverterTests() : base(new GeometryJsonConverter()) { } |
| 13 | + |
| 14 | + [Fact] |
| 15 | + public void Should_ReadPoint() |
| 16 | + { |
| 17 | + var point = new Point(new Position(0, 1)); |
| 18 | + var json = JsonSerializer.Serialize(point); |
| 19 | + var result = Read(json); |
| 20 | + Assert.IsType<Point>(result); |
| 21 | + Assert.Equal(json, JsonSerializer.Serialize(result as Point)); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void Should_ReadLineString() |
| 26 | + { |
| 27 | + var lineString = new LineString(new[] { new Position(0, 1), new Position(2, 3) }); |
| 28 | + var json = JsonSerializer.Serialize(lineString); |
| 29 | + var result = Read(json); |
| 30 | + Assert.IsType<LineString>(result); |
| 31 | + Assert.Equal(json, JsonSerializer.Serialize(result as LineString)); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void Should_ReadMultiLineString() |
| 36 | + { |
| 37 | + var multiLineString = new MultiLineString(new[] { |
| 38 | + new [] { |
| 39 | + new Position(0, 1), |
| 40 | + new Position(2,3) |
| 41 | + }, |
| 42 | + new [] { |
| 43 | + new Position(4,5), |
| 44 | + new Position(6,7) |
| 45 | + } |
| 46 | + }); |
| 47 | + var json = JsonSerializer.Serialize(multiLineString); |
| 48 | + var result = Read(json); |
| 49 | + Assert.IsType<MultiLineString>(result); |
| 50 | + Assert.Equal(json, JsonSerializer.Serialize(result as MultiLineString)); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void Should_ReadMultiPoint() |
| 55 | + { |
| 56 | + var multiPoint = new MultiPoint(new[] { new Position(0, 1), new Position(2, 3) }); |
| 57 | + var json = JsonSerializer.Serialize(multiPoint); |
| 58 | + var result = Read(json); |
| 59 | + Assert.IsType<MultiPoint>(result); |
| 60 | + Assert.Equal(json, JsonSerializer.Serialize(result as MultiPoint)); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void Should_ReadMultiPolygon() |
| 65 | + { |
| 66 | + var multiPolygon = new MultiPolygon(new[] { |
| 67 | + new [] { |
| 68 | + new [] { |
| 69 | + new Position(0, 1), |
| 70 | + new Position(2, 3) |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + var json = JsonSerializer.Serialize(multiPolygon); |
| 75 | + var result = Read(json); |
| 76 | + Assert.IsType<MultiPolygon>(result); |
| 77 | + Assert.Equal(json, JsonSerializer.Serialize(result as MultiPolygon)); |
| 78 | + } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + public void Should_ReadPolygon() |
| 82 | + { |
| 83 | + var polygon = new Polygon(new[] { |
| 84 | + new [] { |
| 85 | + new Position(0, 1), |
| 86 | + new Position(2, 3) |
| 87 | + } |
| 88 | + }); |
| 89 | + var json = JsonSerializer.Serialize(polygon); |
| 90 | + var result = Read(json); |
| 91 | + Assert.IsType<Polygon>(result); |
| 92 | + Assert.Equal(json, JsonSerializer.Serialize(result as Polygon)); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + public class GeometryPointJsonConverterTests : JsonConverterTests<Point> |
| 97 | + { |
| 98 | + public GeometryPointJsonConverterTests() : base(new GeometryJsonConverter<Point>()) { } |
| 99 | + |
| 100 | + [Fact] |
| 101 | + public void Should_Read() |
| 102 | + { |
| 103 | + var geometry = new Point(new Position(0, 1)); |
| 104 | + var json = JsonSerializer.Serialize(geometry); |
| 105 | + var result = Read(json); |
| 106 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 107 | + } |
| 108 | + |
| 109 | + [Fact] |
| 110 | + public void Should_Write() |
| 111 | + { |
| 112 | + var geometry = new Point(new Position(0, 1)); |
| 113 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + public class GeometryLineStringJsonConverterTests : JsonConverterTests<LineString> |
| 118 | + { |
| 119 | + public GeometryLineStringJsonConverterTests() : base(new GeometryJsonConverter<LineString>()) { } |
| 120 | + |
| 121 | + [Fact] |
| 122 | + public void Should_Read() |
| 123 | + { |
| 124 | + var geometry = new LineString(new[] { new Position(0, 1), new Position(2, 3) }); |
| 125 | + var json = JsonSerializer.Serialize(geometry); |
| 126 | + var result = Read(json); |
| 127 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 128 | + } |
| 129 | + |
| 130 | + [Fact] |
| 131 | + public void Should_Write() |
| 132 | + { |
| 133 | + var geometry = new LineString(new[] { new Position(0, 1), new Position(2, 3) }); |
| 134 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + public class GeometryMultiLineStringJsonConverterTests : JsonConverterTests<MultiLineString> |
| 139 | + { |
| 140 | + public GeometryMultiLineStringJsonConverterTests() : base(new GeometryJsonConverter<MultiLineString>()) { } |
| 141 | + |
| 142 | + [Fact] |
| 143 | + public void Should_Read() |
| 144 | + { |
| 145 | + var geometry = new MultiLineString(new[] { |
| 146 | + new [] { |
| 147 | + new Position(0, 1), |
| 148 | + new Position(2,3) |
| 149 | + }, |
| 150 | + new [] { |
| 151 | + new Position(4,5), |
| 152 | + new Position(6,7) |
| 153 | + } |
| 154 | + }); |
| 155 | + var json = JsonSerializer.Serialize(geometry); |
| 156 | + var result = Read(json); |
| 157 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 158 | + } |
| 159 | + |
| 160 | + [Fact] |
| 161 | + public void Should_Write() |
| 162 | + { |
| 163 | + var geometry = new MultiLineString(new[] { |
| 164 | + new [] { |
| 165 | + new Position(0, 1), |
| 166 | + new Position(2,3) |
| 167 | + }, |
| 168 | + new [] { |
| 169 | + new Position(4,5), |
| 170 | + new Position(6,7) |
| 171 | + } |
| 172 | + }); |
| 173 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + public class GeometryMultiPointJsonConverterTests : JsonConverterTests<MultiPoint> |
| 178 | + { |
| 179 | + public GeometryMultiPointJsonConverterTests() : base(new GeometryJsonConverter<MultiPoint>()) { } |
| 180 | + |
| 181 | + [Fact] |
| 182 | + public void Should_Read() |
| 183 | + { |
| 184 | + var geometry = new MultiPoint(new[] { new Position(0, 1), new Position(2, 3) }); |
| 185 | + var json = JsonSerializer.Serialize(geometry); |
| 186 | + var result = Read(json); |
| 187 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 188 | + } |
| 189 | + |
| 190 | + [Fact] |
| 191 | + public void Should_Write() |
| 192 | + { |
| 193 | + var geometry = new MultiPoint(new[] { new Position(0, 1), new Position(2, 3) }); |
| 194 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + public class GeometryMultiPolygonJsonConverterTests : JsonConverterTests<MultiPolygon> |
| 199 | + { |
| 200 | + public GeometryMultiPolygonJsonConverterTests() : base(new GeometryJsonConverter<MultiPolygon>()) { } |
| 201 | + |
| 202 | + [Fact] |
| 203 | + public void Should_Read() |
| 204 | + { |
| 205 | + var geometry = new MultiPolygon(new[] { |
| 206 | + new [] { |
| 207 | + new [] { |
| 208 | + new Position(0, 1), |
| 209 | + new Position(2, 3) |
| 210 | + } |
| 211 | + } |
| 212 | + }); |
| 213 | + var json = JsonSerializer.Serialize(geometry); |
| 214 | + var result = Read(json); |
| 215 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 216 | + } |
| 217 | + |
| 218 | + [Fact] |
| 219 | + public void Should_Write() |
| 220 | + { |
| 221 | + var geometry = new MultiPolygon(new[] { |
| 222 | + new [] { |
| 223 | + new [] { |
| 224 | + new Position(0, 1), |
| 225 | + new Position(2, 3) |
| 226 | + } |
| 227 | + } |
| 228 | + }); |
| 229 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + public class GeometryPolygonJsonConverterTests : JsonConverterTests<Polygon> |
| 234 | + { |
| 235 | + public GeometryPolygonJsonConverterTests() : base(new GeometryJsonConverter<Polygon>()) { } |
| 236 | + |
| 237 | + [Fact] |
| 238 | + public void Should_Read() |
| 239 | + { |
| 240 | + var geometry = new Polygon(new[] { |
| 241 | + new [] { |
| 242 | + new Position(0, 1), |
| 243 | + new Position(2, 3) |
| 244 | + } |
| 245 | + }); |
| 246 | + var json = JsonSerializer.Serialize(geometry); |
| 247 | + var result = Read(json); |
| 248 | + Assert.Equal(json, JsonSerializer.Serialize(result)); |
| 249 | + } |
| 250 | + |
| 251 | + [Fact] |
| 252 | + public void Should_Write() |
| 253 | + { |
| 254 | + var geometry = new Polygon(new[] { |
| 255 | + new [] { |
| 256 | + new Position(0, 1), |
| 257 | + new Position(2, 3) |
| 258 | + } |
| 259 | + }); |
| 260 | + TestAndAssertWrite(geometry, JsonSerializer.Serialize(geometry)); |
| 261 | + } |
| 262 | + } |
| 263 | +} |
0 commit comments