Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -23,18 +23,23 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; +using Core.Components.Charting.Forms; using Core.Components.Charting.TestUtil; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.PresentationObjects; using NUnit.Framework; using Rhino.Mocks; using GuiResources = Core.Common.Gui.Properties.Resources; +using ChartResources = Core.Plugins.Chart.Properties.Resources; namespace Core.Plugins.Chart.Test.Legend { @@ -43,13 +48,16 @@ { private ChartLegendView chartLegendView; private TreeNodeInfo info; + private IContextMenuBuilderProvider contextMenuBuilderProvider; private MockRepository mocks; + private const int contextMenuZoomToAllIndex = 0; + [SetUp] public void SetUp() { mocks = new MockRepository(); - var contextMenuBuilderProvider = mocks.Stub(); + contextMenuBuilderProvider = mocks.Stub(); mocks.ReplayAll(); chartLegendView = new ChartLegendView(contextMenuBuilderProvider); @@ -224,7 +232,6 @@ public void OnDrop_ChartDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) { // Setup - var mocks = new MockRepository(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); @@ -263,7 +270,6 @@ public void OnDrop_ChartDataMovedToPositionOutsideRange_ThrowsException(int position) { // Setup - var mocks = new MockRepository(); var observer = mocks.StrictMock(); mocks.ReplayAll(); @@ -297,6 +303,162 @@ } } + [Test] + public void ContextMenuStrip_InvisibleFeatureBasedMapDataInChartDataCollection_ZoomToAllDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var pointData = new ChartPointData("test data") + { + IsVisible = false + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(pointData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + Assert.AreEqual(1, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn.", + ChartResources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_VisibleFeatureBasedMapDataWithoutFeaturesInChartDataCollection_ZoomToAllDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var lineData = new ChartLineData("test line") + { + IsVisible = false, + Points = new[] + { + new Point2D(1, 5) + } + }; + var pointData = new ChartPointData("test data") + { + IsVisible = true + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(pointData); + chartDataCollection.Add(lineData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + Assert.AreEqual(1, contextMenu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten.", + ChartResources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_ChartDataCollectionWithVisibleFeatureBasedmapData_ZoomToAllEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var mapPointData = new ChartPointData("test") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1), + } + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(mapPointData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + Assert.AreEqual(1, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen.", + ChartResources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var lineData = new ChartLineData("test line") + { + IsVisible = true, + Points = new[] + { + new Point2D(1, 5) + } + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(lineData); + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var chartControl = mocks.StrictMock(); + chartControl.Expect(c => c.Data).Return(new ChartDataCollection("name")); + chartControl.Expect(c => c.ZoomToAllVisibleLayers(chartDataCollection)); + + mocks.ReplayAll(); + + chartLegendView.ChartControl = chartControl; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_DisabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var lineData = new ChartLineData("test line"); + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(lineData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + private static ChartDataContext GetContext(ChartData chartData, ChartDataCollection chartDataCollection = null) { return new ChartDataContext(chartData, chartDataCollection ?? new ChartDataCollection("test")); Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs =================================================================== diff -u -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -32,6 +32,7 @@ using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; +using Core.Components.Charting.Forms; using Core.Components.Charting.TestUtil; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.PresentationObjects; @@ -505,6 +506,7 @@ mocks.VerifyAll(); // Expect no update observer. } } + [Test] [TestCaseSource(nameof(NoChartDataCollection))] public void ContextMenuStrip_DifferentTypesOfChartData_CallsBuilder(ChartData chartData) @@ -536,7 +538,7 @@ mocks.ReplayAll(); - var mapData = new ChartLineData("A") + var lineData = new ChartLineData("A") { IsVisible = true, Points = new[] @@ -546,7 +548,7 @@ }; // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, @@ -565,13 +567,13 @@ mocks.ReplayAll(); - var mapData = new ChartLineData("A") + var lineData = new ChartLineData("A") { IsVisible = false }; // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, @@ -591,13 +593,13 @@ mocks.ReplayAll(); - var mapData = new ChartLineData("A") + var lineData = new ChartLineData("A") { IsVisible = true }; // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, @@ -608,6 +610,65 @@ } } + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var lineData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var chartControl = mocks.StrictMock(); + chartControl.Expect(c => c.Data).Return(new ChartDataCollection("name")); + chartControl.Expect(c => c.ZoomToAllVisibleLayers(lineData)); + mocks.ReplayAll(); + + chartLegendView.ChartControl = chartControl; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var lineData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + private static ChartDataContext GetContext(ChartData chartData, ChartDataCollection chartDataCollection = null) { return new ChartDataContext(chartData, chartDataCollection ?? new ChartDataCollection("test")); Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -33,6 +33,7 @@ using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; @@ -362,7 +363,6 @@ using (var treeViewControl = new TreeViewControl()) { - // Call var builder = new ContextMenuBuilder(applicationFeatureCommandsStub, importCommandHandlerMock, exportCommandHandlerMock, @@ -435,7 +435,6 @@ using (var treeViewControl = new TreeViewControl()) { - // Call var builder = new ContextMenuBuilder(applicationFeatureCommandsStub, importCommandHandlerMock, exportCommandHandlerMock, @@ -480,7 +479,7 @@ } [Test] - public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() { // Setup var mapData = new MapDataCollection("A"); @@ -496,9 +495,13 @@ var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); - + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); mocks.ReplayAll(); + mapLegendView.MapControl = mapControl; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapData, null, null)) { // Call @@ -510,16 +513,13 @@ } [Test] - public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() { // Setup var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); - mocks.ReplayAll(); - mapLegendView.MapControl = null; - var mapData = new MapDataCollection("A") { IsVisible = true Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -32,6 +32,7 @@ using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; @@ -233,7 +234,7 @@ } [Test] - public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() { // Setup var mapData = new MapLineData("A") @@ -247,9 +248,13 @@ var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); - + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); mocks.ReplayAll(); + mapLegendView.MapControl = mapControl; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapData, null, null)) { // Call @@ -261,16 +266,14 @@ } [Test] - public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() { // Setup var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); mocks.ReplayAll(); - mapLegendView.MapControl = null; - var mapData = new MapLineData("A") { IsVisible = true Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -32,6 +32,7 @@ using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; @@ -233,7 +234,7 @@ } [Test] - public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() { // Setup var mapData = new MapPointData("A") @@ -247,9 +248,13 @@ var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); - + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); mocks.ReplayAll(); + mapLegendView.MapControl = mapControl; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapData, null, null)) { // Call @@ -261,16 +266,14 @@ } [Test] - public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() { // Setup var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); mocks.ReplayAll(); - mapLegendView.MapControl = null; - var mapData = new MapPointData("A") { IsVisible = true Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) @@ -32,6 +32,7 @@ using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; @@ -233,7 +234,7 @@ } [Test] - public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() { // Setup var mapData = new MapPolygonData("A") @@ -247,9 +248,13 @@ var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); - + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); mocks.ReplayAll(); + mapLegendView.MapControl = mapControl; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapData, null, null)) { // Call @@ -261,16 +266,14 @@ } [Test] - public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() { // Setup var builder = new CustomItemsOnlyContextMenuBuilder(); contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); mocks.ReplayAll(); - mapLegendView.MapControl = null; - var mapData = new MapPolygonData("A") { IsVisible = true