public void FeatureCollectionSerialization() { var model = new FeatureCollection(); for (var i = 10; i-- > 0;) { var geom = new LineString(new[] { new GeographicPosition(51.010, -1.034), new GeographicPosition(51.010, -0.034) }); var props = new Dictionary<string, object> { { "test1", "1" }, { "test2", 2 } }; var feature = new Net.Feature.Feature(geom, props); model.Features.Add(feature); } var actualJson = JsonConvert.SerializeObject(model); Assert.IsNotNull(actualJson); Assert.IsFalse(string.IsNullOrEmpty(actualJson)); }
public void Feature_Equals_Itself_Issue94() { bool equal1 = false; bool equal2 = false; var feature = new Net.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { equal1 = feature == feature; equal2 = feature.Equals(feature); }); Assert.IsTrue(equal1); Assert.IsTrue(equal2); }
public void Feature_Equals_Null_Issue94() { bool equal1 = true; bool equal2 = true; var feature = new Net.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { equal1 = feature.Equals(null); equal2 = feature == null; }); Assert.IsFalse(equal1); Assert.IsFalse(equal2); }
public void Feature_Equals_Other_Geometry_Null_Issue115() { bool equal1 = false; bool equal2 = false; var feature1 = new Net.Feature.Feature(new Point(new Position(12, 123))); var feature2 = new Net.Feature.Feature(null); Assert.DoesNotThrow(() => { equal1 = feature1 == feature2; equal2 = feature1.Equals(feature2); }); Assert.IsFalse(equal1); Assert.IsFalse(equal2); }
public void Feature_Equals_All_Geometry_Null_Issue115() { bool equal1 = false; bool equal2 = false; var feature1 = new Net.Feature.Feature(null); var feature2 = new Net.Feature.Feature(null); Assert.DoesNotThrow(() => { equal1 = feature1 == feature2; equal2 = feature1.Equals(feature2); }); Assert.IsTrue(equal1); Assert.IsTrue(equal2); }
public void Feature_Equals_Itself_Issue94() { bool equal1 = false; bool equal2 = false; var feature = new Net.Feature.Feature(new Point(new Position(12, 123))); Assert.DoesNotThrow(() => { #pragma warning disable CS1718 // Comparison made to same variable equal1 = feature == feature; #pragma warning restore CS1718 // Comparison made to same variable equal2 = feature.Equals(feature); }); Assert.IsTrue(equal1); Assert.IsTrue(equal2); }
private void Assert_Are_Equal(Net.Feature.Feature left, Net.Feature.Feature right) { Assert.AreEqual(left, right); Assert.IsTrue(left.Equals(right)); Assert.IsTrue(right.Equals(left)); Assert.IsTrue(left.Equals(left)); Assert.IsTrue(right.Equals(right)); Assert.IsTrue(left == right); Assert.IsTrue(right == left); Assert.IsFalse(left != right); Assert.IsFalse(right != left); Assert.AreEqual(left.GetHashCode(), right.GetHashCode()); }
private FeatureCollection GetFeatureCollection() { var model = new FeatureCollection(); for (var i = 10; i-- > 0;) { var geom = new LineString(new[] { new GeographicPosition(51.010, -1.034), new GeographicPosition(51.010, -0.034) }); var props = FeatureTests.GetPropertiesInRandomOrder(); var feature = new Net.Feature.Feature(geom, props); model.Features.Add(feature); } return model; }
public void Ctor_Can_Add_Properties_Using_Object() { var properties = new TestFeatureProperty { BooleanProperty = true, DateTimeProperty = DateTime.Now, DoubleProperty = 1.2345d, EnumProperty = TestFeatureEnum.Value1, IntProperty = -1, StringProperty = "Hello, GeoJSON !" }; Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Count > 1); Assert.AreEqual(feature.Properties.Count, 6); }
public void Serialized_And_Deserialized_Feature_Equals_And_Share_HashCode() { var geometry = GetGeometry(); var leftFeature = new Net.Feature.Feature(geometry); var leftJson = JsonConvert.SerializeObject(leftFeature); var left = JsonConvert.DeserializeObject <Net.Feature.Feature>(leftJson); var rightFeature = new Net.Feature.Feature(geometry); var rightJson = JsonConvert.SerializeObject(rightFeature); var right = JsonConvert.DeserializeObject <Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder()); leftJson = JsonConvert.SerializeObject(leftFeature); left = JsonConvert.DeserializeObject <Net.Feature.Feature>(leftJson); rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder()); rightJson = JsonConvert.SerializeObject(rightFeature); right = JsonConvert.DeserializeObject <Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); // assert properties doesn't influence comparison and hashcode leftFeature = new Net.Feature.Feature(geometry, null, "abc_abc"); leftJson = JsonConvert.SerializeObject(leftFeature); left = JsonConvert.DeserializeObject <Net.Feature.Feature>(leftJson); rightFeature = new Net.Feature.Feature(geometry, null, "xyz_XYZ"); rightJson = JsonConvert.SerializeObject(rightFeature); right = JsonConvert.DeserializeObject <Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); // assert id's doesn't influence comparison and hashcode leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); leftJson = JsonConvert.SerializeObject(leftFeature); left = JsonConvert.DeserializeObject <Net.Feature.Feature>(leftJson); rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); rightJson = JsonConvert.SerializeObject(rightFeature); right = JsonConvert.DeserializeObject <Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); // assert id's + properties doesn't influence comparison and hashcode }
private void Assert_Are_Equal <TGeometry, TProps>(Net.Feature.Feature <TGeometry, TProps> left, Net.Feature.Feature <TGeometry, TProps> right) where TGeometry : IGeometryObject { Assert.AreEqual(left, right); Assert.IsTrue(left.Equals(right)); Assert.IsTrue(right.Equals(left)); Assert.IsTrue(left.Equals(left)); Assert.IsTrue(right.Equals(right)); Assert.IsTrue(left == right); Assert.IsTrue(right == left); Assert.IsFalse(left != right); Assert.IsFalse(right != left); Assert.AreEqual(left.GetHashCode(), right.GetHashCode()); }
private FeatureCollection GetFeatureCollection() { var model = new FeatureCollection(); for (var i = 10; i-- > 0;) { var geom = new LineString(new[] { new Position(51.010, -1.034), new Position(51.010, -0.034) }); var props = FeatureTests.GetPropertiesInRandomOrder(); var feature = new Net.Feature.Feature(geom, props); model.Features.Add(feature); } return(model); }
public void Can_Serialize_MultiPolygon_Feature() { var multiPolygon = new GeoMultiPolygon(new List <GeoPolygon> { new GeoPolygon(new List <GeoLineString> { new GeoLineString(new List <GeoEntity> { new GeoEntity(0, 0), new GeoEntity(1, 0), new GeoEntity(1, 1), new GeoEntity(0, 1), new GeoEntity(0, 0) }) }), new GeoPolygon(new List <GeoLineString> { new GeoLineString(new List <GeoEntity> { new GeoEntity(100, 100), new GeoEntity(101, 100), new GeoEntity(101, 101), new GeoEntity(100, 101), new GeoEntity(100, 100) }), new GeoLineString(new List <GeoEntity> { new GeoEntity(200, 200), new GeoEntity(201, 200), new GeoEntity(201, 201), new GeoEntity(200, 201), new GeoEntity(200, 200) }) }) }); var feature = new Net.Feature.Feature(multiPolygon); var expectedJson = GetExpectedJson(); var actualJson = JsonSerializer.SerializeToString(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Can_Serialize_MultiPolygon_Feature() { var multiPolygon = new MultiPolygon(new List <Polygon> { new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(0, 0), new Position(0, 1), new Position(1, 1), new Position(1, 0), new Position(0, 0) }) }), new Polygon(new List <LineString> { new LineString(new List <IPosition> { new Position(70, 70), new Position(70, 71), new Position(71, 71), new Position(71, 70), new Position(70, 70) }), new LineString(new List <IPosition> { new Position(80, 80), new Position(80, 81), new Position(81, 81), new Position(81, 80), new Position(80, 80) }) }) }); var feature = new Net.Feature.Feature(multiPolygon); var expectedJson = GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Can_Serialize_MultiPolygon_Feature() { var multiPolygon = new MultiPolygon(new List <Polygon> { new Polygon(new List <LineString> { new LineString(new List <GeographicPosition> { new GeographicPosition(0, 0), new GeographicPosition(0, 1), new GeographicPosition(1, 1), new GeographicPosition(1, 0), new GeographicPosition(0, 0) }) }), new Polygon(new List <LineString> { new LineString(new List <GeographicPosition> { new GeographicPosition(100, 100), new GeographicPosition(100, 101), new GeographicPosition(101, 101), new GeographicPosition(101, 100), new GeographicPosition(100, 100) }), new LineString(new List <GeographicPosition> { new GeographicPosition(200, 200), new GeographicPosition(200, 201), new GeographicPosition(201, 201), new GeographicPosition(201, 200), new GeographicPosition(200, 200) }) }) }); var feature = new Net.Feature.Feature(multiPolygon); var expectedJson = GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void FeatureCollection_Test_IndexOf() { var model = new FeatureCollection(); var expectedIds = new List <string>(); var expectedIndexes = new List <int>(); for (var i = 0; i < 10; i++) { var id = "id" + i; expectedIds.Add(id); expectedIndexes.Add(i); var geom = new LineString(new[] { new Position(51.010, -1.034), new Position(51.010, -0.034) }); var props = FeatureTests.GetPropertiesInRandomOrder(); var feature = new Net.Feature.Feature(geom, props, id); model.Features.Add(feature); } for (var i = 0; i < 10; i++) { var actualFeature = model.Features[i]; var actualId = actualFeature.Id; var actualIndex = model.Features.IndexOf(actualFeature); var expectedId = expectedIds[i]; var expectedIndex = expectedIndexes[i]; Assert.AreEqual(expectedId, actualId); Assert.AreEqual(expectedIndex, actualIndex); Assert.Inconclusive("not supported. the Feature.Id is optional. " + " create a new class that inherits from" + " Feature and then override Equals and GetHashCode"); } }
public void Can_Serialize_Dictionary_Subclass() { var properties = new TestFeaturePropertyDictionary() { BooleanProperty = true, DoubleProperty = 1.2345d, EnumProperty = TestFeatureEnum.Value1, IntProperty = -1, StringProperty = "Hello, GeoJSON !" }; Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); var expectedJson = this.GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); Assert.False(string.IsNullOrEmpty(expectedJson)); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Can_Serialize_Polygon_Feature() { var coordinates = new List <GeoEntity> { new GeoEntity(4.889259338378, 52.37072588121), new GeoEntity(4.895267486572, 52.37114511056), new GeoEntity(4.892091751098, 52.36931095278), new GeoEntity(4.889259338378, 52.37072588121) }; var polygon = new GeoPolygon(new List <GeoLineString> { new GeoLineString(coordinates) }); var properties = new Dictionary <string, object> { { "Name", "Foo" } }; var feature = new Net.Feature.Feature(polygon, properties); var expectedJson = GetExpectedJson(); var actualJson = JsonSerializer.SerializeToString(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Can_Serialize_Polygon_Feature() { var coordinates = new List <IPosition> { new Position(52.370725881211314, 4.889259338378906), new Position(52.3711451105601, 4.895267486572266), new Position(52.36931095278263, 4.892091751098633), new Position(52.370725881211314, 4.889259338378906) }; var polygon = new Polygon(new List <LineString> { new LineString(coordinates) }); var properties = new Dictionary <string, object> { { "Name", "Foo" } }; var feature = new Net.Feature.Feature(polygon, properties); var expectedJson = GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Ctor_Can_Add_Properties_Using_Object_Inheriting_Dictionary() { int expectedProperties = 6; var properties = new TestFeaturePropertyDictionary() { BooleanProperty = true, DateTimeProperty = DateTime.Now, DoubleProperty = 1.2345d, EnumProperty = TestFeatureEnum.Value1, IntProperty = -1, StringProperty = "Hello, GeoJSON !" }; Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new Position(10, 10)), properties); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Count > 1); Assert.AreEqual( feature.Properties.Count, expectedProperties, $"Expected: {expectedProperties} Actual: {feature.Properties.Count}"); }
public void Ctor_Creates_Properties_Collection_When_Passed_Null_Proper_Object() { Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new GeographicPosition(10, 10)), (object)null); Assert.IsNotNull(feature.Properties); CollectionAssert.IsEmpty(feature.Properties); }
public void Ctor_Can_Add_Properties_Using_Object() { var properties = new MyTestClass { BooleanProperty = true, DateTimeProperty = DateTime.Now, DoubleProperty = 1.2345d, EnumProperty = MyTestEnum.Value1, IntProperty = -1, StringProperty = "Hello, GeoJSON !" }; Net.Feature.Feature feature = new Net.Feature.Feature(new Point(new GeographicPosition(10, 10)), properties); Assert.IsNotNull(feature.Properties); Assert.IsTrue(feature.Properties.Count > 1); Assert.AreEqual(feature.Properties.Count, 6); }
public void Can_Serialize_MultiPolygon_Feature() { var multiPolygon = new MultiPolygon(new List<Polygon> { new Polygon(new List<LineString> { new LineString(new List<GeographicPosition> { new GeographicPosition(0, 0), new GeographicPosition(0, 1), new GeographicPosition(1, 1), new GeographicPosition(1, 0), new GeographicPosition(0, 0) }) }), new Polygon(new List<LineString> { new LineString(new List<GeographicPosition> { new GeographicPosition(100, 100), new GeographicPosition(100, 101), new GeographicPosition(101, 101), new GeographicPosition(101, 100), new GeographicPosition(100, 100) }), new LineString(new List<GeographicPosition> { new GeographicPosition(200, 200), new GeographicPosition(200, 201), new GeographicPosition(201, 201), new GeographicPosition(201, 200), new GeographicPosition(200, 200) }) }) }); var feature = new Net.Feature.Feature(multiPolygon); var expectedJson = GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
public void Can_Serialize_Polygon_Feature() { var coordinates = new List<GeographicPosition> { new GeographicPosition(52.370725881211314, 4.889259338378906), new GeographicPosition(52.3711451105601, 4.895267486572266), new GeographicPosition(52.36931095278263, 4.892091751098633), new GeographicPosition(52.370725881211314, 4.889259338378906) }; var polygon = new Polygon(new List<LineString> { new LineString(coordinates) }); var properties = new Dictionary<string, object> { { "Name", "Foo" } }; var feature = new Net.Feature.Feature(polygon, properties); var expectedJson = GetExpectedJson(); var actualJson = JsonConvert.SerializeObject(feature); JsonAssert.AreEqual(expectedJson, actualJson); }
private Net.Feature.Feature GetFeature(IGeometryObject geometry, object properties = null, string id = null) { var feature = new Net.Feature.Feature(geometry, properties, id); return(feature); }
public void Feature_Equals_GetHashCode_Contract_Dictionary() { var leftDictionary = GetPropertiesInRandomOrder(); var rightDictionary = GetPropertiesInRandomOrder(); var geometry_10 = new GeographicPosition(10, 10); var geometry_20 = new GeographicPosition(20, 20); var left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); var right = new Net.Feature.Feature(new Point( geometry_20), rightDictionary, "abc"); Assert_Are_Not_Equal(left, right); // different geometries left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_20), rightDictionary, "xyz"); // different geometries and ids Assert_Are_Not_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // identical except properties are in random order Assert_Are_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "xyz"); // different ids Assert_Are_Not_Equal(left, right); leftDictionary.Add("Guid", Guid.NewGuid().ToString()); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // different properties Assert_Are_Not_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), null, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // different properties Assert_Are_Not_Equal(left, right); }
public void Serialized_And_Deserialized_Feature_Equals_And_Share_HashCode() { var geometry = GetGeometry(); var leftFeature = new Net.Feature.Feature(geometry, null, null); var leftJson = JsonConvert.SerializeObject(leftFeature); var left = JsonConvert.DeserializeObject<Net.Feature.Feature>(leftJson); var rightFeature = new Net.Feature.Feature(geometry, null, null); var rightJson = JsonConvert.SerializeObject(rightFeature); var right = JsonConvert.DeserializeObject<Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), null); leftJson = JsonConvert.SerializeObject(leftFeature); left = JsonConvert.DeserializeObject<Net.Feature.Feature>(leftJson); rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), null); rightJson = JsonConvert.SerializeObject(rightFeature); right = JsonConvert.DeserializeObject<Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); leftFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); leftJson = JsonConvert.SerializeObject(leftFeature); left = JsonConvert.DeserializeObject<Net.Feature.Feature>(leftJson); rightFeature = new Net.Feature.Feature(geometry, GetPropertiesInRandomOrder(), "abc"); rightJson = JsonConvert.SerializeObject(rightFeature); right = JsonConvert.DeserializeObject<Net.Feature.Feature>(rightJson); Assert_Are_Equal(left, right); }
private Net.Feature.Feature GetFeature(IGeometryObject geometry, object properties = null, string id = null) { var feature = new Net.Feature.Feature(geometry, properties, id); return feature; }
public void FeatureCollection_Test_IndexOf() { var model = new FeatureCollection(); var expectedIds = new List<string>(); var expectedIndexes = new List<int>(); for (var i = 0; i < 10; i++) { var id = "id" + i.ToString(); expectedIds.Add(id); expectedIndexes.Add(i); var geom = new LineString(new[] { new GeographicPosition(51.010, -1.034), new GeographicPosition(51.010, -0.034) }); var props = FeatureTests.GetPropertiesInRandomOrder(); var feature = new Net.Feature.Feature(geom, props, id); model.Features.Add(feature); } for (var i = 0; i < 10; i++) { var actualFeature = model.Features[i]; var actualId = actualFeature.Id; var actualIndex = model.Features.IndexOf(actualFeature); var expectedId = expectedIds[i]; var expectedIndex = expectedIndexes[i]; Assert.AreEqual(expectedId, actualId); Assert.AreEqual(expectedIndex, actualIndex); } }
public void Feature_Equals_GetHashCode_Contract_Properties_Of_Objects() { // order of keys should not matter var leftProp = new MyTestClass { StringProperty = "Hello, GeoJSON !", EnumProperty = MyTestEnum.Value1, IntProperty = -1, BooleanProperty = true, DateTimeProperty = DateTime.Now, DoubleProperty = 1.2345d }; var left = new Net.Feature.Feature(new Point(new GeographicPosition(10, 10)), leftProp); var rightProp = new MyTestClass { BooleanProperty = true, DateTimeProperty = DateTime.Now, DoubleProperty = 1.2345d, EnumProperty = MyTestEnum.Value1, IntProperty = -1, StringProperty = "Hello, GeoJSON !" }; var right = new Net.Feature.Feature(new Point(new GeographicPosition(10, 10)), rightProp); Assert_Are_Equal(left, right); }