Index: Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs =================================================================== diff -u -r86e717a5477d55d1c4351f2857a1d76e220a3ab4 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision 86e717a5477d55d1c4351f2857a1d76e220a3ab4) +++ Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -80,7 +80,7 @@ private MapLegendController CreateLegendController(IToolViewController toolViewController) { - var controller = new MapLegendController(toolViewController); + var controller = new MapLegendController(toolViewController, Gui); controller.OnOpenLegend += (s, e) => UpdateComponentsForActiveView(); return controller; } Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendController.cs =================================================================== diff -u -ra3c8c0cb4384de51a18d77cc7bea487f97ba21e1 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendController.cs (.../MapLegendController.cs) (revision a3c8c0cb4384de51a18d77cc7bea487f97ba21e1) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendController.cs (.../MapLegendController.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -22,6 +22,7 @@ using System; using Core.Common.Controls.Views; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Components.Gis.Data; namespace Core.Plugins.DotSpatial.Legend @@ -32,6 +33,7 @@ public class MapLegendController { private readonly IToolViewController toolViewController; + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; public EventHandler OnOpenLegend; private IView legendView; @@ -40,13 +42,20 @@ /// Creates a new instance of . /// /// The to invoke actions upon. - public MapLegendController(IToolViewController toolViewController) + /// The to create context menus. + /// Thrown when or is null. + public MapLegendController(IToolViewController toolViewController, IContextMenuBuilderProvider contextMenuBuilderProvider) { if (toolViewController == null) { throw new ArgumentNullException("toolViewController", "Cannot create a MapLegendController when the tool view controller is null."); } + if (contextMenuBuilderProvider == null) + { + throw new ArgumentNullException("contextMenuBuilderProvider", "Cannot create a MapLegendController when the context menu builder provider is null."); + } this.toolViewController = toolViewController; + this.contextMenuBuilderProvider = contextMenuBuilderProvider; } /// @@ -91,7 +100,7 @@ /// private void OpenLegendView() { - legendView = new MapLegendView(); + legendView = new MapLegendView(contextMenuBuilderProvider); toolViewController.OpenToolView(legendView); if (OnOpenLegend != null) { Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs =================================================================== diff -u -r30b12b82918d500fe834eafd9f6cd9b2c5dbe60f -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 30b12b82918d500fe834eafd9f6cd9b2c5dbe60f) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -19,11 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; +using Core.Common.Gui.ContextMenu; using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; @@ -37,13 +39,22 @@ /// public sealed partial class MapLegendView : UserControl, IView { + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; private readonly TreeViewControl treeViewControl; /// /// Creates a new instance of . /// - public MapLegendView() + /// The to create context menus. + /// Thrown when is null. + public MapLegendView(IContextMenuBuilderProvider contextMenuBuilderProvider) { + if (contextMenuBuilderProvider == null) + { + throw new ArgumentNullException("contextMenuBuilderProvider", "Cannot create a MapLegendView when the context menu builder provider is null"); + } + + this.contextMenuBuilderProvider = contextMenuBuilderProvider; InitializeComponent(); Text = DotSpatialResources.General_Map; Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Commands/ToggleMapLegendViewCommandTest.cs =================================================================== diff -u -r5c3f702f76f617808344416749d1ec1cfb104559 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Commands/ToggleMapLegendViewCommandTest.cs (.../ToggleMapLegendViewCommandTest.cs) (revision 5c3f702f76f617808344416749d1ec1cfb104559) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Commands/ToggleMapLegendViewCommandTest.cs (.../ToggleMapLegendViewCommandTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -1,5 +1,6 @@ using Core.Common.Controls.Commands; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Plugins.DotSpatial.Commands; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; @@ -40,9 +41,11 @@ var plugin = mocks.StrictMock(); plugin.Expect(p => p.IsToolWindowOpen()).Return(open); + var contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); - var controller = new MapLegendController(plugin); + var controller = new MapLegendController(plugin, contextMenuBuilderProvider); var command = new ToggleMapLegendViewCommand(controller); // Call @@ -59,6 +62,7 @@ // Setup var mocks = new MockRepository(); var plugin = mocks.StrictMock(); + var contextMenuBuilderProvider = mocks.StrictMock(); // Open first using (mocks.Ordered()) @@ -72,7 +76,7 @@ } mocks.ReplayAll(); - var controller = new MapLegendController(plugin); + var controller = new MapLegendController(plugin, contextMenuBuilderProvider); var command = new ToggleMapLegendViewCommand(controller); // Call Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -rc9f9c04e4fc62406231afd07d63cd7da11673ec6 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision c9f9c04e4fc62406231afd07d63cd7da11673ec6) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -3,6 +3,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; @@ -25,7 +26,8 @@ public void SetUp() { mocks = new MockRepository(); - mapLegendView = new MapLegendView(); + var contextMenuBuilderProvider = mocks.StrictMock(); + mapLegendView = new MapLegendView(contextMenuBuilderProvider); var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs =================================================================== diff -u -rf2859c13f845d1cb1f654022aad4f48cdb5d908b -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs (.../MapLegendControllerTest.cs) (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs (.../MapLegendControllerTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -1,5 +1,6 @@ using System; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; using Rhino.Mocks; @@ -12,25 +13,49 @@ [Test] public void Constructor_WithoutToolViewController_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + // Call - TestDelegate test = () => new MapLegendController(null); + TestDelegate test = () => new MapLegendController(null, contextMenuBuilderProvider); // Assert ArgumentNullException exception = Assert.Throws(test); Assert.AreEqual("toolViewController", exception.ParamName); + mocks.VerifyAll(); } [Test] - public void Constructor_WithToolViewController_DoesNotThrow() + public void Constructor_WithoutContextMenuBuilderProvicer_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var toolViewController = mocks.StrictMock(); + mocks.ReplayAll(); + // Call + TestDelegate test = () => new MapLegendController(toolViewController, null); + + // Assert + ArgumentNullException exception = Assert.Throws(test); + Assert.AreEqual("contextMenuBuilderProvider", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_WithToolViewControllerAndContextMenuBuilderProvider_DoesNotThrow() + { + // Setup + var mocks = new MockRepository(); + var toolViewController = mocks.StrictMock(); + var contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); // Call - TestDelegate test = () => new MapLegendController(toolViewController); + TestDelegate test = () => new MapLegendController(toolViewController, contextMenuBuilderProvider); // Assert Assert.DoesNotThrow(test); @@ -45,11 +70,12 @@ // Setup var mocks = new MockRepository(); var plugin = mocks.StrictMock(); + var contextMenuBuilderProvider = mocks.StrictMock(); plugin.Expect(p => p.IsToolWindowOpen()).Return(open); mocks.ReplayAll(); - var controller = new MapLegendController(plugin); + var controller = new MapLegendController(plugin, contextMenuBuilderProvider); // Call var result = controller.IsLegendViewOpen(); @@ -67,6 +93,8 @@ // Setup var mocks = new MockRepository(); var plugin = mocks.StrictMock(); + var contextMenuBuilderProvider = mocks.StrictMock(); + if (open) { plugin.Expect(p => p.IsToolWindowOpen()).Return(false); @@ -81,7 +109,7 @@ mocks.ReplayAll(); - var controller = new MapLegendController(plugin); + var controller = new MapLegendController(plugin, contextMenuBuilderProvider); if (open) { Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -rc9f9c04e4fc62406231afd07d63cd7da11673ec6 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision c9f9c04e4fc62406231afd07d63cd7da11673ec6) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -5,22 +5,42 @@ using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Plugins.DotSpatial.Legend; using Core.Plugins.DotSpatial.Properties; using NUnit.Framework; +using Rhino.Mocks; namespace Core.Plugins.DotSpatial.Test.Legend { [TestFixture] public class MapLegendViewTest { + private MockRepository mocks; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + [Test] - public void DefaultConstructor_CreatesUserControl() + public void Constructor_CreatesUserControl() { // Call - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); // Assert Assert.IsInstanceOf(view); @@ -30,10 +50,20 @@ } [Test] + public void Constructor_ContextMenuBuilderProviderNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new MapLegendView(null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "Cannot create a MapLegendView when the context menu builder provider is null"); + } + + [Test] public void DefaultConstructor_CreatesTreeViewControl() { // Call - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var treeView = TypeUtils.GetField(view, "treeViewControl"); @@ -46,7 +76,7 @@ public void Data_MapDataCollection_DataSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var mapData = new MapDataCollection(new List(), "test data"); // Call @@ -62,7 +92,7 @@ public void Data_MapPointData_DataSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var mapData = new MapPointData(Enumerable.Empty(), "test data"); // Call @@ -77,7 +107,7 @@ public void Data_MapLineData_DataSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var mapData = new MapLineData(Enumerable.Empty(), "test data"); // Call @@ -92,7 +122,7 @@ public void Data_MapPolygonData_DataSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var mapData = new MapPolygonData(Enumerable.Empty(), "test data"); // Call @@ -107,7 +137,7 @@ public void Data_MapMultiLineData_DataSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); var mapData = new MapMultiLineData(Enumerable.Empty>(), "test data"); // Call @@ -122,7 +152,7 @@ public void Data_ForNull_NullSet() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); // Call view.Data = null; @@ -135,7 +165,7 @@ public void Data_OtherObject_ThrowsInvalidCastException() { // Setup - var view = new MapLegendView(); + var view = new MapLegendView(contextMenuBuilderProvider); // Call TestDelegate test = () => view.Data = new object(); Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -rc9f9c04e4fc62406231afd07d63cd7da11673ec6 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision c9f9c04e4fc62406231afd07d63cd7da11673ec6) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -4,6 +4,7 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; @@ -19,18 +20,29 @@ { private MapLegendView mapLegendView; private TreeNodeInfo info; + private MockRepository mockRepository; [SetUp] public void SetUp() { - mapLegendView = new MapLegendView(); + mockRepository = new MockRepository(); + var contextMenuBuilderProvider = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); info = treeNodeInfoLookup[typeof(MapLineData)]; } + [TearDown] + public void TearDown() + { + mockRepository.VerifyAll(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() { Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -rc9f9c04e4fc62406231afd07d63cd7da11673ec6 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision c9f9c04e4fc62406231afd07d63cd7da11673ec6) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -4,6 +4,7 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; @@ -19,18 +20,29 @@ { private MapLegendView mapLegendView; private TreeNodeInfo info; + private MockRepository mockRepository; [SetUp] public void SetUp() { - mapLegendView = new MapLegendView(); + mockRepository = new MockRepository(); + var contextMenuBuilderProvider = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); info = treeNodeInfoLookup[typeof(MapPointData)]; } + [TearDown] + public void TearDown() + { + mockRepository.VerifyAll(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() { Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -rc9f9c04e4fc62406231afd07d63cd7da11673ec6 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision c9f9c04e4fc62406231afd07d63cd7da11673ec6) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -4,6 +4,7 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; @@ -19,18 +20,29 @@ { private MapLegendView mapLegendView; private TreeNodeInfo info; + private MockRepository mockRepository; [SetUp] public void SetUp() { - mapLegendView = new MapLegendView(); + mockRepository = new MockRepository(); + var contextMenuBuilderProvider = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); info = treeNodeInfoLookup[typeof(MapPolygonData)]; } + [TearDown] + public void TearDown() + { + mockRepository.VerifyAll(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() { Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs =================================================================== diff -u -ra27cdd78dfeac8fceb178d406b32f2c188ca9c81 -r70686cbe24e58c091018219365a4bfa0c3c62685 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision a27cdd78dfeac8fceb178d406b32f2c188ca9c81) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision 70686cbe24e58c091018219365a4bfa0c3c62685) @@ -4,6 +4,7 @@ using System.Windows.Controls.Primitives; using Core.Common.Controls.Commands; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Components.Gis.Forms; using Core.Plugins.DotSpatial.Commands; using Core.Plugins.DotSpatial.Legend; @@ -47,9 +48,10 @@ // Setup var mocks = new MockRepository(); var toolViewController = mocks.Stub(); + var contextMenuBuilderProvider = mocks.StrictMock(); mocks.ReplayAll(); - var toggleLegendViewCommand = new ToggleMapLegendViewCommand(new MapLegendController(toolViewController)); + var toggleLegendViewCommand = new ToggleMapLegendViewCommand(new MapLegendController(toolViewController, contextMenuBuilderProvider)); var ribbon = new MapRibbon {