1
+ using System . IO ;
2
+ using System . Text ;
3
+ using NetTopologySuite . Features ;
4
+ using Newtonsoft . Json ;
5
+ using Newtonsoft . Json . Linq ;
6
+ using NUnit . Framework ;
7
+
8
+ namespace NetTopologySuite . IO . Tests . GeoJSON
9
+ {
10
+ [ Category ( "GitHub" ) ]
11
+ [ TestFixture ]
12
+ public class GitHubIssues
13
+ {
14
+ [ Test ( Description = "Testcase for Issue 83" ) ]
15
+ public void TestIssue83 ( )
16
+ {
17
+ var geoJson = "{ \" type\" : \" Feature\" , " +
18
+ "\" geometry\" : { \" type\" : \" Point\" , \" coordinates\" : [10.0, 60.0] }, " +
19
+ "\" id\" : 1, " +
20
+ "\" properties\" : { \" Name\" : \" test\" } }" ;
21
+
22
+ var s = new GeoJsonSerializer ( ) ;
23
+ Feature f = null ;
24
+ Assert . DoesNotThrow ( ( ) =>
25
+ f = s . Deserialize < Feature > ( new JsonTextReader ( new StringReader ( geoJson ) ) )
26
+ ) ;
27
+
28
+ Assert . IsNotNull ( f , "f != null" ) ;
29
+ Assert . IsTrue ( f . HasID ( ) , "f.HasID()" ) ;
30
+ Assert . AreEqual ( 1 , f . ID ( ) , "f.ID != 1" ) ;
31
+
32
+ var sb = new StringBuilder ( ) ;
33
+ var tw = new JsonTextWriter ( new StringWriter ( sb ) ) ;
34
+ s . Serialize ( tw , f ) ;
35
+ var geoJsonRes = sb . ToString ( ) ;
36
+
37
+ CompareJson ( geoJson , geoJsonRes ) ;
38
+ }
39
+
40
+ public void CompareJson ( string expectedJson , string json )
41
+ {
42
+ var e = JToken . Parse ( expectedJson ) ;
43
+ var j = JToken . Parse ( json ) ;
44
+
45
+ if ( ! JToken . DeepEquals ( e , j ) )
46
+ {
47
+ var res = string . Format ( "The json's do not match:\n 1: {0}\n 2:{1}" ,
48
+ expectedJson , json ) ;
49
+ Assert . IsTrue ( false , res ) ;
50
+ }
51
+
52
+ }
53
+ }
54
+ }
0 commit comments