Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -r9bb8dbe7de006c5ced0943bd226f88a6ff13736f -r41ca4af10d1089c35edfdd620b12ac49d54540f2 --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 9bb8dbe7de006c5ced0943bd226f88a6ff13736f) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 41ca4af10d1089c35edfdd620b12ac49d54540f2) @@ -118,7 +118,7 @@ { map.BackgroundMapData = backgroundMapData; var mapDataCollection = new MapDataCollection("A"); - mapDataCollection.Add(new MapPointData("points") + mapDataCollection.Add(new MapPointData("Points") { Features = new[] { @@ -155,36 +155,8 @@ // Given using (var map = new MapControl()) { - var mapPointData = new MapPointData("Points") - { - Features = new[] - { - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(1.1, 2.2) - } - }) - }) - } - }; - 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); - // When - map.Data = mapDataCollection; + map.Data = CreateTestMapDataCollection(); // Then Map mapView = map.Controls.OfType().First(); @@ -242,26 +214,18 @@ using (var map = new MapControl()) { Map 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 testMapDataCollection = CreateTestMapDataCollection(); + FeatureBasedMapData featureBasedMapData = testMapDataCollection.Collection + .OfType() + .First(); - mapDataCollection.Add(mapPointData); - mapDataCollection.Add(nestedMapDataCollection1); - nestedMapDataCollection1.Add(mapLineData); - nestedMapDataCollection1.Add(nestedMapDataCollection2); - nestedMapDataCollection2.Add(mapPolygonData); + map.Data = testMapDataCollection; - map.Data = mapDataCollection; - IMapLayer[] layersBeforeUpdate = mapView.Layers.ToArray(); // When - mapLineData.Features = new MapFeature[0]; - mapLineData.NotifyObservers(); + featureBasedMapData.Features = new MapFeature[0]; + featureBasedMapData.NotifyObservers(); // Then CollectionAssert.AreEqual(layersBeforeUpdate, mapView.Layers); @@ -275,29 +239,24 @@ using (var map = new MapControl()) { Map 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 testMapDataCollection = CreateTestMapDataCollection(); + MapDataCollection nestedMapDataCollection = testMapDataCollection.Collection + .OfType() + .First(); + MapLineData nestedMapLineData = nestedMapDataCollection.Collection + .OfType() + .First(); - mapDataCollection.Add(mapPointData); - mapDataCollection.Add(nestedMapDataCollection1); - nestedMapDataCollection1.Add(mapLineData); - nestedMapDataCollection1.Add(nestedMapDataCollection2); - nestedMapDataCollection2.Add(mapPolygonData); + map.Data = testMapDataCollection; - map.Data = mapDataCollection; - List layersBeforeUpdate = mapView.Layers.ToList(); // Precondition Assert.AreEqual(3, layersBeforeUpdate.Count); // When - nestedMapDataCollection1.Remove(mapLineData); - nestedMapDataCollection1.NotifyObservers(); + nestedMapDataCollection.Remove(nestedMapLineData); + nestedMapDataCollection.NotifyObservers(); // Then Assert.AreEqual(2, mapView.Layers.Count); @@ -315,29 +274,21 @@ using (var map = new MapControl()) { Map 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 testMapDataCollection = CreateTestMapDataCollection(); + MapDataCollection nestedMapDataCollection = testMapDataCollection.Collection + .OfType() + .First(); - mapDataCollection.Add(mapPointData); - mapDataCollection.Add(nestedMapDataCollection1); - nestedMapDataCollection1.Add(mapLineData); - nestedMapDataCollection1.Add(nestedMapDataCollection2); - nestedMapDataCollection2.Add(mapPolygonData); + map.Data = testMapDataCollection; - map.Data = mapDataCollection; - List layersBeforeUpdate = mapView.Layers.ToList(); // Precondition Assert.AreEqual(3, layersBeforeUpdate.Count); // When - nestedMapDataCollection1.Insert(0, new MapPolygonData("Additional polygons")); - nestedMapDataCollection1.NotifyObservers(); + nestedMapDataCollection.Insert(0, new MapPolygonData("Additional polygons")); + nestedMapDataCollection.NotifyObservers(); // Then Assert.AreEqual(4, mapView.Layers.Count); @@ -357,17 +308,16 @@ using (var map = new MapControl()) { Map 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 testMapDataCollection = CreateTestMapDataCollection(); + MapDataCollection nestedMapDataCollection = testMapDataCollection.Collection + .OfType() + .Last(); + MapPointData nestedMapPointData = testMapDataCollection.Collection + .OfType() + .First(); - mapDataCollection.Add(mapPointData); - mapDataCollection.Add(mapLineData); - mapDataCollection.Add(mapPolygonData); + map.Data = testMapDataCollection; - map.Data = mapDataCollection; - List layersBeforeUpdate = mapView.Layers.Cast().ToList(); // Precondition @@ -377,9 +327,9 @@ Assert.AreEqual("Polygons", layersBeforeUpdate[2].Name); // When - mapDataCollection.Remove(mapPointData); - mapDataCollection.Add(mapPointData); - mapDataCollection.NotifyObservers(); + testMapDataCollection.Remove(nestedMapPointData); + nestedMapDataCollection.Add(nestedMapPointData); + nestedMapDataCollection.NotifyObservers(); // Then Assert.AreEqual(3, mapView.Layers.Count); @@ -569,6 +519,39 @@ Assert.AreEqual(5.7, mapView.ViewExtents.MaxY, 1e-3); } + private static MapDataCollection CreateTestMapDataCollection() + { + var mapPointData = new MapPointData("Points") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(1.1, 2.2) + } + }) + }) + } + }; + 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); + + return mapDataCollection; + } + #region BackgroundMapData [Test]