Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -r0b17763d8c51949424fade278f2d52fe804cda52 -r842679c47f28f5f6349a2a34a96fc93adb094e51 --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 0b17763d8c51949424fade278f2d52fe804cda52) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 842679c47f28f5f6349a2a34a96fc93adb094e51) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -135,10 +136,10 @@ ContextMenuStrip = MapDataContextContextMenuStrip }); - treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo + treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { - Text = mapDataCollection => mapDataCollection.Name, - Image = mapDataCollection => GuiResources.folder, + Text = context => context.WrappedData.Name, + Image = context => GuiResources.folder, ChildNodeObjects = GetCollectionChildNodeObjects, CanDrag = (collection, parentData) => true, CanDrop = MapDataCollectionCanDropAndInsert, @@ -148,19 +149,21 @@ }); } - private static object[] GetChildNodeObjects(MapDataCollection mapDataCollection) + private StrictContextMenuItem CreateZoomToExtentsItem(MapDataContext context) { - return mapDataCollection.Collection.Reverse() - .Select(mapData => new MapDataContext(mapData, mapDataCollection)) - .Cast().ToArray(); - } + StrictContextMenuItem zoomToExtentsItem = null; - private void NotifyObserversOfData(MapData mapData) - { - mapData.NotifyObservers(); + if (context is MapDataCollectionContext) + { + zoomToExtentsItem = CreateZoomToExtentsItem((MapDataCollection) context.WrappedData); + } - var observableParent = Data as IObservable; - observableParent?.NotifyObservers(); + if (context is FeatureBasedMapDataContext) + { + zoomToExtentsItem = CreateZoomToExtentsItem((FeatureBasedMapData) context.WrappedData); + } + + return zoomToExtentsItem; } #region MapData @@ -235,15 +238,15 @@ #endregion - #region MapDataContext + #region FeatureBasedMapDataContext private static Image GetImage(FeatureBasedMapDataContext context) { if (context.WrappedData is MapPointData) { return MapResources.PointsIcon; } - + if (context.WrappedData is MapLineData) { return MapResources.LineIcon; @@ -257,10 +260,10 @@ return GuiResources.folder; } - private void FeatureBasedMapDataContextOnNodeChecked(FeatureBasedMapDataContext mapDataContext, object parentData) + private static void FeatureBasedMapDataContextOnNodeChecked(FeatureBasedMapDataContext mapDataContext, object parentData) { mapDataContext.WrappedData.IsVisible = !mapDataContext.WrappedData.IsVisible; - NotifyObserversOfData(mapDataContext.WrappedData); + mapDataContext.WrappedData.NotifyObservers(); } private static bool FeatureBasedMapDataContextCanDropAndInsert(object draggedData, object targetData) @@ -302,7 +305,7 @@ private ContextMenuStrip MapDataContextContextMenuStrip(FeatureBasedMapDataContext mapDataContext, object parentData, TreeViewControl treeView) { return contextMenuBuilderProvider.Get(mapDataContext.WrappedData, treeView) - .AddCustomItem(CreateZoomToExtentsItem((FeatureBasedMapData) mapDataContext.WrappedData)) + .AddCustomItem(CreateZoomToExtentsItem(mapDataContext)) .AddSeparator() .AddDeleteItem() .AddSeparator() @@ -312,16 +315,34 @@ #endregion - #region MapDataCollection + #region MapDataCollectionContext - private static object[] GetCollectionChildNodeObjects(MapDataCollection mapDataCollection) + private static object[] GetCollectionChildNodeObjects(MapDataCollectionContext context) { - return GetChildNodeObjects(mapDataCollection); + var childObjects = new List(); + + var collection = (MapDataCollection) context.WrappedData; + foreach (MapData mapData in collection.Collection.Reverse()) + { + var featureBasedMapData = mapData as FeatureBasedMapData; + if (featureBasedMapData != null) + { + childObjects.Add(new FeatureBasedMapDataContext(featureBasedMapData, collection)); + } + + var nestedCollection = mapData as MapDataCollection; + if (nestedCollection != null) + { + childObjects.Add(new MapDataCollectionContext(nestedCollection, collection)); + } + } + + return childObjects.ToArray(); } private static bool MapDataCollectionCanDropAndInsert(object draggedData, object targetData) { - var draggedDataContext = (MapDataContext) draggedData; + var draggedDataContext = (MapDataCollectionContext) draggedData; var targetDataContext = targetData as MapDataContext; object targetDataObject = targetDataContext != null ? targetDataContext.ParentMapData : targetData; @@ -330,25 +351,26 @@ private static void MapDataCollectionOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) { - var mapDataContext = (MapDataContext) droppedData; - + var mapDataContext = (MapDataCollectionContext) droppedData; MapData mapData = mapDataContext.WrappedData; - var parent = (MapDataCollection) oldParentData; + var parentContext = (MapDataCollectionContext) oldParentData; + var parent = (MapDataCollection) parentContext.WrappedData; + parent.Remove(mapData); parent.Insert(parent.Collection.Count() - position, mapData); // Note: target is the same as the previous parent in this case parent.NotifyObservers(); } - private ContextMenuStrip MapDataCollectionContextMenuStrip(MapDataCollection mapDataCollection, object parentData, TreeViewControl treeView) + private ContextMenuStrip MapDataCollectionContextMenuStrip(MapDataCollectionContext context, object parentData, TreeViewControl treeView) { - return contextMenuBuilderProvider.Get(mapDataCollection, treeView) + return contextMenuBuilderProvider.Get(context, treeView) .AddCustomImportItem( MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer, MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer_ToolTip, MapResources.MapPlusIcon) .AddSeparator() - .AddCustomItem(CreateZoomToExtentsItem(mapDataCollection)) + .AddCustomItem(CreateZoomToExtentsItem(context)) .AddSeparator() .AddPropertiesItem() .Build(); Index: Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj =================================================================== diff -u -r0b17763d8c51949424fade278f2d52fe804cda52 -r842679c47f28f5f6349a2a34a96fc93adb094e51 --- Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision 0b17763d8c51949424fade278f2d52fe804cda52) +++ Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision 842679c47f28f5f6349a2a34a96fc93adb094e51) @@ -51,7 +51,7 @@ - + Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs =================================================================== diff -u -r0b17763d8c51949424fade278f2d52fe804cda52 -r842679c47f28f5f6349a2a34a96fc93adb094e51 --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs (.../FeatureBasedMapDataContextTreeNodeInfoTest.cs) (revision 0b17763d8c51949424fade278f2d52fe804cda52) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/FeatureBasedMapDataContextTreeNodeInfoTest.cs (.../FeatureBasedMapDataContextTreeNodeInfoTest.cs) (revision 842679c47f28f5f6349a2a34a96fc93adb094e51) @@ -176,7 +176,7 @@ [Test] [TestCase(true)] [TestCase(false)] - public void OnNodeChecked_WithContext_SetsMapDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + public void OnNodeChecked_WithContext_SetMapDataVisibilityAndNotifyObservers(bool initialVisibleState) { // Setup var observer = mocks.StrictMock(); @@ -360,7 +360,6 @@ mapDataCollection.Add(mapData3); mapDataCollection.Attach(observer); -// mapLegendView.Data = mapDataCollection; FeatureBasedMapDataContext context = GetContext(mapData1); MapDataCollectionContext collectionContext = GetContext(mapDataCollection); Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionContextTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionContextTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionContextTreeNodeInfoTest.cs (revision 842679c47f28f5f6349a2a34a96fc93adb094e51) @@ -0,0 +1,518 @@ +// 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.Commands; +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.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.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using GuiResources = Core.Common.Gui.Properties.Resources; + +namespace Core.Plugins.Map.Test.Legend +{ + [TestFixture] + public class MapDataCollectionContextTreeNodeInfoTest : NUnitFormTest + { + private const int contextMenuAddMapLayerIndex = 0; + private const int contextMenuZoomToAllIndex = 2; + + private MockRepository mocks; + private MapLegendView mapLegendView; + private TreeNodeInfo info; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + + public override void Setup() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + + info = treeNodeInfoLookup[typeof(MapDataCollectionContext)]; + } + + public override 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.IsNotNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNotNull(info.CanDrop); + Assert.IsNotNull(info.CanInsert); + Assert.IsNotNull(info.OnDrop); + } + + [Test] + public void Text_WithContext_ReturnsNameFromMapData() + { + // Setup + var mapDataCollection = new MapDataCollection("Collectie"); + + // Call + string text = info.Text(GetContext(mapDataCollection)); + + // Assert + Assert.AreEqual(mapDataCollection.Name, text); + } + + [Test] + public void Image_Always_ReturnsImageFromResource() + { + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(GuiResources.folder, image); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildrenWithContextAndDataReversed() + { + // Setup + var mapData1 = new TestFeatureBasedMapData(); + var mapData2 = new TestFeatureBasedMapData(); + var nestedCollection = new MapDataCollection("nested"); + var mapData3 = new TestFeatureBasedMapData(); + var mapDataCollection = new MapDataCollection("test data"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(nestedCollection); + mapDataCollection.Add(mapData3); + + mocks.ReplayAll(); + + // Call + object[] objects = info.ChildNodeObjects(GetContext(mapDataCollection)); + + // Assert + CollectionAssert.AreEqual(new MapDataContext[] + { + new FeatureBasedMapDataContext(mapData3, mapDataCollection), + new MapDataCollectionContext(nestedCollection, mapDataCollection), + new FeatureBasedMapDataContext(mapData2, mapDataCollection), + new FeatureBasedMapDataContext(mapData1, mapDataCollection) + }, objects); + } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Call + bool canDrag = info.CanDrag(null, null); + + // Assert + Assert.IsTrue(canDrag); + } + + [Test] + public void CanDrop_TargetParentIsSameAsSourceParent_ReturnsTrue() + { + // Setup + MapDataCollectionContext context = GetContext(new MapDataCollection("test")); + + // Call + bool canDrop = info.CanDrop(context, context.ParentMapData); + + // Assert + Assert.IsTrue(canDrop); + } + + [Test] + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + MapDataCollectionContext context = GetContext(new MapDataCollection("test")); + + // Call + bool canDrop = info.CanDrop(context, GetContext(new MapDataCollection("parent"))); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanInsert_TargetParentIsSameAsSourceParent_ReturnsTrue() + { + // Setup + MapDataCollectionContext context = GetContext(new MapDataCollection("test")); + + // Call + bool canInsert = info.CanInsert(context, context.ParentMapData); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + MapDataCollectionContext context = GetContext(new MapDataCollection("test")); + + // Call + bool canInsert = info.CanInsert(context, GetContext(new MapDataCollection("parent"))); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_MapDataCollectionContextMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var mapDataCollection1 = new MapDataCollection("Collection 1"); + var mapDataCollection2 = new MapDataCollection("Collection 2"); + var mapDataCollection3 = new MapDataCollection("Collection 3"); + var parentMapDataCollection = new MapDataCollection("test data"); + + parentMapDataCollection.Add(mapDataCollection1); + parentMapDataCollection.Add(mapDataCollection2); + parentMapDataCollection.Add(mapDataCollection3); + + MapDataCollectionContext parentContext = GetContext(parentMapDataCollection); + MapDataCollectionContext context = GetContext(mapDataCollection1); + + parentMapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + info.OnDrop(context, parentContext, parentContext, position, treeViewControl); + + // Assert + int reversedIndex = 2 - position; + Assert.AreSame(context.WrappedData, parentMapDataCollection.Collection.ElementAt(reversedIndex)); + } + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(4)] + [TestCase(50)] + public void OnDrop_MapDataCollectionContextMovedToPositionOutsideRange_ThrowsException(int position) + { + // Setup + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var mapDataCollection1 = new MapDataCollection("Collection 1"); + var mapDataCollection2 = new MapDataCollection("Collection 2"); + var mapDataCollection3 = new MapDataCollection("Collection 3"); + var parentMapDataCollection = new MapDataCollection("test data"); + + parentMapDataCollection.Add(mapDataCollection1); + parentMapDataCollection.Add(mapDataCollection2); + parentMapDataCollection.Add(mapDataCollection3); + + parentMapDataCollection.Attach(observer); + + MapDataCollectionContext parentContext = GetContext(parentMapDataCollection); + MapDataCollectionContext context = GetContext(mapDataCollection1); + + parentMapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + TestDelegate test = () => info.OnDrop(context, parentContext, parentContext, position, treeViewControl); + + // Assert + Assert.Throws(test); + } + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var mapData = new MapDataCollection("test data"); + MapDataCollectionContext context = GetContext(mapData); + + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomImportItem(null, null, null)).IgnoreArguments().Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).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(context, null)).Return(builder); + + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(context, null, null); + + // Assert + // Assert expectancies are called in TearDown() + } + + [Test] + public void ContextMenuStrip_Always_CustomImportItemEnabled() + { + // Setup + var mapDataCollection = new MapDataCollection("test data"); + MapDataCollectionContext context = GetContext(mapDataCollection); + + var applicationFeatureCommands = mocks.Stub(); + var importCommandHandler = mocks.Stub(); + importCommandHandler.Stub(ich => ich.CanImportOn(null)).IgnoreArguments().Return(true); + var exportCommandHandler = mocks.Stub(); + var updateCommandHandler = mocks.Stub(); + var viewCommands = mocks.Stub(); + + using (var treeViewControl = new TreeViewControl()) + { + var builder = new ContextMenuBuilder(applicationFeatureCommands, + importCommandHandler, + exportCommandHandler, + updateCommandHandler, + viewCommands, + mapDataCollection, + treeViewControl); + + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(context, treeViewControl)).Return(builder); + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuAddMapLayerIndex, + "&Voeg kaartlaag toe...", + "Importeer een nieuwe kaartlaag en voeg deze toe.", + Resources.MapPlusIcon); + } + } + } + + [Test] + public void ContextMenuStrip_VisibleFeatureBasedMapDataWithFeaturesInMapDataCollection_ZoomToAllItemEnabled() + { + // Setup + var featureBasedMapData = new TestFeatureBasedMapData + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + var mapDataCollection = new MapDataCollection("test data"); + mapDataCollection.Add(featureBasedMapData); + + using (var treeViewControl = new TreeViewControl()) + { + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapDataCollection), null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat alle zichtbare kaartlagen in deze map met kaartlagen precies in het beeld passen.", + Resources.ZoomToAllIcon); + } + } + } + + [Test] + public void ContextMenuStrip_InvisibleFeatureBasedMapDataInMapDataCollection_ZoomToAllItemDisabled() + { + // Setup + var featureBasedMapData = new TestFeatureBasedMapData + { + IsVisible = false + }; + var mapDataCollection = new MapDataCollection("test data"); + mapDataCollection.Add(featureBasedMapData); + + using (var treeViewControl = new TreeViewControl()) + { + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapDataCollection), null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet er minstens één kaartlaag in deze map met kaartlagen zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_VisibleFeatureBasedMapDataWithoutFeaturesInMapDataCollection_ZoomToAllItemDisabled() + { + // Setup + var featureBasedMapData = new TestFeatureBasedMapData + { + IsVisible = true + }; + var mapDataCollection = new MapDataCollection("test data"); + mapDataCollection.Add(featureBasedMapData); + + using (var treeViewControl = new TreeViewControl()) + { + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapDataCollection), null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet minstens één van de zichtbare kaartlagen in deze map met kaartlagen elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var mapData = new MapDataCollection("A"); + var featureBasedMapData = new TestFeatureBasedMapData + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + mapData.Add(featureBasedMapData); + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(mapData); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_NoMapControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var mapData = new MapDataCollection("A") + { + IsVisible = true + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + 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 842679c47f28f5f6349a2a34a96fc93adb094e51 refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?