Index: Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs
===================================================================
diff -u -reff23cd289c9dfc4d626a76cac16477cebfdb0fe -r47324919290e03ed6e8147f85e67024c16e602a8
--- Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision eff23cd289c9dfc4d626a76cac16477cebfdb0fe)
+++ Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision 47324919290e03ed6e8147f85e67024c16e602a8)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using Core.Common.Gui.Forms;
using Core.Common.Gui.Forms.ViewManager;
@@ -48,6 +49,12 @@
public override void Activate()
{
mapRibbon = CreateMapRibbon();
+
+ if (Gui == null)
+ {
+ throw new ArgumentNullException("Gui", "Cannot create a view when the plugin is null");
+ }
+
Gui.ActiveViewChanged += GuiOnActiveViewChanged;
activated = true;
}
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj
===================================================================
diff -u -r96605c3f9beab21e2739081492bac131d0978d7a -r47324919290e03ed6e8147f85e67024c16e602a8
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj (.../Core.Plugins.DotSpatial.Test.csproj) (revision 96605c3f9beab21e2739081492bac131d0978d7a)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Core.Plugins.DotSpatial.Test.csproj (.../Core.Plugins.DotSpatial.Test.csproj) (revision 47324919290e03ed6e8147f85e67024c16e602a8)
@@ -53,6 +53,9 @@
+
+ ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+
@@ -66,9 +69,17 @@
+
+
+ Component
+
+
+ {3BBFD65B-B277-4E50-AE6D-BD24C3434609}
+ Core.Common.Base
+
{9a2d67e6-26ac-4d17-b11a-2b4372f2f572}
Core.Common.Controls
@@ -83,6 +94,10 @@
{D749EE4C-CE50-4C17-BF01-9A953028C126}
Core.Common.TestUtil
+
+ {E0990383-FB2E-47D1-99CD-9B9FA2929E5B}
+ Core.Common.Test
+
{AA47E858-A2A7-470E-8B2D-C76AE8ED9CCD}
Core.Components.DotSpatial
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs
===================================================================
diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -r47324919290e03ed6e8147f85e67024c16e602a8
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision 47324919290e03ed6e8147f85e67024c16e602a8)
@@ -1,9 +1,17 @@
-using System.Linq;
+using System;
+using System.Linq;
+using System.Windows;
+using Core.Common.Base.Storage;
+using Core.Common.Controls.Views;
using Core.Common.Gui;
+using Core.Common.Gui.Forms.MainWindow;
using Core.Common.Gui.Plugin;
+using Core.Common.Test.TestObjects;
+using Core.Components.DotSpatial;
using Core.Components.DotSpatial.Data;
using Core.Plugins.DotSpatial.Forms;
using NUnit.Framework;
+using Rhino.Mocks;
namespace Core.Plugins.DotSpatial.Test
{
@@ -23,6 +31,50 @@
}
[Test]
+ [RequiresSTA]
+ public void Activate_WithoutGui_ThrowsArgumentNullException()
+ {
+ // Setup
+ using (var plugin = new DotSpatialGuiPlugin())
+ {
+ // Call
+ TestDelegate test = () => plugin.Activate();
+
+ // Assert
+ ArgumentNullException exception = Assert.Throws(test);
+ Assert.AreEqual("Gui", exception.ParamName);
+ }
+ }
+
+ [Test]
+ [RequiresSTA]
+ public void Activate_WithGui_BindsActiveViewChanged()
+ {
+ // Setup
+ var mocks = new MockRepository();
+
+ using (var plugin = new DotSpatialGuiPlugin())
+ {
+ var gui = mocks.StrictMock();
+
+ gui.Expect(g => g.ActiveViewChanged += null).IgnoreArguments();
+ gui.Expect(g => g.ActiveViewChanged -= null).IgnoreArguments();
+
+ mocks.ReplayAll();
+
+ plugin.Gui = gui;
+
+ // Call
+ plugin.Activate();
+
+ // Assert
+ Assert.IsInstanceOf(plugin);
+ Assert.NotNull(plugin.RibbonCommandHandler);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
public void GetViewInfoObjects_Always_ReturnsMapDataViewInfo()
{
// Setup
@@ -40,5 +92,39 @@
Assert.AreEqual("Kaart", views[0].GetViewName(view, null));
}
}
+
+ [Test]
+ [RequiresSTA]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void GivenConfiguredGui_WhenActiveViewChangesToViewWithMap_ThenRibbonSetVisibility(bool visible)
+ {
+ // Given
+ var mocks = new MockRepository();
+ var projectStore = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var gui = new RingtoetsGui(new MainWindow(), projectStore))
+ {
+ var plugin = new DotSpatialGuiPlugin();
+ var testMapView = new TestMapView();
+ var map = new BaseMap();
+ IView viewMock = visible ? (IView) testMapView : new TestView();
+
+ testMapView.Data = map;
+
+ gui.Plugins.Add(plugin);
+ plugin.Gui = gui;
+ gui.Run();
+
+ // When
+ gui.DocumentViews.Add(viewMock);
+ gui.DocumentViews.ActiveView = viewMock;
+
+ // Then
+ Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility);
+ mocks.VerifyAll();
+ }
+ }
}
}
\ No newline at end of file
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Forms/MapDataViewTest.cs
===================================================================
diff -u -rcd2cd8c2cfa9e88043c9dd10f843ba2d7fd81338 -r47324919290e03ed6e8147f85e67024c16e602a8
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Forms/MapDataViewTest.cs (.../MapDataViewTest.cs) (revision cd2cd8c2cfa9e88043c9dd10f843ba2d7fd81338)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Forms/MapDataViewTest.cs (.../MapDataViewTest.cs) (revision 47324919290e03ed6e8147f85e67024c16e602a8)
@@ -39,6 +39,7 @@
var map = (BaseMap) mapObject;
Assert.AreEqual(DockStyle.Fill, map.Dock);
+ Assert.NotNull(mapView.Map);
}
[Test]
Fisheye: Tag 329e2f80a0adb45f0bdad64269e0862bae458a44 refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.DotSpatial.Test/MapRibbonTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/TestMapView.cs
===================================================================
diff -u
--- Core/Plugins/test/Core.Plugins.DotSpatial.Test/TestMapView.cs (revision 0)
+++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/TestMapView.cs (revision 47324919290e03ed6e8147f85e67024c16e602a8)
@@ -0,0 +1,22 @@
+using System.Windows.Forms;
+using Core.Components.DotSpatial;
+using Core.Plugins.DotSpatial.Forms;
+
+namespace Core.Plugins.DotSpatial.Test
+{
+ ///
+ /// Simple implementation which can be used in tests.
+ ///
+ public class TestMapView : Control, IMapView
+ {
+ public object Data { get; set; }
+
+ public IMap Map
+ {
+ get
+ {
+ return (BaseMap) Data;
+ }
+ }
+ }
+}