Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -rb519fc798c63691f04bb8008b562a94ed9232d51 -ra23d8fd94a47ec519194793bc559b0b86de509fd --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision b519fc798c63691f04bb8008b562a94ed9232d51) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision a23d8fd94a47ec519194793bc559b0b86de509fd) @@ -101,10 +101,125 @@ } } + private static MapDataCollection GetTestData() + { + var mapDataCollection = new MapDataCollection("Test data"); + + mapDataCollection.Add(new MapPointData("Test data") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(1.5, 2) + } + }), + new MapGeometry(new[] + { + new[] + { + new Point2D(1.1, 1) + } + }), + new MapGeometry(new[] + { + new[] + { + new Point2D(0.8, 0.5) + } + }) + }) + } + }); + + mapDataCollection.Add(new MapLineData("Test data") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(0.0, 1.1), + new Point2D(1.0, 2.1), + new Point2D(1.6, 1.6) + } + }) + }) + } + }); + + mapDataCollection.Add(new MapPolygonData("Test data") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(1.0, 1.3), + new Point2D(3.0, 2.6), + new Point2D(5.6, 1.6) + } + }) + }) + }, + IsVisible = false + }); + + return mapDataCollection; + } + + private static void ExtendWithExpectedMargin(Extent expectedExtent) + { + double smallestDimension = Math.Min(expectedExtent.Height, expectedExtent.Width); + expectedExtent.ExpandBy(smallestDimension * padding); + } + + private static Extent GetExpectedExtent(FeatureBasedMapData visibleMapData) + { + double minX = double.MaxValue; + double maxX = double.MinValue; + double minY = double.MaxValue; + double maxY = double.MinValue; + + foreach (MapFeature feature in visibleMapData.Features) + { + foreach (MapGeometry geometry in feature.MapGeometries) + { + foreach (IEnumerable pointCollection in geometry.PointCollections) + { + foreach (Point2D point in pointCollection) + { + minX = Math.Min(minX, point.X); + maxX = Math.Max(maxX, point.X); + + minY = Math.Min(minY, point.Y); + maxY = Math.Max(maxY, point.Y); + } + } + } + } + + return new Extent(minX, minY, maxX, maxY); + } + + #region BackgroundMapData + + #region WmtsMapData + [Test] [TestCase(true)] [TestCase(false)] - public void GivenMapControlWithoutBackgroundMapData_WhenBackgroundMapDataSet_ThenMapControlUpdated(bool isVisible) + public void GivenMapControlWithoutBackgroundMapData_WhenWmtsBackgroundMapDataSet_ThenMapControlUpdated(bool isVisible) { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); @@ -368,7 +483,7 @@ // Given WmtsMapData originalBackgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); originalBackgroundMapData.IsVisible = true; - originalBackgroundMapData.Transparency = (RoundedDouble)0.25; + originalBackgroundMapData.Transparency = (RoundedDouble) 0.25; using (new UseCustomTileSourceFactoryConfig(originalBackgroundMapData)) using (var map = new MapControl()) @@ -387,8 +502,8 @@ Assert.AreEqual(layer.Projection, mapView.Projection); // When - var newBackgroundMapData = WmtsMapData.CreateUnconnectedMapData(); - map.BackgroundMapData= newBackgroundMapData; + var newBackgroundMapData = WmtsMapData.CreateUnconnectedMapData(); + map.BackgroundMapData = newBackgroundMapData; // Then Assert.AreEqual(0, mapView.Layers.Count); @@ -397,7 +512,7 @@ } [Test] - public void GivenMapControlWithUnconfiguredBackgroundMapData_WhenBackgroundMapDataSet_ThenMapControlUpdated() + public void GivenMapControlWithUnconfiguredBackgroundMapData_WhenWmtsBackgroundMapDataSet_ThenMapControlUpdated() { // Given var newBackgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); @@ -431,7 +546,7 @@ } [Test] - public void GivenMapControlWithBackgroundData_WhenVisibilityPropertiesChangeAndNotified_ThenBackgroundLayerReused() + public void GivenMapControlWithWmtsBackgroundData_WhenVisibilityPropertiesChangeAndNotified_ThenBackgroundLayerReused() { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); @@ -463,7 +578,7 @@ } [Test] - public void GivenMapWithUnconfiguredBackgroundAndMapDataCollection_WhenBackgroundMapDataConfigured_ThenLayerIsReusedAndUpdatedFeaturesReprojected() + public void GivenMapWithUnconfiguredWmtsBackgroundAndMapDataCollection_WhenBackgroundMapDataConfigured_ThenLayerIsReusedAndUpdatedFeaturesReprojected() { // Given var newBackgroundMapData = WmtsMapData.CreateAlternativePdokMapData(); @@ -525,7 +640,7 @@ } [Test] - public void GivenMapWithBackgroundAndMapDataCollection_WhenBackgroundMapDataConfigurationRemoved_ThenLayerIsReusedAndUpdatedFeaturesReprojected() + public void GivenMapWithWmtsBackgroundAndMapDataCollection_WhenBackgroundMapDataConfigurationRemoved_ThenLayerIsReusedAndUpdatedFeaturesReprojected() { // Given var backgroundMapData = WmtsMapData.CreateAlternativePdokMapData(); @@ -588,7 +703,7 @@ } [Test] - public void GivenMapControlWithData_WhenBackgroundMapDataSet_ThenDataLayersReprojected() + public void GivenMapControlWithData_WhenWmtsBackgroundMapDataSet_ThenDataLayersReprojected() { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateAlternativePdokMapData(); @@ -638,7 +753,7 @@ } [Test] - public void GivenMapControlWithData_WhenUnconfiguredBackgroundMapDataSet_NoChangesToLayerConfiguration() + public void GivenMapControlWithData_WhenUnconfiguredWmtsBackgroundMapDataSet_NoChangesToLayerConfiguration() { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateUnconnectedMapData(); @@ -685,7 +800,7 @@ } [Test] - public void GivenMapControlWithDataAndBackground_WhenDifferentBackgroundMapDataSet_LayersReprojected() + public void GivenMapControlWithDataAndBackground_WhenDifferentWmtsBackgroundMapDataSet_LayersReprojected() { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); @@ -723,7 +838,8 @@ Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); // When - WmtsMapData differentBackgroundMapData = WmtsMapData.CreateAlternativePdokMapData();; + WmtsMapData differentBackgroundMapData = WmtsMapData.CreateAlternativePdokMapData(); + ; using (new UseCustomTileSourceFactoryConfig(differentBackgroundMapData)) { map.BackgroundMapData = differentBackgroundMapData; @@ -742,7 +858,7 @@ } [Test] - public void GivenMapControlWithDataAndBackground_WhenUnconfiguredBackgroundMapDataSet_LayersReprojected() + public void GivenMapControlWithDataAndBackground_WhenUnconfiguredWmtsBackgroundMapDataSet_LayersReprojected() { // Given WmtsMapData backgroundMapData = WmtsMapData.CreateAlternativePdokMapData(); @@ -1286,6 +1402,38 @@ } } + /// + /// Generates containing problematic . + /// + /// The test-name prefix. + /// The data for the test cases. + /// Some test runners, like TeamCity, cannot properly deal with reuse of + /// sources where the source defines a name of the test, + /// as these testrunners to not display tests in hierarchical form. + private static IEnumerable GetProblematicTileSourceFactoryTestCaseData(string prefix) + { + var factoryWithoutRequiredTileSource = MockRepository.GenerateStub(); + factoryWithoutRequiredTileSource.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull)) + .Return(Enumerable.Empty()); + + var factoryThrowingCannotFindTileSourceException = MockRepository.GenerateStub(); + factoryThrowingCannotFindTileSourceException.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull)) + .Throw(new CannotFindTileSourceException()); + + yield return new TestCaseData(factoryWithoutRequiredTileSource) + .SetName($"{prefix}: Required tile source not returned by factory."); + + yield return new TestCaseData(factoryThrowingCannotFindTileSourceException) + .SetName($"{prefix}: Tile source factory throws CannotFindTileSourceException."); + } + + + #endregion + + #endregion + + #region ZoomToAllVisibleLayers + [Test] [Apartment(ApartmentState.STA)] public void ZoomToAllVisibleLayers_MapInFormWithEmptyDataSet_ViewInvalidatedLayersSame() @@ -1669,6 +1817,10 @@ } } + #endregion + + #region SelectionZoom + [Test] [Apartment(ApartmentState.STA)] public void SelectionZoom_MouseUp_DefaultCursorSet() @@ -1769,6 +1921,37 @@ [Test] [Apartment(ApartmentState.STA)] + [TestCase(MouseButtons.Right)] + [TestCase(MouseButtons.Middle)] + public void SelectionZoom_OtherThanMouseLeftDownAndMapBusy_SizeNWSECursorSet(MouseButtons mouseButton) + { + using (var form = new Form()) + { + // Setup + var mapControl = new MapControl(); + form.Controls.Add(mapControl); + form.Show(); + + var map = (Map) new ControlTester("Map").TheObject; + var mapFunctionSelectionZoom = map.MapFunctions.OfType().First(); + + map.IsBusy = true; + map.Cursor = Cursors.WaitCursor; + + // Call + EventHelper.RaiseEvent(mapFunctionSelectionZoom, "MouseDown", new GeoMouseArgs(new MouseEventArgs(mouseButton, 1, 2, 3, 4), map)); + + // Assert + Assert.AreEqual(Cursors.SizeNWSE, map.Cursor); + } + } + + #endregion + + #region Panning + + [Test] + [Apartment(ApartmentState.STA)] public void Panning_MouseUp_DefaultCursorSet() { using (var form = new Form()) @@ -1887,6 +2070,10 @@ } } + #endregion + + #region Toggle + [Test] [Apartment(ApartmentState.STA)] public void ToggleRectangleZooming_Always_CorrectlySetsMapFunctions() @@ -1940,33 +2127,6 @@ } [Test] - [Apartment(ApartmentState.STA)] - [TestCase(MouseButtons.Right)] - [TestCase(MouseButtons.Middle)] - public void SelectionZoom_OtherThanMouseLeftDownAndMapBusy_SizeNWSECursorSet(MouseButtons mouseButton) - { - using (var form = new Form()) - { - // Setup - var mapControl = new MapControl(); - form.Controls.Add(mapControl); - form.Show(); - - var map = (Map) new ControlTester("Map").TheObject; - var mapFunctionSelectionZoom = map.MapFunctions.OfType().First(); - - map.IsBusy = true; - map.Cursor = Cursors.WaitCursor; - - // Call - EventHelper.RaiseEvent(mapFunctionSelectionZoom, "MouseDown", new GeoMouseArgs(new MouseEventArgs(mouseButton, 1, 2, 3, 4), map)); - - // Assert - Assert.AreEqual(Cursors.SizeNWSE, map.Cursor); - } - } - - [Test] [TestCase(true)] [TestCase(false)] public void ToggleRectangleZooming_Always_ChangesState(bool isRectangleZooming) @@ -2047,140 +2207,6 @@ } } - /// - /// Generates containing problematic . - /// - /// The test-name prefix. - /// The data for the test cases. - /// Some test runners, like TeamCity, cannot properly deal with reuse of - /// sources where the source defines a name of the test, - /// as these testrunners to not display tests in hierarchical form. - private static IEnumerable GetProblematicTileSourceFactoryTestCaseData(string prefix) - { - var factoryWithoutRequiredTileSource = MockRepository.GenerateStub(); - factoryWithoutRequiredTileSource.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull)) - .Return(Enumerable.Empty()); - - var factoryThrowingCannotFindTileSourceException = MockRepository.GenerateStub(); - factoryThrowingCannotFindTileSourceException.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull)) - .Throw(new CannotFindTileSourceException()); - - yield return new TestCaseData(factoryWithoutRequiredTileSource) - .SetName($"{prefix}: Required tile source not returned by factory."); - - yield return new TestCaseData(factoryThrowingCannotFindTileSourceException) - .SetName($"{prefix}: Tile source factory throws CannotFindTileSourceException."); - } - - private static MapDataCollection GetTestData() - { - var mapDataCollection = new MapDataCollection("Test data"); - - mapDataCollection.Add(new MapPointData("Test data") - { - Features = new[] - { - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(1.5, 2) - } - }), - new MapGeometry(new[] - { - new[] - { - new Point2D(1.1, 1) - } - }), - new MapGeometry(new[] - { - new[] - { - new Point2D(0.8, 0.5) - } - }) - }) - } - }); - - mapDataCollection.Add(new MapLineData("Test data") - { - Features = new[] - { - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(0.0, 1.1), - new Point2D(1.0, 2.1), - new Point2D(1.6, 1.6) - } - }) - }) - } - }); - - mapDataCollection.Add(new MapPolygonData("Test data") - { - Features = new[] - { - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(1.0, 1.3), - new Point2D(3.0, 2.6), - new Point2D(5.6, 1.6) - } - }) - }) - }, - IsVisible = false - }); - - return mapDataCollection; - } - - private static void ExtendWithExpectedMargin(Extent expectedExtent) - { - double smallestDimension = Math.Min(expectedExtent.Height, expectedExtent.Width); - expectedExtent.ExpandBy(smallestDimension * padding); - } - - private Extent GetExpectedExtent(FeatureBasedMapData visibleMapData) - { - double minX = double.MaxValue; - double maxX = double.MinValue; - double minY = double.MaxValue; - double maxY = double.MinValue; - - foreach (MapFeature feature in visibleMapData.Features) - { - foreach (MapGeometry geometry in feature.MapGeometries) - { - foreach (IEnumerable pointCollection in geometry.PointCollections) - { - foreach (Point2D point in pointCollection) - { - minX = Math.Min(minX, point.X); - maxX = Math.Max(maxX, point.X); - - minY = Math.Min(minY, point.Y); - maxY = Math.Max(maxY, point.Y); - } - } - } - } - - return new Extent(minX, minY, maxX, maxY); - } + #endregion } } \ No newline at end of file