Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -rc5360f0514913f85b89148bd8a63f8b0f5943493 -r690aec1a84716f53f06b669903e2d1fd1560fc6b --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision c5360f0514913f85b89148bd8a63f8b0f5943493) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 690aec1a84716f53f06b669903e2d1fd1560fc6b) @@ -163,11 +163,11 @@ var layersBeforeUpdate = mapView.Layers.ToList(); - // Call + // When mapLineData.Features = new MapFeature[0]; mapLineData.NotifyObservers(); - // Assert + // Then Assert.AreEqual(3, mapView.Layers.Count); Assert.AreSame(layersBeforeUpdate[0], mapView.Layers[0]); Assert.AreSame(layersBeforeUpdate[1], mapView.Layers[1]); @@ -176,6 +176,105 @@ } [Test] + public void GivenMapControlWithData_WhenMapDataRemoved_CorrespondingLayerRemoved() + { + // Given + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var mapPointData = new MapPointData("Points"); + var mapLineData = new MapLineData("Lines"); + var mapPolygonData = new MapPolygonData("Polygons"); + var mapDataCollection = new MapDataCollection("Root collection"); + var nestedMapDataCollection1 = new MapDataCollection("Nested collection 1"); + var nestedMapDataCollection2 = new MapDataCollection("Nested collection 2"); + + mapDataCollection.Add(mapPointData); + mapDataCollection.Add(nestedMapDataCollection1); + nestedMapDataCollection1.Add(mapLineData); + nestedMapDataCollection1.Add(nestedMapDataCollection2); + nestedMapDataCollection2.Add(mapPolygonData); + + map.Data = mapDataCollection; + + // When + nestedMapDataCollection1.Remove(mapLineData); + nestedMapDataCollection1.NotifyObservers(); + + // Then + Assert.AreEqual(2, mapView.Layers.Count); + Assert.IsInstanceOf(mapView.Layers[0]); + Assert.IsInstanceOf(mapView.Layers[1]); + } + } + + [Test] + public void GivenMapControlWithData_WhenMapDataAdded_CorrespondingLayerAdded() + { + // Given + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var mapPointData = new MapPointData("Points"); + var mapLineData = new MapLineData("Lines"); + var mapPolygonData = new MapPolygonData("Polygons"); + var mapDataCollection = new MapDataCollection("Root collection"); + var nestedMapDataCollection1 = new MapDataCollection("Nested collection 1"); + var nestedMapDataCollection2 = new MapDataCollection("Nested collection 2"); + + mapDataCollection.Add(mapPointData); + mapDataCollection.Add(nestedMapDataCollection1); + nestedMapDataCollection1.Add(mapLineData); + nestedMapDataCollection1.Add(nestedMapDataCollection2); + nestedMapDataCollection2.Add(mapPolygonData); + + map.Data = mapDataCollection; + + // When + nestedMapDataCollection1.Insert(0, new MapPolygonData("Additional polygons")); + nestedMapDataCollection1.NotifyObservers(); + + // Then + Assert.AreEqual(4, mapView.Layers.Count); + Assert.IsInstanceOf(mapView.Layers[0]); + Assert.IsInstanceOf(mapView.Layers[1]); + Assert.IsInstanceOf(mapView.Layers[2]); + Assert.IsInstanceOf(mapView.Layers[3]); + } + } + + [Test] + public void GivenMapControlWithData_WhenMapDataMoved_CorrespondingLayerMoved() + { + // Given + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var mapPointData = new MapPointData("Points"); + var mapLineData = new MapLineData("Lines"); + var mapPolygonData = new MapPolygonData("Polygons"); + var mapDataCollection = new MapDataCollection("Root collection"); + + mapDataCollection.Add(mapPointData); + mapDataCollection.Add(mapLineData); + mapDataCollection.Add(mapPolygonData); + + map.Data = mapDataCollection; + + // When + mapDataCollection.Remove(mapPointData); + mapDataCollection.Add(mapPointData); + mapDataCollection.NotifyObservers(); + + // Then + Assert.AreEqual(3, mapView.Layers.Count); + Assert.IsInstanceOf(mapView.Layers[0]); + Assert.IsInstanceOf(mapView.Layers[1]); + Assert.IsInstanceOf(mapView.Layers[2]); + } + } + + [Test] [RequiresSTA] public void ZoomToAllVisibleLayers_MapInFormWithEmptyDataSet_ViewInvalidatedLayersSame() {