Skip to content

Commit 53e12d6

Browse files
Fixing issue 115, Feature.Equals thros excpeiton when geometry is null
1 parent 446154f commit 53e12d6

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
[![NuGet Version](http://img.shields.io/nuget/v/GeoJSON.NET.svg?style=flat)](https://www.nuget.org/packages/GeoJSON.NET/)
22
[![Build status](https://ci.appveyor.com/api/projects/status/n4q1opb6dod0hwac?svg=true)](https://ci.appveyor.com/project/matt-lethargic/geojson-net)
33

4-
## *** Notice ***
5-
A quick note... sorry to everyone who has been following or using this project over t
6-
last year, I started a new role a year ago and it took some time away from this project, when that calmed down I actually got locked out of my GitHub account and as it had two factor authentication on it was not an easy task getting back in. This is all sorted now and I'm going to be starting back on this project now.
7-
MattLethargic, Aug '18
8-
94
# GeoJSON.NET
105
GeoJSON.Net is a .NET library for the [RFC 7946 The GeoJSON Format](https://tools.ietf.org/html/rfc7946) and it uses and provides [Newtonsoft Json.NET](http://json.codeplex.com) converters for serialization and deserialization of GeoJSON data.
116

7+
## Version 2
8+
I'm starting to put together a plan for version 2 of GeoJSON.Net. I'm open to any suggestions or ideas, if you have any thoughts please open an issue and make it clear that it's an idea for version to and I'll tag it up as such.
129

1310
## Installation & Usage
1411

@@ -35,10 +32,6 @@ Point point = JsonConvert.DeserializeObject<Point>(json);
3532
See the [Tests](https://github.com/GeoJSON-Net/GeoJSON.Net/tree/master/src/GeoJSON.Net.Tests) for more examples.
3633

3734

38-
## News
39-
It's probably best to check out the [commits](https://github.com/GeoJSON-Net/GeoJSON.Net/commits/master)
40-
and the [issues](https://github.com/GeoJSON-Net/GeoJSON.Net/issues) what has been added over time.
41-
4235
## Contributing
4336
Highly welcome! Just fork away and send a pull request. We try and review most pull requests within a couple of days. There is now a version 2.0.0 branch. I've created this ready for any breaking changes and any extra features and would encourage anything that isn't a bug fix to go in there.
4437

src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using GeoJSON.Net.Feature;
51
using GeoJSON.Net.Geometry;
62
using Newtonsoft.Json;
73
using NUnit.Framework;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
87

98
namespace GeoJSON.Net.Tests.Feature
109
{
@@ -356,7 +355,65 @@ public void Feature_Equals_Itself_Issue94()
356355
Assert.IsTrue(equal1);
357356
Assert.IsTrue(equal2);
358357
}
359-
358+
359+
[Test]
360+
public void Feature_Equals_Geometry_Null_Issue115()
361+
{
362+
bool equal1 = false;
363+
bool equal2 = false;
364+
365+
var feature1 = new Net.Feature.Feature(null);
366+
var feature2 = new Net.Feature.Feature(new Point(new Position(12, 123)));
367+
368+
Assert.DoesNotThrow(() =>
369+
{
370+
equal1 = feature1 == feature2;
371+
equal2 = feature1.Equals(feature2);
372+
});
373+
374+
Assert.IsFalse(equal1);
375+
Assert.IsFalse(equal2);
376+
}
377+
378+
[Test]
379+
public void Feature_Equals_Other_Geometry_Null_Issue115()
380+
{
381+
bool equal1 = false;
382+
bool equal2 = false;
383+
384+
var feature1 = new Net.Feature.Feature(new Point(new Position(12, 123)));
385+
var feature2 = new Net.Feature.Feature(null);
386+
387+
Assert.DoesNotThrow(() =>
388+
{
389+
equal1 = feature1 == feature2;
390+
equal2 = feature1.Equals(feature2);
391+
});
392+
393+
Assert.IsFalse(equal1);
394+
Assert.IsFalse(equal2);
395+
}
396+
397+
[Test]
398+
public void Feature_Equals_All_Geometry_Null_Issue115()
399+
{
400+
bool equal1 = false;
401+
bool equal2 = false;
402+
403+
var feature1 = new Net.Feature.Feature(null);
404+
var feature2 = new Net.Feature.Feature(null);
405+
406+
Assert.DoesNotThrow(() =>
407+
{
408+
equal1 = feature1 == feature2;
409+
equal2 = feature1.Equals(feature2);
410+
});
411+
412+
Assert.IsTrue(equal1);
413+
Assert.IsTrue(equal2);
414+
}
415+
416+
360417
private IGeometryObject GetGeometry()
361418
{
362419
var coordinates = new List<LineString>

src/GeoJSON.Net/Feature/Feature.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ public bool Equals(Feature<TGeometry> other)
175175
if (ReferenceEquals(null, other)) return false;
176176
if (ReferenceEquals(this, other)) return true;
177177

178+
if (Geometry == null && other.Geometry == null)
179+
{
180+
return true;
181+
}
182+
183+
if (Geometry == null && other.Geometry != null)
184+
{
185+
return false;
186+
}
187+
188+
if (Geometry == null)
189+
{
190+
return false;
191+
}
192+
178193
return Geometry.Equals(other.Geometry);
179194
}
180195

0 commit comments

Comments
 (0)