public void InitalizingMapPresenterWithNonEmptyMapHasUndefinedView() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); map.AddLayer(DataSourceHelper.CreateFeatureFeatureLayer(_factories.GeoFactory)); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(1000, 1000); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); //Assert.Equal(map.Center[Ordinates.X], mapPresenter.GeoCenter[Ordinates.X]); //Assert.Equal(map.Center[Ordinates.Y], mapPresenter.GeoCenter[Ordinates.Y]); Assert.Equal(0, mapPresenter.WorldWidth); Assert.Equal(0, mapPresenter.WorldHeight); Assert.Equal(0, mapPresenter.WorldUnitsPerPixel); Assert.Equal(1, mapPresenter.WorldAspectRatio); Assert.Equal(0, mapPresenter.PixelWorldWidth); Assert.Equal(0, mapPresenter.PixelWorldHeight); Assert.Equal(null, mapPresenter.ToViewTransform); Assert.Equal(null, mapPresenter.ToWorldTransform); }
public void PanTest() { TestView2D view; //_factories.GeoFactory.CoordinateFactory.BitResolution = 24; TestPresenter2D mapPresenter = createPresenter(400, 800, out view); mapPresenter.ZoomToExtents(); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); Map map = mapPresenter.Map; map.ActiveTool = StandardMapView2DMapTools.Pan; /* * 1 * |*. * | `. 2 * | `* * | * |____________ * */ view.RaiseBegin(new Point2D(0, 0)); view.RaiseMoveTo(new Point2D(200, 400)); view.RaiseEnd(new Point2D(200, 400)); ICoordinate expected = _factories.GeoFactory.CoordinateFactory.Create(0, 170); Assert.Equal <ICoordinate>(expected, mapPresenter.GeoCenter, EpsilonComparer.Default); }
public void SetMaximumZoom_NegativeValue_ThrowException() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); Assert.Throws <ArgumentOutOfRangeException>(delegate { mapPresenter.MaximumWorldWidth = -1; }); }
public void DisposingPresenterMakesItDisposed() { TestView2D view; TestPresenter2D mapPresenter = createPresenter(1000, 1000, out view); Assert.Equal(false, mapPresenter.IsDisposed); mapPresenter.Dispose(); Assert.Equal(true, mapPresenter.IsDisposed); }
public void SetMinimumZoom_OKValue() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); mapPresenter.MinimumWorldWidth = 100.3; Assert.Equal(100.3, mapPresenter.MinimumWorldWidth); }
public void GetPixelSize_FixedZoom_Return8_75() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 500); mapPresenter.ZoomToWorldWidth(3500); Assert.Equal <Double>(8.75, mapPresenter.WorldUnitsPerPixel, EpsilonComparer.Default); }
public void DisposingPresenterRaisesDisposedEvent() { TestView2D view; TestPresenter2D mapPresenter = createPresenter(1000, 1000, out view); Boolean disposedCalled = false; mapPresenter.Disposed += delegate { disposedCalled = true; }; mapPresenter.Dispose(); Assert.Equal(true, disposedCalled); }
public void SetZoom_ValueBelowMin() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); mapPresenter.MinimumWorldWidth = 100; mapPresenter.ZoomToWorldWidth(50); Assert.Equal(100, mapPresenter.WorldWidth); }
public void GetWorldHeight_FixedZoom_Return1750() { MockRepository mocks = new MockRepository(); // create a presenter with a view having Width = 400 and Height = 200 TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); mapPresenter.ZoomToWorldWidth(3500); Assert.Equal <Double>(1750, mapPresenter.WorldHeight, EpsilonComparer.Default); }
public void ZoomToWorldBounds_NoAspectCorrection() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 1000, 1000); mapPresenter.ZoomToWorldBounds(_factories.GeoFactory.CreateExtents2D(20, 50, 100, 80)); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 65), mapPresenter.GeoCenter); Assert.Equal(80, mapPresenter.WorldWidth); }
public void ZoomToWorldBounds_WithAspectCorrection() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); mapPresenter.WorldAspectRatio = 2; mapPresenter.ZoomToWorldBounds(_factories.GeoFactory.CreateExtents2D(20, 10, 100, 180)); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 95), mapPresenter.GeoCenter); Assert.Equal(170, mapPresenter.WorldWidth); Assert.Equal(170, mapPresenter.WorldHeight); }
public void ZoomingToExtentsCentersMap() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 500); mapPresenter.ZoomToExtents(); Map map = mapPresenter.Map; Assert.Equal(map.Center[Ordinates.X], mapPresenter.GeoCenter[Ordinates.X]); Assert.Equal(map.Center[Ordinates.Y], mapPresenter.GeoCenter[Ordinates.Y]); }
public void ZoomToViewBoundsWhenNoWorldBoundsSetThrowsException() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 1000, 1000); Assert.Throws <InvalidOperationException>(delegate { mapPresenter.ZoomToViewBounds(new Rectangle2D(300, 300, 900, 900)); }); }
public void ViewEnvelopeMeasuresCorrectly() { TestView2D view; TestPresenter2D mapPresenter = createPresenter(120, 100, out view); mapPresenter.ZoomToExtents(); IExtents expected = _factories.GeoFactory.CreateExtents2D(0, 0, 120, 100); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); Assert.Equal(1, mapPresenter.WorldUnitsPerPixel); Assert.Equal(120, mapPresenter.WorldWidth); Assert.Equal(100, mapPresenter.WorldHeight); Assert.Equal(expected, mapPresenter.ViewEnvelope); }
public void ZoomToViewBounds_NoAspectCorrection() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 1000, 1000); mapPresenter.ZoomToExtents(); mapPresenter.ZoomToViewBounds(new Rectangle2D(300, 300, 900, 900)); BufferedCoordinate expectedCoord = (BufferedCoordinate)_factories.GeoFactory.CoordinateFactory.Create(72, 38); Assert.Equal(expectedCoord, mapPresenter.GeoCenter); Assert.Equal(72, mapPresenter.WorldWidth); Assert.Equal(72, mapPresenter.WorldHeight); }
private TestPresenter2D createPresenter(Double width, Double height, out TestView2D view) { Map map = new Map(_factories.GeoFactory); map.AddLayer(DataSourceHelper.CreateFeatureFeatureLayer(_factories.GeoFactory)); //map.AddLayer(DataSourceHelper.CreateGeometryFeatureLayer()); view = new TestView2D(map); view.ViewSize = new Size2D(width, height); TestPresenter2D mapPresenter = view.Presenter; return(mapPresenter); }
public void ViewToWorldTests() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 500, 200); mapPresenter.GeoCenter = _factories.GeoFactory.CoordinateFactory.Create(23, 34); mapPresenter.ZoomToWorldWidth(1000); ICoordinate p1 = mapPresenter.ToWorld(242.5f, 92); ICoordinate p2 = mapPresenter.ToWorld(new Point2D(242.5f, 92)); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(8, 50), p1); Assert.Equal(p1, p2); }
public void WorldToViewTests() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 1000, 1000); mapPresenter.GeoCenter = _factories.GeoFactory.CoordinateFactory.Create(23, 34); mapPresenter.ZoomToWorldWidth(2500); Point2D p1 = mapPresenter.ToView(8, 50); Point2D p2 = mapPresenter.ToView(_factories.GeoFactory.CoordinateFactory.Create(8, 50)); Assert.Equal(new Point2D(494, 493.6), p1); Assert.Equal(p1, p2); }
private TestPresenter2D createPresenter(MockRepository mocks, Double width, Double height) { Map map = new Map(_factories.GeoFactory); map.AddLayer(DataSourceHelper.CreateFeatureFeatureLayer(_factories.GeoFactory)); //map.AddLayer(DataSourceHelper.CreateGeometryFeatureLayer()); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(width, height); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); return(mapPresenter); }
public void ZoomWhenNoWorldBoundsThrowsException() { TestView2D view; TestPresenter2D mapPresenter = createPresenter(400, 500, out view); Map map = mapPresenter.Map; map.ActiveTool = StandardMapView2DMapTools.ZoomIn; Assert.Throws <InvalidOperationException>(delegate { view.RaiseBegin(new Point2D(100, 125)); }); //view.RaiseMoveTo(new Point2D(300, 375)); //view.RaiseEnd(new Point2D(300, 375)); }
public void GettingGeoCenterOnUndefinedViewFails() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); // Changed to null from Point.Empty Assert.Throws <InvalidOperationException>(delegate { Assert.Equal(null, mapPresenter.GeoCenter); }); }
public void ZoomToViewBounds_WithAspectCorrection() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); // Set the aspect ratio, which is the number of height units per width unit // to 2 height units to 1 width unit mapPresenter.WorldAspectRatio = 2; // Zooming to extents should mapPresenter.ZoomToExtents(); Assert.Equal(120, mapPresenter.WorldWidth); Assert.Equal(120, mapPresenter.WorldHeight); // Zoom to a 200x100 rectangle in view coordinates mapPresenter.ZoomToViewBounds(new Rectangle2D(100, 50, 300, 150)); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); Assert.Equal(60, mapPresenter.WorldWidth); Assert.Equal(60, mapPresenter.WorldHeight); }
public void GetMap_GeometryProvider_ReturnImage() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); Map map = mapPresenter.Map; GeometryLayer vLayer = new GeometryLayer("Geom layer", DataSourceHelper.CreateGeometryDatasource(_factories.GeoFactory)); vLayer.Style.Outline = new StylePen(StyleColor.Red, 2f); vLayer.Style.EnableOutline = true; vLayer.Style.Line = new StylePen(StyleColor.Green, 2f); vLayer.Style.Fill = new SolidStyleBrush(StyleColor.Yellow); map.AddLayer(vLayer); GeometryLayer vLayer2 = new GeometryLayer("Geom layer 2", vLayer.DataSource); Stream data = Assembly.GetAssembly(typeof(Map)) .GetManifestResourceStream("SharpMap.Styles.DefaultSymbol.png"); vLayer2.Style.Symbol = new Symbol2D(data, new Size2D(16, 16)); vLayer2.Style.Symbol.Offset = new Point2D(3, 4); vLayer2.Style.Symbol.Rotation = 45; vLayer2.Style.Symbol.Scale(0.4f); map.AddLayer(vLayer2); GeometryLayer vLayer3 = new GeometryLayer("Geom layer 3", vLayer.DataSource); vLayer3.Style.Symbol.Offset = new Point2D(3, 4); vLayer3.Style.Symbol.Rotation = 45; map.AddLayer(vLayer3); GeometryLayer vLayer4 = new GeometryLayer("Geom layer 4", vLayer.DataSource); vLayer4.Style.Symbol.Offset = new Point2D(3, 4); vLayer2.Style.Symbol.Scale(0.4f); map.AddLayer(vLayer4); mapPresenter.ZoomToExtents(); map.Dispose(); }
public void DisposingPresenterUnwiresAllEvents() { MockRepository mocks = new MockRepository(); TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200); Map map = mapPresenter.Map; mapPresenter.Dispose(); FieldInfo listChangedField = typeof(BindingList <ILayer>).GetField("onListChanged", BindingFlags.NonPublic | BindingFlags.Instance); Delegate listChanged = listChangedField.GetValue(map.Layers) as Delegate; Assert.NotNull(listChanged); Delegate[] listeners = listChanged.GetInvocationList(); // the only listener should be the map Assert.Equal(1, listeners.Length); Assert.Same(map, listeners[0].Target); }
public void ZoomingInFromViewCalculatesCorrectViewMetrics() { TestView2D view; TestPresenter2D mapPresenter = createPresenter(400, 500, out view); mapPresenter.ZoomToExtents(); Assert.Equal(120, mapPresenter.WorldWidth); Assert.Equal(150, mapPresenter.WorldHeight); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); Map map = mapPresenter.Map; map.ActiveTool = new MapTool <IMapView2D, Point2D>("TestZoomIn", nullAction, testBeginZoomIn, testContinueZoomIn, testEndZoomIn); // Zoom using click view.RaiseBegin(new Point2D(200, 250)); view.RaiseMoveTo(new Point2D(200, 250)); view.RaiseEnd(new Point2D(200, 250)); Assert.Equal(100, mapPresenter.WorldWidth); Assert.Equal(125, mapPresenter.WorldHeight); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); mapPresenter.ZoomToExtents(); Assert.Equal(120, mapPresenter.WorldWidth); Assert.Equal(150, mapPresenter.WorldHeight); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); // Zoom using selection view.RaiseBegin(new Point2D(100, 125)); view.RaiseMoveTo(new Point2D(300, 375)); view.RaiseEnd(new Point2D(300, 375)); Assert.Equal(60, mapPresenter.WorldWidth); Assert.Equal(75, mapPresenter.WorldHeight); Assert.Equal(_factories.GeoFactory.CoordinateFactory.Create(60, 50), mapPresenter.GeoCenter); }
public void TransformingPointFromWorldToViewOnUndefinedViewFails() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); Assert.Throws <InvalidOperationException>(delegate { Assert.Equal(Point2D.Empty, mapPresenter.ToView( _factories.GeoFactory.CoordinateFactory. Create(50, 50))); }); }
public void InitalizingMapPresenterWithEmptyMapHasUndefinedView() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); Assert.Equal(0, mapPresenter.WorldWidth); Assert.Equal(0, mapPresenter.WorldHeight); Assert.Equal(0, mapPresenter.WorldUnitsPerPixel); Assert.Equal(1, mapPresenter.WorldAspectRatio); Assert.Equal(0, mapPresenter.PixelWorldWidth); Assert.Equal(0, mapPresenter.PixelWorldHeight); Assert.Equal(null, mapPresenter.ToViewTransform); Assert.Equal(null, mapPresenter.ToWorldTransform); }
public TestView2D(Map map) { _presenter = new TestPresenter2D(map, this); }