Skip to content

Commit ee56135

Browse files
Initial code commit, build fails
1 parent 4a5e80c commit ee56135

88 files changed

Lines changed: 7076 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
open_collective: geojson-net

.github/workflows/ci-build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build and Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
env:
14+
VSTEST_CONNECTION_TIMEOUT: 900
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Setup .NET Core
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: '6.0.x'
22+
- name: Install dependencies
23+
run: dotnet restore
24+
- name: Build
25+
run: dotnet build --configuration Release --no-restore
26+
- name: Test
27+
run: dotnet test --no-restore --verbosity normal

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Jörg Battermann & Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<PropertyGroup>
4+
<AssemblyOriginatorKeyFile>$(SolutionDir)key.snk</AssemblyOriginatorKeyFile>
5+
<SignAssembly>true</SignAssembly>
6+
</PropertyGroup>
7+
</Project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using GeoJSON.Net.CoordinateReferenceSystem;
2+
using GeoJSON.Net.Feature;
3+
using GeoJSON.Net.Geometry;
4+
using Newtonsoft.Json;
5+
using NUnit.Framework;
6+
7+
namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
8+
{
9+
[TestFixture]
10+
public class DefaultCrsTests : TestBase
11+
{
12+
[Test]
13+
public void Can_Serialize_Does_Not_Output_Crs_Property()
14+
{
15+
var collection = new FeatureCollection();
16+
17+
var json = JsonConvert.SerializeObject(collection);
18+
19+
Assert.IsTrue(!json.Contains("\"crs\""));
20+
}
21+
22+
[Test]
23+
public void Can_Deserialize_When_Json_Does_Not_Contain_Crs_Property()
24+
{
25+
var json = "{\"coordinates\":[90.65464646,53.2455662,200.4567],\"type\":\"Point\"}";
26+
27+
var point = JsonConvert.DeserializeObject<Point>(json);
28+
29+
Assert.IsNull(point.CRS);
30+
}
31+
32+
[Test]
33+
public void Can_Deserialize_CRS_issue_89()
34+
{
35+
var json = "{\"coordinates\": [ 90.65464646, 53.2455662, 200.4567 ], \"type\": \"Point\", \"crs\": { \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" }}}";
36+
37+
var point = JsonConvert.DeserializeObject<Point>(json);
38+
39+
Assert.IsNotNull(point.CRS);
40+
Assert.AreEqual(CRSType.Name, point.CRS.Type);
41+
}
42+
43+
[Test]
44+
public void Can_Serialize_CRS_issue_89()
45+
{
46+
var expected =
47+
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"TEST NAME\"},\"type\":\"name\"}}";
48+
var point = new Point(new Position(12.34, 34.56)) { CRS = new NamedCRS("TEST NAME") };
49+
50+
var json = JsonConvert.SerializeObject(point);
51+
52+
Assert.IsNotNull(json);
53+
Assert.AreEqual(expected, json);
54+
}
55+
56+
[Test]
57+
public void Can_Serialize_DefaultCRS_issue_89()
58+
{
59+
var expected =
60+
"{\"type\":\"Point\",\"coordinates\":[34.56,12.34],\"crs\":{\"properties\":{\"name\":\"urn:ogc:def:crs:OGC::CRS84\"},\"type\":\"name\"}}";
61+
var point = new Point(new Position(12.34, 34.56)) { CRS = new NamedCRS("urn:ogc:def:crs:OGC::CRS84") };
62+
63+
var json = JsonConvert.SerializeObject(point);
64+
65+
Assert.IsNotNull(json);
66+
Assert.AreEqual(expected, json);
67+
}
68+
}
69+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using GeoJSON.Net.CoordinateReferenceSystem;
3+
using GeoJSON.Net.Geometry;
4+
using Newtonsoft.Json;
5+
using NUnit.Framework;
6+
7+
namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
8+
{
9+
[TestFixture]
10+
public class LinkedCRSTests : TestBase
11+
{
12+
private const string Href = "http://localhost";
13+
14+
[Test]
15+
public void Has_Correct_Type()
16+
{
17+
var crs = new LinkedCRS(Href);
18+
Assert.AreEqual(CRSType.Link, crs.Type);
19+
}
20+
21+
[Test]
22+
public void Has_Href_Property_With_Href()
23+
{
24+
var crs = new LinkedCRS(Href);
25+
26+
Assert.IsTrue(crs.Properties.ContainsKey("href"));
27+
Assert.AreEqual(Href, crs.Properties["href"]);
28+
}
29+
30+
[Test]
31+
public void Has_Type_Property()
32+
{
33+
const string type = "ogcwkt";
34+
var crs = new LinkedCRS(Href, type);
35+
36+
Assert.IsTrue(crs.Properties.ContainsKey("type"));
37+
Assert.AreEqual(type, crs.Properties["type"]);
38+
}
39+
40+
[Test]
41+
public void Can_Serialize()
42+
{
43+
var collection = new Point(new Position(1, 2, 3)) { CRS = new LinkedCRS(Href) };
44+
var actualJson = JsonConvert.SerializeObject(collection);
45+
46+
JsonAssert.Contains("{\"properties\":{\"href\":\"http://localhost\"},\"type\":\"link\"}", actualJson);
47+
}
48+
49+
[Test]
50+
public void Can_Deserialize_CRS_issue_101()
51+
{
52+
const string pointJson = "{\"type\":\"Point\",\"coordinates\":[2.0,1.0,3.0],\"crs\":{\"properties\":{\"href\":\"http://localhost\"},\"type\":\"link\"}}";
53+
var pointWithCRS = JsonConvert.DeserializeObject<Point>(pointJson);
54+
var linkCRS = pointWithCRS.CRS as LinkedCRS;
55+
56+
Assert.IsNotNull(linkCRS);
57+
Assert.AreEqual(CRSType.Link, linkCRS.Type);
58+
Assert.AreEqual(Href, linkCRS.Properties["href"]);
59+
}
60+
61+
[Test]
62+
public void Ctor_Throws_ArgumentNullExpection_When_Href_String_Is_Null()
63+
{
64+
Assert.Throws<ArgumentNullException>(() => { var crs = new LinkedCRS((string)null); });
65+
}
66+
67+
[Test]
68+
public void Ctor_Throws_ArgumentNullExpection_When_Href_Uri_Is_Null()
69+
{
70+
Assert.Throws<ArgumentNullException>(() => { var crs = new LinkedCRS((Uri)null); });
71+
}
72+
73+
[Test]
74+
public void Ctor_Throws_ArgumentExpection_When_Href_Is_Not_Dereferencable_Uri()
75+
{
76+
#if NETCOREAPP1_1
77+
System.Globalization.CultureInfo.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
78+
#else
79+
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
80+
#endif
81+
82+
var argumentExpection = Assert.Throws<ArgumentException>(() => { var crs = new LinkedCRS("http://not-a-valid-<>-url"); });
83+
Assert.AreEqual($"must be a dereferenceable URI{Environment.NewLine}Parameter name: href", argumentExpection.Message);
84+
}
85+
86+
[Test]
87+
public void Ctor_Does_Not_Throw_When_Href_Is_Dereferencable_Uri()
88+
{
89+
Assert.DoesNotThrow(() => { var crs = new LinkedCRS("data.crs"); });
90+
}
91+
92+
[Test]
93+
public void Ctor_Throws_ArgumentNullExpection_When_Name_Is_Empty()
94+
{
95+
Assert.Throws<ArgumentException>(() => { var crs = new LinkedCRS(string.Empty); });
96+
}
97+
98+
[Test]
99+
public void Equals_GetHashCode_Contract()
100+
{
101+
var left = new LinkedCRS(Href);
102+
var right = new LinkedCRS(Href);
103+
104+
Assert.AreEqual(left, right);
105+
106+
Assert.IsTrue(left == right);
107+
Assert.IsTrue(right == left);
108+
109+
Assert.IsTrue(left.Equals(right));
110+
Assert.IsTrue(right.Equals(left));
111+
112+
Assert.IsTrue(left.Equals(left));
113+
Assert.IsTrue(right.Equals(right));
114+
115+
Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
116+
117+
right = new LinkedCRS(Href + "?query=null");
118+
119+
Assert.AreNotEqual(left, right);
120+
121+
Assert.IsFalse(left == right);
122+
Assert.IsFalse(right == left);
123+
124+
Assert.IsFalse(left.Equals(right));
125+
Assert.IsFalse(right.Equals(left));
126+
127+
Assert.AreNotEqual(left.GetHashCode(), right.GetHashCode());
128+
}
129+
}
130+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using GeoJSON.Net.CoordinateReferenceSystem;
3+
using GeoJSON.Net.Feature;
4+
using Newtonsoft.Json;
5+
using NUnit.Framework;
6+
7+
namespace GeoJSON.Net.Tests.CoordinateReferenceSystem
8+
{
9+
[TestFixture]
10+
public class NamedCRSTests : TestBase
11+
{
12+
[Test]
13+
public void Has_Correct_Type()
14+
{
15+
var name = "EPSG:31370";
16+
var crs = new NamedCRS(name);
17+
18+
Assert.AreEqual(CRSType.Name, crs.Type);
19+
}
20+
21+
[Test]
22+
public void Has_Name_Property_With_Name()
23+
{
24+
var name = "EPSG:31370";
25+
var crs = new NamedCRS(name);
26+
27+
Assert.IsTrue(crs.Properties.ContainsKey("name"));
28+
Assert.AreEqual(name, crs.Properties["name"]);
29+
}
30+
31+
[Test]
32+
public void Can_Serialize()
33+
{
34+
var collection = new FeatureCollection() { CRS = new NamedCRS("EPSG:31370") };
35+
var actualJson = JsonConvert.SerializeObject(collection);
36+
37+
JsonAssert.Contains("{\"properties\":{\"name\":\"EPSG:31370\"},\"type\":\"name\"}", actualJson);
38+
}
39+
40+
[Test]
41+
public void Ctor_Throws_ArgumentNullExpection_When_Name_Is_Null()
42+
{
43+
Assert.Throws<ArgumentNullException>(() => { var collection = new FeatureCollection() { CRS = new NamedCRS(null) }; });
44+
}
45+
46+
[Test]
47+
public void Ctor_Throws_ArgumentNullExpection_When_Name_Is_Empty()
48+
{
49+
Assert.Throws<ArgumentException>(() => { var collection = new FeatureCollection() { CRS = new NamedCRS(string.Empty) }; });
50+
}
51+
52+
[Test]
53+
public void Equals_GetHashCode_Contract()
54+
{
55+
var name = "EPSG:31370";
56+
57+
var left = new NamedCRS(name);
58+
var right = new NamedCRS(name);
59+
60+
Assert.AreEqual(left, right);
61+
62+
Assert.IsTrue(left == right);
63+
Assert.IsTrue(right == left);
64+
65+
Assert.IsTrue(left.Equals(right));
66+
Assert.IsTrue(right.Equals(left));
67+
68+
Assert.IsTrue(left.Equals(left));
69+
Assert.IsTrue(right.Equals(right));
70+
71+
Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
72+
73+
name = "EPSG:25832";
74+
right = new NamedCRS(name);
75+
76+
Assert.AreNotEqual(left, right);
77+
78+
Assert.IsFalse(left == right);
79+
Assert.IsFalse(right == left);
80+
81+
Assert.IsFalse(left.Equals(right));
82+
Assert.IsFalse(right.Equals(left));
83+
84+
Assert.AreNotEqual(left.GetHashCode(), right.GetHashCode());
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)