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