Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -r690aec1a84716f53f06b669903e2d1fd1560fc6b -r778ffc42baaaf50f68d84359fd7dbe63be311a4b --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 690aec1a84716f53f06b669903e2d1fd1560fc6b) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 778ffc42baaaf50f68d84359fd7dbe63be311a4b) @@ -29,6 +29,7 @@ using Core.Components.Gis.Geometries; using DotSpatial.Controls; using DotSpatial.Data; +using DotSpatial.Symbology; using NUnit.Extensions.Forms; using NUnit.Framework; @@ -76,7 +77,7 @@ } [Test] - public void GivenMapControlWithoutData_WhenDataSetToMapDataCollection_MapControlUpdated() + public void GivenMapControlWithoutData_WhenDataSetToMapDataCollection_ThenMapControlUpdated() { // Given using (var map = new MapControl()) @@ -100,14 +101,15 @@ // Then Assert.AreEqual(3, mapView.Layers.Count); - Assert.IsInstanceOf(mapView.Layers[0]); - Assert.IsInstanceOf(mapView.Layers[1]); - Assert.IsInstanceOf(mapView.Layers[2]); + var featureLayers = mapView.Layers.Cast().ToList(); + Assert.AreEqual("Points", featureLayers[0].Name); + Assert.AreEqual("Lines", featureLayers[1].Name); + Assert.AreEqual("Polygons", featureLayers[2].Name); } } [Test] - public void GivenMapControlWithData_WhenDataSetToOtherMapDataCollection_MapControlUpdated() + public void GivenMapControlWithData_WhenDataSetToOtherMapDataCollection_ThenMapControlUpdated() { // Given using (var map = new MapControl()) @@ -127,20 +129,21 @@ // Precondition Assert.AreEqual(1, mapView.Layers.Count); - Assert.IsInstanceOf(mapView.Layers[0]); + Assert.AreEqual("Points", ((FeatureLayer) mapView.Layers[0]).Name); // When map.Data = mapDataCollection2; // Then Assert.AreEqual(2, mapView.Layers.Count); - Assert.IsInstanceOf(mapView.Layers[0]); - Assert.IsInstanceOf(mapView.Layers[1]); + var featureLayers = mapView.Layers.Cast().ToList(); + Assert.AreEqual("Lines", featureLayers[0].Name); + Assert.AreEqual("Polygons", featureLayers[1].Name); } } [Test] - public void GivenMapControlWithData_WhenMapDataNotifiesChange_CorrespondingLayerReused() + public void GivenMapControlWithData_WhenMapDataNotifiesChange_ThenAllLayersReused() { // Given using (var map = new MapControl()) @@ -168,15 +171,12 @@ mapLineData.NotifyObservers(); // Then - Assert.AreEqual(3, mapView.Layers.Count); - Assert.AreSame(layersBeforeUpdate[0], mapView.Layers[0]); - Assert.AreSame(layersBeforeUpdate[1], mapView.Layers[1]); - Assert.AreSame(layersBeforeUpdate[2], mapView.Layers[2]); + Assert.AreEqual(0, layersBeforeUpdate.Except(mapView.Layers).Count()); } } [Test] - public void GivenMapControlWithData_WhenMapDataRemoved_CorrespondingLayerRemoved() + public void GivenMapControlWithData_WhenMapDataRemoved_ThenCorrespondingLayerRemovedAndOtherLayersReused() { // Given using (var map = new MapControl()) @@ -197,19 +197,23 @@ map.Data = mapDataCollection; + var layersBeforeUpdate = mapView.Layers.ToList(); + // When nestedMapDataCollection1.Remove(mapLineData); nestedMapDataCollection1.NotifyObservers(); // Then Assert.AreEqual(2, mapView.Layers.Count); - Assert.IsInstanceOf(mapView.Layers[0]); - Assert.IsInstanceOf(mapView.Layers[1]); + var featureLayers = mapView.Layers.Cast().ToList(); + Assert.AreEqual("Points", featureLayers[0].Name); + Assert.AreEqual("Polygons", featureLayers[1].Name); + Assert.AreEqual(0, mapView.Layers.Except(layersBeforeUpdate).Count()); } } [Test] - public void GivenMapControlWithData_WhenMapDataAdded_CorrespondingLayerAdded() + public void GivenMapControlWithData_WhenMapDataAdded_ThenCorrespondingLayerAddedAndOtherLayersReused() { // Given using (var map = new MapControl()) @@ -230,21 +234,25 @@ map.Data = mapDataCollection; + var layersBeforeUpdate = mapView.Layers.ToList(); + // 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]); + var featureLayers = mapView.Layers.Cast().ToList(); + Assert.AreEqual("Points", featureLayers[0].Name); + Assert.AreEqual("Additional polygons", featureLayers[1].Name); + Assert.AreEqual("Lines", featureLayers[2].Name); + Assert.AreEqual("Polygons", featureLayers[3].Name); + Assert.AreEqual(0, layersBeforeUpdate.Except(mapView.Layers).Count()); } } [Test] - public void GivenMapControlWithData_WhenMapDataMoved_CorrespondingLayerMoved() + public void GivenMapControlWithData_WhenMapDataMoved_ThenCorrespondingLayerMovedAndAllLayersReused() { // Given using (var map = new MapControl()) @@ -261,16 +269,20 @@ map.Data = mapDataCollection; + var layersBeforeUpdate = mapView.Layers.ToList(); + // 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]); + var featureLayers = mapView.Layers.Cast().ToList(); + Assert.AreEqual("Lines", featureLayers[0].Name); + Assert.AreEqual("Polygons", featureLayers[1].Name); + Assert.AreEqual("Points", featureLayers[2].Name); + Assert.AreEqual(0, layersBeforeUpdate.Except(mapView.Layers).Count()); } }