|
1 | | -using System.Linq; |
2 | | -using GeoJSON.Net.Geometry; |
3 | | -using Newtonsoft.Json; |
4 | | -using NUnit.Framework; |
5 | | - |
6 | | -namespace GeoJSON.Net.Tests.Feature |
7 | | -{ |
8 | | - [TestFixture] |
9 | | - internal class GenericFeatureTests : TestBase |
10 | | - { |
11 | | - [Test] |
12 | | - public void Can_Deserialize_Point_Feature() |
13 | | - { |
14 | | - var json = GetExpectedJson(); |
15 | | - |
16 | | - var feature = JsonConvert.DeserializeObject<Net.Feature.Feature<Point>>(json); |
17 | | - |
18 | | - Assert.IsNotNull(feature); |
19 | | - Assert.IsNotNull(feature.Properties); |
20 | | - Assert.IsTrue(feature.Properties.Any()); |
21 | | - |
22 | | - Assert.IsTrue(feature.Properties.ContainsKey("name")); |
23 | | - Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); |
24 | | - |
25 | | - Assert.AreEqual("test-id", feature.Id); |
26 | | - |
27 | | - Assert.AreEqual(GeoJSONObjectType.Point, feature.Geometry.Type); |
28 | | - Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude); |
29 | | - Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude); |
30 | | - Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude); |
31 | | - } |
32 | | - |
33 | | - [Test] |
34 | | - public void Can_Deserialize_LineString_Feature() |
35 | | - { |
36 | | - var json = GetExpectedJson(); |
37 | | - |
38 | | - var feature = JsonConvert.DeserializeObject<Net.Feature.Feature<LineString>>(json); |
39 | | - |
40 | | - Assert.IsNotNull(feature); |
41 | | - Assert.IsNotNull(feature.Properties); |
42 | | - Assert.IsTrue(feature.Properties.Any()); |
43 | | - |
44 | | - Assert.IsTrue(feature.Properties.ContainsKey("name")); |
45 | | - Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); |
46 | | - |
47 | | - Assert.AreEqual("test-id", feature.Id); |
48 | | - |
49 | | - Assert.AreEqual(GeoJSONObjectType.LineString, feature.Geometry.Type); |
50 | | - |
51 | | - Assert.AreEqual(4, feature.Geometry.Coordinates.Count); |
52 | | - |
53 | | - //Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude); |
54 | | - //Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude); |
55 | | - //Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude); |
56 | | - } |
57 | | - } |
58 | | -} |
| 1 | +using System.Linq; |
| 2 | +using GeoJSON.Net.Feature; |
| 3 | +using GeoJSON.Net.Geometry; |
| 4 | +using Newtonsoft.Json; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace GeoJSON.Net.Tests.Feature |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + internal class GenericFeatureTests : TestBase |
| 11 | + { |
| 12 | + [Test] |
| 13 | + public void Can_Deserialize_Point_Feature() |
| 14 | + { |
| 15 | + var json = GetExpectedJson(); |
| 16 | + |
| 17 | + var feature = JsonConvert.DeserializeObject<Feature<Point>>(json); |
| 18 | + |
| 19 | + Assert.IsNotNull(feature); |
| 20 | + Assert.IsNotNull(feature.Properties); |
| 21 | + Assert.IsTrue(feature.Properties.Any()); |
| 22 | + |
| 23 | + Assert.IsTrue(feature.Properties.ContainsKey("name")); |
| 24 | + Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); |
| 25 | + |
| 26 | + Assert.AreEqual("test-id", feature.Id); |
| 27 | + |
| 28 | + Assert.AreEqual(GeoJSONObjectType.Point, feature.Geometry.Type); |
| 29 | + Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude); |
| 30 | + Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude); |
| 31 | + Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude); |
| 32 | + } |
| 33 | + |
| 34 | + [Test] |
| 35 | + public void Can_Deserialize_LineString_Feature() |
| 36 | + { |
| 37 | + var json = GetExpectedJson(); |
| 38 | + |
| 39 | + var feature = JsonConvert.DeserializeObject<Feature<LineString>>(json); |
| 40 | + |
| 41 | + Assert.IsNotNull(feature); |
| 42 | + Assert.IsNotNull(feature.Properties); |
| 43 | + Assert.IsTrue(feature.Properties.Any()); |
| 44 | + |
| 45 | + Assert.IsTrue(feature.Properties.ContainsKey("name")); |
| 46 | + Assert.AreEqual("Dinagat Islands", feature.Properties["name"]); |
| 47 | + |
| 48 | + Assert.AreEqual("test-id", feature.Id); |
| 49 | + |
| 50 | + Assert.AreEqual(GeoJSONObjectType.LineString, feature.Geometry.Type); |
| 51 | + |
| 52 | + Assert.AreEqual(4, feature.Geometry.Coordinates.Count); |
| 53 | + |
| 54 | + //Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude); |
| 55 | + //Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude); |
| 56 | + //Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude); |
| 57 | + } |
| 58 | + |
| 59 | + private class TypedFeatureProps |
| 60 | + { |
| 61 | + [JsonProperty("name")] |
| 62 | + public string Name { get; set; } |
| 63 | + [JsonProperty("value")] |
| 64 | + public double Value { get; set; } |
| 65 | + } |
| 66 | + |
| 67 | + [Test] |
| 68 | + public void Can_Deserialize_Typed_Point_Feature() |
| 69 | + { |
| 70 | + var json = GetExpectedJson(); |
| 71 | + var feature = JsonConvert.DeserializeObject<Feature<Point, TypedFeatureProps>>(json); |
| 72 | + |
| 73 | + Assert.IsNotNull(feature); |
| 74 | + |
| 75 | + Assert.IsNotNull(feature.Properties); |
| 76 | + Assert.AreEqual(feature.Properties.Name, "Dinagat Islands"); |
| 77 | + Assert.AreEqual(feature.Properties.Value, 4.2); |
| 78 | + |
| 79 | + Assert.AreEqual(feature.Id, "test-id"); |
| 80 | + |
| 81 | + Assert.AreEqual(feature.Geometry.Type, GeoJSONObjectType.Point); |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + [Test] |
| 86 | + public void Can_Serialize_Typed_Point_Feature() |
| 87 | + { |
| 88 | + var geometry = new Point(new Position(1, 2)); |
| 89 | + var props = new TypedFeatureProps |
| 90 | + { |
| 91 | + Name = "no name here", |
| 92 | + Value = 1.337 |
| 93 | + }; |
| 94 | + var feature = new Feature<Point, TypedFeatureProps>(geometry, props, "no id there"); |
| 95 | + |
| 96 | + var expectedJson = GetExpectedJson(); |
| 97 | + var actualJson = JsonConvert.SerializeObject(feature); |
| 98 | + |
| 99 | + JsonAssert.AreEqual(expectedJson, actualJson); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments