Index: Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs
===================================================================
diff -u -rf665ce5f69f43f2ee4a96a05e44b849d019bb53a -rf2859c13f845d1cb1f654022aad4f48cdb5d908b
--- Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision f665ce5f69f43f2ee4a96a05e44b849d019bb53a)
+++ Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -54,6 +54,7 @@
mapLegendController = CreateLegendController(Gui);
mapRibbon = CreateMapRibbon();
+ mapLegendController.ToggleLegend();
Gui.ActiveViewChanged += GuiOnActiveViewChanged;
activated = true;
}
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj
===================================================================
diff -u -r3167b898b071fea4cf86c775bca5467fab086038 -rf2859c13f845d1cb1f654022aad4f48cdb5d908b
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj (.../Core.Plugins.DotSpatial.Test.csproj) (revision 3167b898b071fea4cf86c775bca5467fab086038)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj (.../Core.Plugins.DotSpatial.Test.csproj) (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -70,6 +70,8 @@
+
+
@@ -81,6 +83,10 @@
{3BBFD65B-B277-4E50-AE6D-BD24C3434609}
Core.Common.Base
+
+ {1D27F91F-4E62-4EAF-A0A8-A32708B9A9B1}
+ Core.Common.Controls.TreeView
+
{9a2d67e6-26ac-4d17-b11a-2b4372f2f572}
Core.Common.Controls
@@ -91,6 +97,10 @@
Core.Common.Gui
True
+
+ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
+ Core.Common.Utils
+
{D749EE4C-CE50-4C17-BF01-9A953028C126}
Core.Common.TestUtil
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs
===================================================================
diff -u -r3386076de3df80a7f7a5fd59e82eb8bdb1a7ebcd -rf2859c13f845d1cb1f654022aad4f48cdb5d908b
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision 3386076de3df80a7f7a5fd59e82eb8bdb1a7ebcd)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Windows;
+using System.Windows.Forms;
using Core.Common.Base.Storage;
using Core.Common.Controls.Views;
using Core.Common.Gui;
@@ -9,7 +10,9 @@
using Core.Common.Test.TestObjects;
using Core.Components.DotSpatial;
using Core.Components.DotSpatial.Data;
+using Core.Components.DotSpatial.TestUtil;
using Core.Plugins.DotSpatial.Forms;
+using Core.Plugins.DotSpatial.Legend;
using NUnit.Framework;
using Rhino.Mocks;
@@ -48,17 +51,38 @@
[Test]
[RequiresSTA]
- public void Activate_WithGui_BindsActiveViewChanged()
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Activate_WithGui_InitializeComponentsWithIMapViewAndBindsActiveViewChanged(bool useMapView)
{
// Setup
var mocks = new MockRepository();
+ IView view;
+
+ if (useMapView)
+ {
+ var chartView = mocks.Stub();
+ var chart = mocks.Stub();
+ chart.Data = new TestMapData();
+ chartView.Stub(v => v.Map).Return(chart);
+ view = chartView;
+ }
+ else
+ {
+ view = mocks.StrictMock();
+ }
+
using (var plugin = new DotSpatialGuiPlugin())
{
var gui = mocks.StrictMock();
+ gui.Stub(g => g.IsToolWindowOpen()).Return(false);
+
+ gui.Expect(g => g.OpenToolView(Arg.Matches(c => true)));
gui.Expect(g => g.ActiveViewChanged += null).IgnoreArguments();
gui.Expect(g => g.ActiveViewChanged -= null).IgnoreArguments();
+ gui.Expect(g => g.ActiveView).Return(view);
mocks.ReplayAll();
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs
===================================================================
diff -u
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs (revision 0)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendControllerTest.cs (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -0,0 +1,98 @@
+using System;
+using Core.Common.Gui;
+using Core.Plugins.DotSpatial.Legend;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Core.Plugins.DotSpatial.Test.Legend
+{
+ [TestFixture]
+ public class MapLegendControllerTest
+ {
+ [Test]
+ public void Constructor_WithoutToolViewController_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new MapLegendController(null);
+
+ // Assert
+ ArgumentNullException exception = Assert.Throws(test);
+ Assert.AreEqual("toolViewController", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_WithToolViewController_DoesNotThrow()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var toolViewController = mocks.StrictMock();
+
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate test = () => new MapLegendController(toolViewController);
+
+ // Assert
+ Assert.DoesNotThrow(test);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void IsLegendViewOpen_LegendViewOpenAndClosedState_ReturnsExpectedState(bool open)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var plugin = mocks.StrictMock();
+ plugin.Expect(p => p.IsToolWindowOpen()).Return(open);
+
+ mocks.ReplayAll();
+
+ var controller = new MapLegendController(plugin);
+
+ // Call
+ var result = controller.IsLegendViewOpen();
+
+ // Assert
+ Assert.AreEqual(open, result);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void ToggleLegendView_LegendViewOpenAndClosedState_TogglesStateOfLegendView(bool open)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var plugin = mocks.StrictMock();
+ if (open)
+ {
+ plugin.Expect(p => p.IsToolWindowOpen()).Return(false);
+ plugin.Expect(p => p.OpenToolView(Arg.Matches(c => true)));
+ plugin.Expect(p => p.CloseToolView(Arg.Matches(c => true)));
+ }
+ else
+ {
+ plugin.Expect(p => p.OpenToolView(Arg.Matches(c => true)));
+ }
+ plugin.Expect(p => p.IsToolWindowOpen()).Return(open);
+
+ mocks.ReplayAll();
+
+ var controller = new MapLegendController(plugin);
+
+ if (open)
+ {
+ controller.ToggleLegend();
+ }
+
+ // Call
+ controller.ToggleLegend();
+
+ // Assert
+ mocks.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs
===================================================================
diff -u
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (revision 0)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -0,0 +1,101 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Controls.TreeView;
+using Core.Common.Controls.Views;
+using Core.Common.Utils.Reflection;
+using Core.Components.DotSpatial.Data;
+using Core.Plugins.DotSpatial.Legend;
+using Core.Plugins.DotSpatial.Properties;
+using NUnit.Framework;
+
+namespace Core.Plugins.DotSpatial.Test.Legend
+{
+ [TestFixture]
+ public class MapLegendViewTest
+ {
+ [Test]
+ public void DefaultConstructor_CreatesUserControl()
+ {
+ // Call
+ var view = new MapLegendView();
+
+ // Assert
+ Assert.IsInstanceOf(view);
+ Assert.IsInstanceOf(view);
+ Assert.IsNull(view.Data);
+ Assert.AreEqual(Resources.General_Map, view.Text);
+ }
+
+ [Test]
+ public void DefaultConstructor_CreatesTreeViewControl()
+ {
+ // Call
+ var view = new MapLegendView();
+
+ var treeView = TypeUtils.GetField(view, "treeViewControl");
+
+ // Assert
+ Assert.IsNotNull(treeView);
+ Assert.IsInstanceOf(treeView);
+ }
+
+ [Test]
+ public void Data_MapData_DataSet()
+ {
+ // Setup
+ var view = new MapLegendView();
+ var mapData = new MapDataCollection(new List());
+
+ // Call
+ view.Data = mapData;
+
+ // Assert
+ Assert.AreSame(mapData, view.Data);
+ Assert.IsInstanceOf(view.Data);
+ }
+
+ [Test]
+ public void Data_ForNull_NullSet()
+ {
+ // Setup
+ var view = new MapLegendView();
+
+ // Call
+ view.Data = null;
+
+ // Assert
+ Assert.IsNull(view.Data);
+ }
+
+ [Test]
+ public void Data_OtherObject_ThrowsInvalidCastException()
+ {
+ // Setup
+ var view = new MapLegendView();
+
+ // Call
+ TestDelegate test = () => view.Data = new object();
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void RegisterTreeNodes_Always_RegisterMapDataObjects()
+ {
+ // Call
+ var view = new MapLegendView();
+ var treeView = TypeUtils.GetField(view, "treeViewControl");
+
+ // Assert
+ Assert.AreEqual(4, treeView.TreeNodeInfos.Count());
+
+ foreach (var treeNodeInfo in treeView.TreeNodeInfos)
+ {
+ Assert.IsInstanceOf(treeNodeInfo);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs
===================================================================
diff -u -r3167b898b071fea4cf86c775bca5467fab086038 -rf2859c13f845d1cb1f654022aad4f48cdb5d908b
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision 3167b898b071fea4cf86c775bca5467fab086038)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision f2859c13f845d1cb1f654022aad4f48cdb5d908b)
@@ -102,6 +102,37 @@
[Test]
[RequiresSTA]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void ValidateItems_Always_ToggleLegendViewIsCheckedEqualToCommandChecked(bool commandChecked)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var command = mocks.StrictMock();
+ command.Expect(c => c.Checked).Return(commandChecked);
+
+ mocks.ReplayAll();
+
+ var ribbon = new MapRibbon
+ {
+ ToggleLegendViewCommand = command,
+ };
+
+ var toggleLegendViewButton = ribbon.GetRibbonControl().FindName("ToggleLegendViewButton") as ToggleButton;
+
+ // Precondition
+ Assert.IsNotNull(toggleLegendViewButton, "Ribbon should have a toggle legend view button.");
+
+ // Call
+ ribbon.ValidateItems();
+
+ // Assert
+ Assert.AreEqual(commandChecked, toggleLegendViewButton.IsChecked);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [RequiresSTA]
public void ToggleLegendViewButton_OnClick_ExecutesToggleLegendViewCommand()
{
// Setup