Index: Core/Components/src/Core.Components.DotSpatial/MapFunctions/MapFunctionPan.cs =================================================================== diff -u -r30b12b82918d500fe834eafd9f6cd9b2c5dbe60f -rccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a --- Core/Components/src/Core.Components.DotSpatial/MapFunctions/MapFunctionPan.cs (.../MapFunctionPan.cs) (revision 30b12b82918d500fe834eafd9f6cd9b2c5dbe60f) +++ Core/Components/src/Core.Components.DotSpatial/MapFunctions/MapFunctionPan.cs (.../MapFunctionPan.cs) (revision ccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a) @@ -21,13 +21,12 @@ using System; using System.Windows.Forms; - using DotSpatial.Controls; namespace Core.Components.DotSpatial.MapFunctions { /// - /// that handles events to update . + /// A that can pan the map and handles events to update . /// public class MapFunctionPan : global::DotSpatial.Controls.MapFunctionPan { Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj =================================================================== diff -u -r30b12b82918d500fe834eafd9f6cd9b2c5dbe60f -rccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 30b12b82918d500fe834eafd9f6cd9b2c5dbe60f) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision ccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a) @@ -85,6 +85,10 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + True + Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/packages.config =================================================================== diff -u -rae34e25064174cb82307bbd514ef3d37bf49586b -rccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/packages.config (.../packages.config) (revision ae34e25064174cb82307bbd514ef3d37bf49586b) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/packages.config (.../packages.config) (revision ccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a) @@ -13,4 +13,5 @@ + \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Test/MapFunctions/MapFunctionSelectionZoomTest.cs =================================================================== diff -u -rc13e35419454e2ca1b1a252b31da36abecf652d4 -rccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a --- Core/Components/test/Core.Components.DotSpatial.Test/MapFunctions/MapFunctionSelectionZoomTest.cs (.../MapFunctionSelectionZoomTest.cs) (revision c13e35419454e2ca1b1a252b31da36abecf652d4) +++ Core/Components/test/Core.Components.DotSpatial.Test/MapFunctions/MapFunctionSelectionZoomTest.cs (.../MapFunctionSelectionZoomTest.cs) (revision ccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a) @@ -23,25 +23,32 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; - using Core.Components.DotSpatial.MapFunctions; - using DotSpatial.Controls; +using DotSpatial.Data; using DotSpatial.Symbology; +using DotSpatial.Topology; using NUnit.Framework; - using Rhino.Mocks; +using Point = System.Drawing.Point; namespace Core.Components.DotSpatial.Test.MapFunctions { [TestFixture] public class MapFunctionSelectionZoomTest { + private MockRepository mockingRepository; + + [SetUp] + public void SetUp() + { + mockingRepository = new MockRepository(); + } + [Test] public void Constructor_Always_ExpectedValues() { // Setup - var mockingRepository = new MockRepository(); var mapMock = mockingRepository.StrictMock(); mockingRepository.ReplayAll(); @@ -57,7 +64,6 @@ public void Constructor_ActivateEvent_ExpectedValues() { // Setup - var mockingRepository = new MockRepository(); var mapMock = mockingRepository.StrictMock(); mapMock.Expect(m => m.Cursor).SetPropertyWithArgument(Cursors.Default); mockingRepository.ReplayAll(); @@ -75,7 +81,6 @@ public void OnMouseDown_Always_SetsCursorToHand() { // Setup - var mockingRepository = new MockRepository(); var mapMock = mockingRepository.Stub(); mapMock.MapFrame = mockingRepository.Stub(); mockingRepository.ReplayAll(); @@ -88,25 +93,139 @@ // Assert Assert.IsTrue(mapMock.IsBusy); - Assert.AreEqual(Cursors.SizeNWSE,mapMock.Cursor); + Assert.AreEqual(Cursors.SizeNWSE, mapMock.Cursor); mockingRepository.VerifyAll(); } [Test] + [TestCase(0, 0, 100, 50)] + [TestCase(-50, -50, 10, 50)] + [TestCase(50, 50, -100, -50)] + public void OnMouseMove_Dragging_DrawNewRectangle(int startPointX, int startPointY, int endPointX, int endPointY) + { + // Setup + int x = Math.Min(Math.Min(startPointX, 0), endPointX); + int y = Math.Min(Math.Min(startPointY, 0), endPointY); + int mx = Math.Max(Math.Max(startPointX, 0), endPointX); + int my = Math.Max(Math.Max(startPointY, 0), endPointY); + var expectedRectangle = new Rectangle(x, y, mx - x, my - y); + + var mapMock = mockingRepository.Stub(); + mapMock.Expect(e => e.PixelToProj(Arg.Is(new Point(startPointX, startPointY)))).Return(null); + mapMock.Expect(e => e.PixelToProj(Arg.Is(new Point(endPointX, endPointY)))).Return(null); + mapMock.Expect(e => e.Invalidate(Arg.Matches(m => m.Equals(expectedRectangle)))); + mockingRepository.ReplayAll(); + + var mapFunction = new MapFunctionSelectionZoom(mapMock); + mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), mapMock)); + + // Call + mapFunction.DoMouseMove(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 0, endPointX, endPointY, 0), mapMock)); + + // Assert + Assert.IsTrue(mapMock.IsBusy); + Assert.AreEqual(Cursors.SizeNWSE, mapMock.Cursor); + mockingRepository.VerifyAll(); + } + + [Test] + public void OnMouseDown_NotZoomedSameLocation_DoesNotZoom() + { + // Setup + var mapMock = mockingRepository.Stub(); + mockingRepository.ReplayAll(); + + int startPointX = 0; + int startPointY = 0; + var mapFunction = new MapFunctionSelectionZoom(mapMock); + mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), mapMock)); + + // Call + mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 0, startPointX, startPointY, 0), mapMock)); + + // Assert + Assert.IsNull(mapMock.ViewExtents); + Assert.IsFalse(mapMock.IsBusy); + Assert.AreEqual(Cursors.Default, mapMock.Cursor); + mockingRepository.VerifyAll(); + } + + [Test] + [TestCase(0, 0, 100, 50)] + [TestCase(-50, -50, 10, 50)] + [TestCase(50, 50, -100, -50)] + public void OnMouseUp_DraggingToOtherLocation_ZoomsToCoordinates(int startPointX, int startPointY, int endPointX, int endPointY) + { + // Setup + double geoStartPointX = 0.0 + startPointX; + double geoStartPointY = 0.0 + startPointY; + double geoEndPointX = 0.0 + endPointX; + double geoEndPointY = 0.0 + endPointY; + + var mapMock = mockingRepository.Stub(); + mapMock.Expect(e => e.PixelToProj(Arg.Is(new Point(startPointX, startPointY)))).Return(new Coordinate(geoStartPointX, geoStartPointY)); + mapMock.Expect(e => e.PixelToProj(Arg.Is(new Point(endPointX, endPointY)))).Return(new Coordinate(geoEndPointX, geoEndPointY)); + mapMock.Expect(e => e.Invalidate()); + mockingRepository.ReplayAll(); + + Extent expectedExtend = new Envelope(geoStartPointX, geoEndPointX, geoStartPointY, geoEndPointY).ToExtent(); + + var mapFunction = new MapFunctionSelectionZoom(mapMock); + mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), mapMock)); + + // Call + mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, endPointX, endPointY, 0), mapMock)); + + // Assert + Assert.AreEqual(expectedExtend, mapMock.ViewExtents); + Assert.IsFalse(mapMock.IsBusy); + Assert.AreEqual(Cursors.Default, mapMock.Cursor); + mockingRepository.VerifyAll(); + } + + [Test] + [TestCase(0, 0)] + [TestCase(10, 10)] + public void OnMouseUp_NotDragging_ResetExtents(int startPointX, int startPointY) + { + // Setup + var mapMock = mockingRepository.Stub(); + var mapFrame = mockingRepository.Stub(); + mapMock.MapFrame = mapFrame; + + double geoStartPointX = 0.0 + startPointX; + double geoStartPointY = 0.0 + startPointY; + + mapMock.Expect(e => e.PixelToProj(Arg.Is(new Point(startPointX, startPointY)))).Return(new Coordinate(geoStartPointX, geoStartPointY)); + mapMock.Expect(e => e.Invalidate()); + mapFrame.Expect(e => e.ResetExtents()); + mockingRepository.ReplayAll(); + + var mapFunction = new MapFunctionSelectionZoom(mapMock); + + // Call + mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), mapMock)); + + // Assert + Assert.IsFalse(mapMock.IsBusy); + Assert.AreEqual(Cursors.Default, mapMock.Cursor); + mockingRepository.VerifyAll(); + } + + [Test] public void OnDraw_NotDragging_NoDrawing() { // Setup - var mockingRepository = new MockRepository(); var mapMock = mockingRepository.Stub(); var mapFrame = mockingRepository.Stub(); var inGraphics = mockingRepository.Stub(); - inGraphics.Expect(e => e.DrawRectangle(null, 0,0,0,0)).IgnoreArguments().Repeat.Never(); + inGraphics.Expect(e => e.DrawRectangle(null, 0, 0, 0, 0)).IgnoreArguments().Repeat.Never(); mockingRepository.ReplayAll(); mapMock.Cursor = Cursors.Cross; var mapFunction = new MapFunctionSelectionZoom(mapMock); - var clipRectangle = new Rectangle(0,0,0,0); + var clipRectangle = new Rectangle(0, 0, 0, 0); // Call mapFunction.Draw(new MapDrawArgs(inGraphics, clipRectangle, mapFrame)); @@ -126,7 +245,6 @@ rectangleFromPoints.Width -= 1; rectangleFromPoints.Height -= 1; - var mockingRepository = new MockRepository(); var mapMock = mockingRepository.Stub(); var mapFrame = mockingRepository.Stub(); var inGraphics = mockingRepository.Stub(); Index: Core/Components/test/Core.Components.DotSpatial.Test/MouseCoordinatesMapExtensionTest.cs =================================================================== diff -u -ra793fc9845a2b861d885170d22cd2353a7146403 -rccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a --- Core/Components/test/Core.Components.DotSpatial.Test/MouseCoordinatesMapExtensionTest.cs (.../MouseCoordinatesMapExtensionTest.cs) (revision a793fc9845a2b861d885170d22cd2353a7146403) +++ Core/Components/test/Core.Components.DotSpatial.Test/MouseCoordinatesMapExtensionTest.cs (.../MouseCoordinatesMapExtensionTest.cs) (revision ccfc7c8e0f80ebd556d1aa0bc13cf36572051c8a) @@ -58,14 +58,15 @@ { // Setup using (var map = new Map()) - using (var extension = new MouseCoordinatesMapExtension(map)) { + using (var extension = new MouseCoordinatesMapExtension(map)) + { + // Call + extension.Activate(); - // Call - extension.Activate(); - - // Assert - Assert.AreEqual(1, map.Controls.Count); + // Assert + Assert.AreEqual(1, map.Controls.Count); + } } } @@ -74,18 +75,20 @@ { // Setup using (var map = new Map()) - using (var extension = new MouseCoordinatesMapExtension(map)) { - extension.Activate(); + using (var extension = new MouseCoordinatesMapExtension(map)) + { + extension.Activate(); - // Precondition - Assert.AreEqual(1, map.Controls.Count); + // Precondition + Assert.AreEqual(1, map.Controls.Count); - // Call - extension.Deactivate(); + // Call + extension.Deactivate(); - // Assert - Assert.AreEqual(0, map.Controls.Count); + // Assert + Assert.AreEqual(0, map.Controls.Count); + } } } }