Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs =================================================================== diff -u -r7a07203c617780964d1edb684eea0c74293b4b40 -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 7a07203c617780964d1edb684eea0c74293b4b40) +++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -315,10 +315,34 @@ public static void AssertContextMenuStripContainsItem(ContextMenuStrip menu, int position, string text, string toolTip, Image icon, bool enabled = true) { Assert.IsNotNull(menu); - Assert.Less(position, menu.Items.Count); + AssertContextMenuStripContainsItem(menu.Items, position, text, toolTip, icon, enabled); + } - var item = menu.Items[position]; + /// + /// Asserts that a contains an item at the given + /// with the correct properties. + /// + /// The containing an item at position . + /// The position of the menu item in . + /// The text expected for the menu item. + /// The tooltip expected for the menu item. + /// The image expected for the menu item. + /// Optional: the expected enabled state of the menu item. Default: true. + /// When does not contain a menu item at + /// position with the right , or . + /// + public static void AssertDropDownItemContainsItem(ToolStripDropDownItem menu, int position, string text, string toolTip, Image icon, bool enabled = true) + { + Assert.IsNotNull(menu); + AssertContextMenuStripContainsItem(menu.DropDownItems, position, text, toolTip, icon, enabled); + } + private static void AssertContextMenuStripContainsItem(ToolStripItemCollection items, int position, string text, string toolTip, Image icon, bool enabled = true) + { + Assert.Less(position, items.Count); + + var item = items[position]; + Assert.AreEqual(text, item.Text); Assert.AreEqual(toolTip, item.ToolTipText); Assert.AreEqual(enabled, item.Enabled); Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj =================================================================== diff -u -ref35125104cc8b0201f9c961049cc6c8a30fb74d -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision ef35125104cc8b0201f9c961049cc6c8a30fb74d) +++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -102,7 +102,9 @@ - + + Component + Index: Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs =================================================================== diff -u -r7a07203c617780964d1edb684eea0c74293b4b40 -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision 7a07203c617780964d1edb684eea0c74293b4b40) +++ Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -302,6 +302,113 @@ } [Test] + public void AssertDropDownItemContainsItem_MenuNull_ThrowsAssertionException() + { + // Call + TestDelegate call = () => TestHelper.AssertDropDownItemContainsItem(null, 0, "", "", null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertDropDownItemContainsItem_NoMenuItemAtPosition_ThrowsAssertionException() + { + // Call + TestDelegate call = () => TestHelper.AssertDropDownItemContainsItem(new TestToolStripDropDownItem(), 0, "", "", null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertDropDownItemContainsItem_MenuItemWithDifferentText_ThrowsAssertionException() + { + // Setup + var dropDownItem = new TestToolStripDropDownItem(); + var testItem = CreateContextMenuItem(); + dropDownItem.DropDownItems.Add(testItem); + + // Call + TestDelegate call = () => + { + TestHelper.AssertDropDownItemContainsItem(dropDownItem, 0, testItem.Text + "someThing", testItem.ToolTipText, testItem.Image); + }; + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertDropDownItemContainsItem_MenuItemWithDifferentToolTip_ThrowsAssertionException() + { + // Setup + var dropDownItem = new TestToolStripDropDownItem(); + var testItem = CreateContextMenuItem(); + dropDownItem.DropDownItems.Add(testItem); + + // Call + TestDelegate call = () => + { + TestHelper.AssertDropDownItemContainsItem(dropDownItem, 0, testItem.Text, testItem.ToolTipText + "someThing", testItem.Image); + }; + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertDropDownItemContainsItem_MenuItemWithDifferentImage_ThrowsAssertionException() + { + // Setup + var dropDownItem = new TestToolStripDropDownItem(); + var testItem = CreateContextMenuItem(); + dropDownItem.DropDownItems.Add(testItem); + + // Call + TestDelegate call = () => + { + TestHelper.AssertDropDownItemContainsItem(dropDownItem, 0, testItem.Text, testItem.ToolTipText, Resources.acorn); + }; + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void AssertDropDownItemContainsItem_MenuItemWithDifferentEnabeldState_ThrowsAssertionException(bool enabled) + { + // Setup + var dropDownItem = new TestToolStripDropDownItem(); + var testItem = CreateContextMenuItem(); + testItem.Enabled = enabled; + dropDownItem.DropDownItems.Add(testItem); + + // Call + TestDelegate call = () => + { + TestHelper.AssertDropDownItemContainsItem(dropDownItem, 0, testItem.Text, testItem.ToolTipText, testItem.Image, !enabled); + }; + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertDropDownItemContainsItem_SameMenuItemProperties_NoExceptions() + { + // Setup + var dropDownItem = new TestToolStripDropDownItem(); + var testItem = CreateContextMenuItem(); + dropDownItem.DropDownItems.Add(testItem); + + // Call & Assert + TestHelper.AssertDropDownItemContainsItem(dropDownItem, 0, testItem.Text, testItem.ToolTipText, testItem.Image); + } + + [Test] public void AssertExceptionCustomMessage_NoException_ThrowsAssertionException() { // Setup @@ -372,4 +479,6 @@ }; } } + + public class TestToolStripDropDownItem : ToolStripDropDownItem {} } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs =================================================================== diff -u -ra772c49f0c4e64a606d832165c4f55f617a6e663 -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs (.../SharpMapGisGuiPlugin.cs) (revision a772c49f0c4e64a606d832165c4f55f617a6e663) +++ Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/SharpMapGisGuiPlugin.cs (.../SharpMapGisGuiPlugin.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -36,10 +36,9 @@ public class SharpMapGisGuiPlugin : GuiPlugin { private static IGui gui; - - private static MapLegendView mapLegendView; private static IGisGuiService gisGuiService; + private MapLegendView mapLegendView; private IRibbonCommandHandler ribbonCommandHandler; public SharpMapGisGuiPlugin() @@ -366,7 +365,7 @@ RefreshRibbonItems(); } - private static void UpdateMapLegendView() + private void UpdateMapLegendView() { if (mapLegendView == null) { Index: Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Core.Plugins.SharpMapGis.Test.csproj =================================================================== diff -u -r529c5b708080eb65abba0502d79869fe549e035a -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Core.Plugins.SharpMapGis.Test.csproj (.../Core.Plugins.SharpMapGis.Test.csproj) (revision 529c5b708080eb65abba0502d79869fe549e035a) +++ Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Core.Plugins.SharpMapGis.Test.csproj (.../Core.Plugins.SharpMapGis.Test.csproj) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -68,6 +68,9 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\lib\NUnitForms.dll + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll @@ -197,10 +200,6 @@ {0A82E7D2-26F8-4A30-9787-7EEABCD7F470} Core.GIS.SharpMapTestUtil - - {EFA25023-CF6A-4FF7-8C42-B24D7F9509E1} - Core.Common.TestUtils - Index: Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Forms/MapLegendViewTest.cs =================================================================== diff -u -rad6f88d1d7b21f950588f6109b79fe007aab0c9e -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 --- Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Forms/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision ad6f88d1d7b21f950588f6109b79fe007aab0c9e) +++ Core/Plugins/test/Core.Plugins.SharpMapGis.Test/Forms/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302) @@ -11,16 +11,25 @@ using Core.GIS.SharpMap.Map; using Core.Plugins.SharpMapGis.Gui; using Core.Plugins.SharpMapGis.Gui.Forms.MapLegendView; +using Core.Plugins.SharpMapGis.Gui.Properties; using NUnit.Framework; using Rhino.Mocks; +using TreeNode = Core.Common.Controls.Swf.TreeViewControls.TreeNode; +using TreeView = Core.Common.Controls.Swf.TreeViewControls.TreeView; namespace Core.Plugins.SharpMapGis.Test.Forms { [TestFixture] public class MapLegendViewTest { - private readonly MockRepository mocks = new MockRepository(); + private MockRepository mocks; + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + } + [Test] public void Init() { @@ -39,6 +48,9 @@ string path = TestHelper.GetDataDir() + "rivers.shp"; var shapeFile = mocks.StrictMock(path); + + mocks.ReplayAll(); + shapeFile.Expect(sf => sf.GetExtents()).Return(null).Repeat.Any(); shapeFile.Expect(sf => sf.FeaturesChanged += null).IgnoreArguments(); shapeFile.Expect(sf => sf.FeaturesChanged -= null).IgnoreArguments().Repeat.Twice(); @@ -54,7 +66,7 @@ TypeUtils.CallPrivateMethod(mapLegendView, "RemoveLayer", vectorLayer); - shapeFile.VerifyAllExpectations(); + mocks.VerifyAll(); } [Test] @@ -109,6 +121,105 @@ MapLegendView.HideAllLayersButThisOne(layer1, map); } + [Test] + public void GetContextMenu_ForMap_ReturnContextMenuStripWithSixItems() + { + // Setup + var mapLegendView = CreateMapLegendView(); + var mapMock = mocks.StrictMock(); + + mocks.Replay(mapMock); + + // Call + var contextMenu = mapLegendView.GetContextMenu(mapMock); + + // Assert + Assert.AreEqual(6, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, "Voeg kaartlaag toe", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 1, "Toevoegen groeplaag", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, "Zoom naar alles", null, Resources.MapZoomToExtentsImage); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 4, "Zoomen tot kaartbereik", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 5, "Veranderen kaartco�rdinatenstelsel...", null, Resources.GlobePencil); + + Assert.IsInstanceOf(contextMenu.Items[2]); + } + + [Test] + public void GetContextMenu_ForLayer_ReturnContextMenuStripWithTwelveItems() + { + // Setup + var mapLegendView = CreateMapLegendView(); + var layerMock = mocks.StrictMock(); + + mocks.Replay(layerMock); + + // Call + var contextMenu = mapLegendView.GetContextMenu(layerMock); + + // Assert + Assert.AreEqual(12, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 2, "&Verwijderen", null, Resources.DeleteHS); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, "&Hernoemen", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 5, "Volgorde", null, Resources.LayersStack); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 6, "&Zoomen naar omvang", null, Resources.MapZoomToExtentsImage); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 7, "Synchroniseer zoomniveau met kaart", null, Resources.LayersUngroup); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 9, "Labels weergeven", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 10, "Weergeven in de legenda", null, null); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 11, "Alle andere lagen verbergen", null, null); + + var toolStripDropDown = contextMenu.Items[5] as ToolStripDropDownItem; + + Assert.NotNull(toolStripDropDown); + TestHelper.AssertDropDownItemContainsItem(toolStripDropDown, 0, "Op de voorgrond plaatsen", null, Resources.LayersStackArrange); + TestHelper.AssertDropDownItemContainsItem(toolStripDropDown, 1, "Naar de achtergrond verplaatsen", null, Resources.LayersStackArrangeBack); + TestHelper.AssertDropDownItemContainsItem(toolStripDropDown, 3, "Naar voren halen", null, null); + TestHelper.AssertDropDownItemContainsItem(toolStripDropDown, 4, "Naar achteren sturen", null, null); + + CollectionAssert.AllItemsAreInstancesOfType(new[] { contextMenu.Items[1], contextMenu.Items[4], contextMenu.Items[8], toolStripDropDown.DropDownItems[2] }, typeof(ToolStripSeparator)); + } + + [Test] + public void GetContextMenu_ForLayerNullLayerSelected_ShowAttributeTableDisabled() + { + // Setup + var layerMock = mocks.StrictMock(); + var mapLegendView = CreateMapLegendView(); + + // Call + var contextMenu = mapLegendView.GetContextMenu(layerMock); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, "Attributentabel openen", null, Resources.Table, false); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetContextMenu_ForLayerShowAttributeTableSetOnSelectedNode_ShowAttributeTableItemSetToCorrectState(bool showAttributeTableEnabled) + { + // Setup + var layerMock = mocks.Stub(); + var mapLegendView = CreateMapLegendView(); + + layerMock.ShowAttributeTable = showAttributeTableEnabled; + + var treeView = (TreeView) mapLegendView.Controls.Find("TreeView", true)[0]; + var selectedNode = new TreeNode(treeView); + var parentNode = new TreeNode(treeView); + parentNode.Nodes.Add(selectedNode); + selectedNode.Tag = layerMock; + treeView.Nodes.Add(parentNode); + treeView.SelectedNode = selectedNode; + + // Call + var contextMenu = mapLegendView.GetContextMenu(layerMock); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, "Attributentabel openen", null, Resources.Table, showAttributeTableEnabled); + + mocks.VerifyAll(); + } + private MapLegendView CreateMapLegendView() { var project = new Project(); @@ -118,9 +229,6 @@ //create stubbed version of plugingui SharpMapGisGuiPlugin guiPlugin = new SharpMapGisGuiPlugin(); - IGisGuiService gisService = mocks.Stub(); - guiPlugin.GisGuiService = gisService; - Expect.Call(gui.ApplicationCore).Return(applicationCore).Repeat.Any(); Expect.Call(gui.Plugins).Return(new[] {