Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -rf75bf6c108f023b3f8c020cf51e0686d500bb342 -r0b17763d8c51949424fade278f2d52fe804cda52 --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision f75bf6c108f023b3f8c020cf51e0686d500bb342) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 0b17763d8c51949424fade278f2d52fe804cda52) @@ -119,20 +119,19 @@ private void RegisterTreeNodeInfos() { - treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo + treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = context => context.WrappedData.Name, Image = GetImage, - ChildNodeObjects = MapDataContextGetChildNodeObjects, - CanDrag = (context, o) => true, - CanCheck = context => !(context.WrappedData is MapDataCollection), + CanDrag = (context, parent) => true, + CanCheck = context => true, IsChecked = context => context.WrappedData.IsVisible, - OnNodeChecked = MapDataContextOnNodeChecked, - CanDrop = MapDataContextCanDropAndInsert, - CanInsert = MapDataContextCanDropAndInsert, - OnDrop = MapDataContextOnDrop, - CanRemove = (context, parent) => CanRemoveMapData(context.WrappedData, parent), - OnNodeRemoved = (context, parent) => RemoveFromParent(context.WrappedData, parent), + OnNodeChecked = FeatureBasedMapDataContextOnNodeChecked, + CanDrop = FeatureBasedMapDataContextCanDropAndInsert, + CanInsert = FeatureBasedMapDataContextCanDropAndInsert, + OnDrop = FeatureBasedMapDataContextOnDrop, + CanRemove = (context, parent) => CanRemoveMapData((FeatureBasedMapData) context.WrappedData, parent), + OnNodeRemoved = (context, parent) => RemoveFromParent((FeatureBasedMapData) context.WrappedData, parent), ContextMenuStrip = MapDataContextContextMenuStrip }); @@ -166,25 +165,6 @@ #region MapData - private StrictContextMenuItem CreateZoomToExtentsItem(MapData nodeData) - { - StrictContextMenuItem zoomToExtentsItem = null; - - var collectionNodeData = nodeData as MapDataCollection; - if (collectionNodeData != null) - { - zoomToExtentsItem = CreateZoomToExtentsItem(collectionNodeData); - } - - var featureBasedNodeData = nodeData as FeatureBasedMapData; - if (featureBasedNodeData != null) - { - zoomToExtentsItem = CreateZoomToExtentsItem(featureBasedNodeData); - } - - return zoomToExtentsItem; - } - private StrictContextMenuItem CreateZoomToExtentsItem(FeatureBasedMapData nodeData) { bool hasFeatures = nodeData.Features.Any(); @@ -257,7 +237,7 @@ #region MapDataContext - private static Image GetImage(MapDataContext context) + private static Image GetImage(FeatureBasedMapDataContext context) { if (context.WrappedData is MapPointData) { @@ -277,45 +257,39 @@ return GuiResources.folder; } - private static object[] MapDataContextGetChildNodeObjects(MapDataContext mapDataContext) + private void FeatureBasedMapDataContextOnNodeChecked(FeatureBasedMapDataContext mapDataContext, object parentData) { - var collection = mapDataContext.WrappedData as MapDataCollection; - return collection != null ? GetChildNodeObjects(collection) : new object[0]; - } - - private void MapDataContextOnNodeChecked(MapDataContext mapDataContext, object parentData) - { mapDataContext.WrappedData.IsVisible = !mapDataContext.WrappedData.IsVisible; NotifyObserversOfData(mapDataContext.WrappedData); } - private static bool MapDataContextCanDropAndInsert(object draggedData, object targetData) + private static bool FeatureBasedMapDataContextCanDropAndInsert(object draggedData, object targetData) { - var draggedDataContext = (MapDataContext) draggedData; + var draggedDataContext = (FeatureBasedMapDataContext) draggedData; var targetDataContext = (MapDataContext) targetData; return draggedDataContext.ParentMapData.Equals(targetDataContext.WrappedData); } - private static void MapDataContextOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) + private static void FeatureBasedMapDataContextOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) { - var mapContext = (MapDataContext) droppedData; - var sourceContext = oldParentData as MapDataContext; + var mapContext = (FeatureBasedMapDataContext) droppedData; + var sourceContext = oldParentData as MapDataCollectionContext; - MapData mapData = mapContext.WrappedData; + var mapData = (FeatureBasedMapData) mapContext.WrappedData; var parent = (MapDataCollection) (sourceContext != null ? sourceContext.WrappedData : oldParentData); parent.Remove(mapData); parent.Insert(parent.Collection.Count() - position, mapData); parent.NotifyObservers(); } - private static bool CanRemoveMapData(MapData mapData, object parent) + private static bool CanRemoveMapData(FeatureBasedMapData mapData, object parent) { return mapData is IRemovable && parent is MapDataCollection; } - private static void RemoveFromParent(MapData dataToRemove, object parentData) + private static void RemoveFromParent(FeatureBasedMapData dataToRemove, object parentData) { if (CanRemoveMapData(dataToRemove, parentData)) { @@ -325,16 +299,10 @@ } } - private ContextMenuStrip MapDataContextContextMenuStrip(MapDataContext mapDataContext, object parentData, TreeViewControl treeView) + private ContextMenuStrip MapDataContextContextMenuStrip(FeatureBasedMapDataContext mapDataContext, object parentData, TreeViewControl treeView) { - var mapDataCollection = mapDataContext.WrappedData as MapDataCollection; - if (mapDataCollection != null) - { - return MapDataCollectionContextMenuStrip(mapDataCollection, parentData, treeView); - } - return contextMenuBuilderProvider.Get(mapDataContext.WrappedData, treeView) - .AddCustomItem(CreateZoomToExtentsItem(mapDataContext.WrappedData)) + .AddCustomItem(CreateZoomToExtentsItem((FeatureBasedMapData) mapDataContext.WrappedData)) .AddSeparator() .AddDeleteItem() .AddSeparator() Index: Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj =================================================================== diff -u -r405db3b688bdee707426a1bc0a44c3be3a3dc563 -r0b17763d8c51949424fade278f2d52fe804cda52 --- Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision 405db3b688bdee707426a1bc0a44c3be3a3dc563) +++ Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision 0b17763d8c51949424fade278f2d52fe804cda52) @@ -49,7 +49,7 @@ - + Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs (revision 0b17763d8c51949424fade278f2d52fe804cda52) @@ -0,0 +1,639 @@ +// Copyright (C) Stichting Deltares 2018. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using Core.Common.Util.Reflection; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.TestUtil; +using Core.Plugins.Map.Legend; +using Core.Plugins.Map.PresentationObjects; +using Core.Plugins.Map.Properties; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Plugins.Map.Test.Legend +{ + [TestFixture] + public class FeatureBasedMapDataContextTreeNodeInfoTest + { + private const int mapDataContextMenuZoomToAllIndex = 0; + + private MapLegendView mapLegendView; + private TreeNodeInfo info; + private MockRepository mocks; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + + private static IEnumerable MapDataLegendImages + { + get + { + yield return new TestCaseData(new MapPointData("test"), Resources.PointsIcon); + yield return new TestCaseData(new MapLineData("test"), Resources.LineIcon); + yield return new TestCaseData(new MapPolygonData("test"), Resources.AreaIcon); + } + } + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + + info = treeNodeInfoLookup[typeof(FeatureBasedMapDataContext)]; + } + + [TearDown] + public void TearDown() + { + mapLegendView.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.IsNotNull(info.Text); + Assert.IsNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ExpandOnCreate); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanCheck); + Assert.IsNotNull(info.IsChecked); + Assert.IsNotNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNotNull(info.CanDrop); + Assert.IsNotNull(info.CanInsert); + Assert.IsNotNull(info.OnDrop); + } + + [Test] + public void Text_WithContext_ReturnsNameFromWrappedMapData() + { + // Setup + FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData()); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual(context.WrappedData.Name, text); + } + + [Test] + [TestCaseSource(nameof(MapDataLegendImages))] + public void Image_WithContext_ReturnExpectedImage(FeatureBasedMapData mapData, Image expectedImage) + { + // Setup + FeatureBasedMapDataContext context = GetContext(mapData); + + // Call + Image image = info.Image(context); + + // Assert + TestHelper.AssertImagesAreEqual(expectedImage, image); + } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Call + bool canDrag = info.CanDrag(null, null); + + // Assert + Assert.IsTrue(canDrag); + } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Call + bool canCheck = info.CanCheck(null); + + // Assert + Assert.IsTrue(canCheck); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void IsChecked_WithContext_ReturnsAccordingToVisibleStateOfMapData(bool isVisible) + { + // Setup + FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData()); + context.WrappedData.IsVisible = isVisible; + + // Call + bool isChecked = info.IsChecked(context); + + // Assert + Assert.AreEqual(isVisible, isChecked); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_WithContext_SetsMapDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FeatureBasedMapDataContext context = GetContext(new TestFeatureBasedMapData()); + context.WrappedData.IsVisible = initialVisibleState; + + context.WrappedData.Attach(observer); + + // Call + info.OnNodeChecked(context, null); + + // Assert + Assert.AreEqual(!initialVisibleState, context.WrappedData.IsVisible); + mocks.VerifyAll(); + } + + [Test] + public void CanDrop_TargetIsSameAsSourceParent_ReturnsTrue() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + var mapDataCollection = new MapDataCollection("test"); + + FeatureBasedMapDataContext context = GetContext(mapData, mapDataCollection); + MapDataCollectionContext targetContext = GetContext(mapDataCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsTrue(canDrop); + } + + [Test] + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + FeatureBasedMapData mapData2 = new TestFeatureBasedMapData(); + + FeatureBasedMapDataContext context = GetContext(mapData); + FeatureBasedMapDataContext targetContext = GetContext(mapData2); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanDrop_TargetDataIsCollectionWithSameParent_ReturnsFalse() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + var rootCollection = new MapDataCollection("test"); + var targetCollection = new MapDataCollection("test"); + + FeatureBasedMapDataContext context = GetContext(mapData, rootCollection); + MapDataCollectionContext targetContext = GetContext(targetCollection, rootCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanInsert_TargetIsSameAsSourceParent_ReturnsTrue() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + var mapDataCollection = new MapDataCollection("test"); + + FeatureBasedMapDataContext context = GetContext(mapData, mapDataCollection); + MapDataCollectionContext targetContext = GetContext(mapDataCollection); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + FeatureBasedMapData mapData2 = new TestFeatureBasedMapData(); + + FeatureBasedMapDataContext context = GetContext(mapData); + FeatureBasedMapDataContext targetContext = GetContext(mapData2); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + public void CanInsert_TargetDataIsCollectionWithSameParent_ReturnsFalse() + { + // Setup + FeatureBasedMapData mapData = new TestFeatureBasedMapData(); + var rootCollection = new MapDataCollection("test"); + var targetCollection = new MapDataCollection("test"); + + FeatureBasedMapDataContext context = GetContext(mapData, rootCollection); + MapDataCollectionContext targetContext = GetContext(targetCollection, rootCollection); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_MapDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var mapData1 = new TestFeatureBasedMapData(); + var mapData2 = new TestFeatureBasedMapData(); + var mapData3 = new TestFeatureBasedMapData(); + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(mapData3); + + FeatureBasedMapDataContext context1 = GetContext(mapData1); + MapDataCollectionContext collectionContext = GetContext(mapDataCollection); + + mapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + info.OnDrop(context1, collectionContext, collectionContext, position, treeViewControl); + + // Assert + int reversedIndex = 2 - position; + var wrappedCollectionData = (MapDataCollection) collectionContext.WrappedData; + Assert.AreSame(context1.WrappedData, wrappedCollectionData.Collection.ElementAt(reversedIndex)); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(5)] + [TestCase(50)] + public void OnDrop_MapDataMovedToPositionOutsideRange_ThrowsException(int position) + { + // Setup + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var mapData1 = new TestFeatureBasedMapData(); + var mapData2 = new TestFeatureBasedMapData(); + var mapData3 = new TestFeatureBasedMapData(); + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(mapData3); + + mapDataCollection.Attach(observer); +// mapLegendView.Data = mapDataCollection; + + FeatureBasedMapDataContext context = GetContext(mapData1); + MapDataCollectionContext collectionContext = GetContext(mapDataCollection); + + mapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + TestDelegate test = () => info.OnDrop(context, collectionContext, collectionContext, position, treeViewControl); + + // Assert + Assert.Throws(test); + + mocks.VerifyAll(); // Expect no update observer. + } + } + + [Test] + public void CanRemove_WithRemovableDataAndCollection_ReturnTrue() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + FeatureBasedMapDataContext context = GetContext(removable); + + // Call + bool canRemove = info.CanRemove(context, context.ParentMapData); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void CanRemove_WithoutCollection_ReturnFalse() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + FeatureBasedMapDataContext context = GetContext(removable); + + // Call + bool canRemove = info.CanRemove(context, null); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void CanRemove_WithNotRemovableData_ReturnFalse() + { + // Setup + var notRemovable = mocks.StrictMock("name"); + mocks.ReplayAll(); + + FeatureBasedMapDataContext context = GetContext(notRemovable); + + // Call + bool canRemove = info.CanRemove(context, context.ParentMapData); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void OnNodeRemoved_WithRemovableDataToRemove_DataRemoved() + { + // Setup + var toRemove = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + var otherData = mocks.Stub("name"); + mocks.ReplayAll(); + + var collection = new MapDataCollection("collection"); + collection.Add(toRemove); + collection.Add(otherData); + + FeatureBasedMapDataContext context = GetContext(toRemove, collection); + + // Call + info.OnNodeRemoved(context, context.ParentMapData); + + // Assert + CollectionAssert.AreEqual(new[] + { + otherData + }, collection.Collection); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var mapData = new TestFeatureBasedMapData(); + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddDeleteItem()).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + + contextMenuBuilderProvider.Expect(p => p.Get(mapData, null)).Return(builder); + + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(GetContext(mapData), null, null); + + // Assert + // Assert expectancies are called in TearDown() + } + + [Test] + public void ContextMenuStrip_VisibleMapDataWithFeatures_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, mapDataContextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat deze kaartlaag precies in het beeld past.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData + { + IsVisible = false + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, mapDataContextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de kaartlaag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_VisibleMapDataWithoutFeatures_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData + { + IsVisible = true + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, mapDataContextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de kaartlaag elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var mapData = new TestFeatureBasedMapData() + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(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(GetContext(mapData), null, null)) + { + // Call + contextMenu.Items[mapDataContextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_NoMapControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[mapDataContextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + private static FeatureBasedMapDataContext GetContext(FeatureBasedMapData mapData, MapDataCollection mapDataCollection = null) + { + return new FeatureBasedMapDataContext(mapData, mapDataCollection ?? new MapDataCollection("test")); + } + private static MapDataCollectionContext GetContext(MapDataCollection mapDataCollection, MapDataCollection parentMapDataCollection = null) + { + return new MapDataCollectionContext(mapDataCollection, parentMapDataCollection ?? new MapDataCollection("test")); + } + } +} \ No newline at end of file Fisheye: Tag 0b17763d8c51949424fade278f2d52fe804cda52 refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataContextTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?