public void TestIssue83() { var geoJson = @"{ ""type"": ""Feature"", ""geometry"": { ""type"": ""Point"", ""coordinates"": [10.0, 60.0] }, ""id"": 1, ""properties"": { ""Name"": ""test"" } }"; var s = new GeoJsonSerializer(); Feature f = null; Assert.DoesNotThrow(() => f = s.Deserialize <Feature>(new JsonTextReader(new StringReader(geoJson))) ); Assert.IsNotNull(f, "f != null"); Assert.IsTrue(FeatureExtensions.HasID(f), "f.HasID()"); Assert.AreEqual(1, FeatureExtensions.ID(f), "f.ID != 1"); var sb = new StringBuilder(); var tw = new JsonTextWriter(new StringWriter(sb)); s.Serialize(tw, f); var geoJsonRes = sb.ToString(); CompareJson(geoJson, geoJsonRes); }
public void TestReaderFailsToParseProperties() { const string geojson = @"{ ""type"": ""Feature"", ""geometry"": { ""type"": ""Point"", ""coordinates"": [ 12.5851472, 55.68323837 ] }, ""crs"": { ""type"": ""name"", ""properties"": { ""name"": ""EPSG:4326"" } }, ""properties"": { ""id"": ""0a3f507a-b2e6-32b8-e044-0003ba298018"", ""status"": 1, ""vejkode"": ""4112"", ""vejnavn"": ""Landgreven"", ""adresseringsvejnavn"": ""Landgreven"", ""husnr"": ""10"", ""supplerendebynavn"": null, ""postnr"": ""1301"", ""postnrnavn"": ""København K"", ""kommunekode"": ""0101"" } }"; Feature f = null; Assert.That(() => f = new GeoJsonReader().Read <Feature>(geojson), Throws.Nothing); Assert.That(f.Attributes, Is.Not.Null); Assert.That(f.Attributes.Count, Is.EqualTo(10)); Assert.That(FeatureExtensions.HasID(f), Is.True); Assert.That(FeatureExtensions.ID(f), Is.EqualTo("0a3f507a-b2e6-32b8-e044-0003ba298018")); }
public void TestIssue88WithoutAdditionalProperties() { string expectedJson = @" { ""id"" : ""00000000-0000-0000-0000-000000000000"", ""type"" : ""Feature"", ""geometry"" : null, ""properties"" : { ""yesNo 1"" : false, ""date 1"" : ""2016-02-16T00:00:00"" } } "; GeoJsonSerializer serializer = new GeoJsonSerializer(); Feature feat = null; Assert.DoesNotThrow(() => { using (JsonReader reader = new JsonTextReader(new StringReader(expectedJson))) feat = serializer.Deserialize <Feature>(reader); }); Assert.IsNotNull(feat); Assert.IsTrue(FeatureExtensions.HasID(feat)); Assert.AreEqual("00000000-0000-0000-0000-000000000000", FeatureExtensions.ID(feat)); IGeometry geometry = feat.Geometry; Assert.IsNull(geometry); IAttributesTable attributes = feat.Attributes; Assert.IsNotNull(attributes); Assert.AreEqual(3, attributes.Count); Assert.AreEqual(FeatureExtensions.ID(feat), attributes["id"]); Assert.AreEqual(false, attributes["yesNo 1"]); Assert.AreEqual(DateTime.Parse("2016-02-16T00:00:00", CultureInfo.InvariantCulture), attributes["date 1"]); }