-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathGenericFeatureTests.cs
More file actions
129 lines (101 loc) · 4.21 KB
/
GenericFeatureTests.cs
File metadata and controls
129 lines (101 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using GeoJSON.Text.Feature;
using GeoJSON.Text.Geometry;
using NUnit.Framework;
namespace GeoJSON.Text.Tests.Feature
{
[TestFixture]
internal class GenericFeatureTests : TestBase
{
[Test]
public void Can_Deserialize_Point_Feature()
{
var json = GetExpectedJson();
var feature = JsonSerializer.Deserialize<Feature<Point>>(json);
Assert.IsNotNull(feature);
Assert.IsNotNull(feature.Properties);
Assert.IsTrue(feature.Properties.Any());
Assert.IsTrue(feature.Properties.ContainsKey("name"));
string name = feature.Properties["name"].ToString();
Assert.AreEqual("Dinagat Islands", name);
Assert.AreEqual((FeatureId)"test-id", feature.Id);
Assert.AreEqual(GeoJSONObjectType.Point, feature.Geometry.Type);
Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude);
Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude);
Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude);
}
[Test]
public void Can_Deserialize_LineString_Feature()
{
var json = GetExpectedJson();
var feature = JsonSerializer.Deserialize<Feature<LineString>>(json);
Assert.IsNotNull(feature);
Assert.IsNotNull(feature.Properties);
Assert.IsTrue(feature.Properties.Any());
Assert.IsTrue(feature.Properties.ContainsKey("name"));
Assert.AreEqual("Dinagat Islands", feature.Properties["name"].ToString());
Assert.AreEqual((FeatureId)"test-id", feature.Id);
Assert.AreEqual(GeoJSONObjectType.LineString, feature.Geometry.Type);
Assert.AreEqual(4, feature.Geometry.Coordinates.Count);
//Assert.AreEqual(125.6, feature.Geometry.Coordinates.Longitude);
//Assert.AreEqual(10.1, feature.Geometry.Coordinates.Latitude);
//Assert.AreEqual(456, feature.Geometry.Coordinates.Altitude);
}
[Test]
public void Feature_Generic_Equals_Null_Issure94()
{
bool equal1 = true;
bool equal2 = true;
var point = new Point(new Position(34, 123));
var properties = new Dictionary<string, string>
{
{"test1", "test1val"},
{"test2", "test2val"}
};
var feature = new Feature<Point, Dictionary<string, string>>(point, properties, "testid");
Assert.DoesNotThrow(() =>
{
equal1 = feature == null;
equal2 = feature.Equals(null);
});
Assert.IsFalse(equal1);
Assert.IsFalse(equal2);
}
private class TypedFeatureProps
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("value")]
public double Value { get; set; }
}
[Test]
public void Can_Deserialize_Typed_Point_Feature()
{
var json = GetExpectedJson();
var feature = JsonSerializer.Deserialize<Feature<Point, TypedFeatureProps>>(json);
Assert.IsNotNull(feature);
Assert.IsNotNull(feature.Properties);
Assert.AreEqual(feature.Properties.Name, "Dinagat Islands");
Assert.AreEqual(feature.Properties.Value, 4.2);
Assert.AreEqual(feature.Id, (FeatureId)"test-id");
Assert.AreEqual(feature.Geometry.Type, GeoJSONObjectType.Point);
}
[Test]
public void Can_Serialize_Typed_Point_Feature()
{
var geometry = new Point(new Position(1, 2));
var props = new TypedFeatureProps
{
Name = "no name here",
Value = 1.337
};
var feature = new Feature<Point, TypedFeatureProps>(geometry, props, "no id there");
var expectedJson = GetExpectedJson();
var actualJson = JsonSerializer.Serialize(feature);
JsonAssert.AreEqual(expectedJson, actualJson);
}
}
}