Index: Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj =================================================================== diff -u -raf6538ce2677998cbc514db20c2756c9dd2eac6f -r89e16fb45c79e575b0c335e71705694a9dac87c8 --- Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj (.../Core.Gui.Test.csproj) (revision af6538ce2677998cbc514db20c2756c9dd2eac6f) +++ Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj (.../Core.Gui.Test.csproj) (revision 89e16fb45c79e575b0c335e71705694a9dac87c8) @@ -17,6 +17,7 @@ + @@ -43,6 +44,12 @@ + + 2.0.0-rc1 + + + 2.0.0-rc1 + 2.0.12 Index: Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs =================================================================== diff -u -rb63b0f07d995741fbfa0d39d987424c7399794e1 -r89e16fb45c79e575b0c335e71705694a9dac87c8 --- Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision b63b0f07d995741fbfa0d39d987424c7399794e1) +++ Core/Gui/test/Core.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 89e16fb45c79e575b0c335e71705694a9dac87c8) @@ -28,6 +28,9 @@ using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; +using Core.Common.Util.Reflection; +using Core.Components.DotSpatial.Forms; +using Core.Components.Gis.Forms; using Core.Gui.Commands; using Core.Gui.Forms.MainWindow; using Core.Gui.Forms.Map; @@ -38,12 +41,15 @@ using Core.Gui.PropertyBag; using Core.Gui.Settings; using Core.Gui.TestUtil; +using Core.Gui.TestUtil.Map; +using DotSpatial.Data; using NUnit.Framework; using Rhino.Mocks; namespace Core.Gui.Test.Forms.MainWindow { [TestFixture] + [Apartment(ApartmentState.STA)] public class MainWindowTest { private MessageWindowLogAppender originalValue; @@ -62,7 +68,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void Constructor_ExpectedValues() { // Call @@ -92,7 +97,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void Dispose_SetIsWindowDisposedTrue() { // Setup @@ -109,7 +113,6 @@ [Test] [TestCase(true)] [TestCase(false)] - [Apartment(ApartmentState.STA)] public void Visible_SettingValueWithoutHavingSetGui_ThrowInvalidOperationException(bool newVisibleValue) { // Setup @@ -124,7 +127,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void Visible_SetToTrue_ShowMainForm() { // Setup @@ -156,7 +158,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void Visible_SetToFalse_HideMainForm() { // Setup @@ -189,7 +190,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void SubscribeToGui_NoGuiSet_DoNothing() { // Setup @@ -204,7 +204,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void SubscribeToGui_GuiSet_AttachEvents() { // Setup @@ -232,7 +231,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void UnsubscribeFromGui_NoGuiSet_DoNothing() { // Setup @@ -247,7 +245,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void UnsubscribeFromGui_GuiSetAndSubscribed_DetachEvents() { // Setup @@ -280,7 +277,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void InitPropertiesWindowOrBringToFront_GuiNotSet_ThrowInvalidOperationException() { // Setup @@ -295,7 +291,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void InitPropertiesWindowOrBringToFront_GuiSet_InitializePropertyGrid() { // Setup @@ -334,7 +329,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void InitPropertiesWindowOrBringToFront_GuiSetAndCalledTwice_PropertyGridViewInstanceNotUpdatedRedundantly() { // Setup @@ -375,7 +369,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void InitializeToolWindows_GuiNotSet_ThrowInvalidOperationException() { // Setup @@ -390,7 +383,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void InitializeToolWindows_GuiSet_InitializeToolWindows() { // Setup @@ -441,7 +433,7 @@ Assert.AreEqual("Berichten", mainWindow.MessageWindow.Text); Assert.IsInstanceOf(mainWindow.MapLegendView); - Assert.IsNull(mainWindow.MapLegendView.Data); + Assert.IsNull(GetMapControl(mainWindow.MapLegendView)); Assert.IsNull(viewHost.ActiveDocumentView); } @@ -450,7 +442,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void GivenGuiWithProjectExplorer_WhenClosingProjectExplorer_ThenProjectExplorerSetToNull() { // Given @@ -484,7 +475,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void GivenGuiWithPropertyGrid_WhenClosingPropertyGrid_ThenPropertyGridSetToNull() { // Given @@ -518,7 +508,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void GivenGuiWithMessageWindow_WhenClosingMessageWindow_ThenMessageWindowSetToNull() { // Given @@ -552,7 +541,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void GivenGuiWithMapLegendView_WhenClosingMapLegendView_ThenMapLegendViewSetToNull() { // Given @@ -586,7 +574,6 @@ } [Test] - [Apartment(ApartmentState.STA)] public void GivenGuiWithProjectExplorer_WhenUpdateProjectExplorer_ThenDataSetOnProjectExplorer() { // Given @@ -623,5 +610,200 @@ } mocks.VerifyAll(); } + + [Test] + public void GivenGuiWithMapLegendView_WhenMapViewOpened_ThenMapZoomedToExtents() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var testMapView = new TestMapView(); + var map = (DotSpatialMap) ((MapControl) testMapView.Map).Controls[0].Controls[1]; + + // Precondition + Extent initialExtents = map.ViewExtents; + + // When + gui.ViewHost.AddDocumentView(testMapView); + + // Then + Assert.AreNotEqual(initialExtents, map.ViewExtents); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithMapLegendView_WhenMapViewAdded_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view = new TestMapView(); + MapLegendView mapLegendView = mainWindow.MapLegendView; + + // Precondition + Assert.IsNull(GetMapControl(mapLegendView)); + + // When + gui.ViewHost.AddDocumentView(view); + + // Then + Assert.AreSame(view.Map, GetMapControl(mapLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithMapLegendView_WhenMapViewBroughtToFront_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view1 = new TestMapView(); + var view2 = new TestMapView(); + MapLegendView mapLegendView = mainWindow.MapLegendView; + + gui.ViewHost.AddDocumentView(view1); + gui.ViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + + // When + gui.ViewHost.BringToFront(view1); + + // Then + Assert.AreSame(view1.Map, GetMapControl(mapLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithMapLegendView_WhenMapViewRemoved_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view = new TestMapView(); + MapLegendView mapLegendView = mainWindow.MapLegendView; + + gui.ViewHost.AddDocumentView(view); + + // Precondition + Assert.AreSame(view.Map, GetMapControl(mapLegendView)); + + // When + gui.ViewHost.Remove(view); + + // Then + Assert.IsNull(GetMapControl(mapLegendView)); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenGuiWithMapLegendView_WhenOtherMapViewRemoved_ThenComponentsNotUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + gui.Plugins.Add(new TestPlugin()); + gui.Run(); + + mainWindow.SetGui(gui); + mainWindow.InitializeToolWindows(); + + var view1 = new TestMapView(); + var view2 = new TestMapView(); + MapLegendView mapLegendView = mainWindow.MapLegendView; + + gui.ViewHost.AddDocumentView(view1); + gui.ViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + + // When + gui.ViewHost.Remove(view1); + + // Then + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + } + + mocks.VerifyAll(); + } + + private static IMapControl GetMapControl(MapLegendView mapLegendView) + { + return TypeUtils.GetProperty(mapLegendView, "MapControl"); + } } } \ No newline at end of file Index: Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj =================================================================== diff -u -ra0c510a8873c29a3f58fe45351565ea7ee72a778 -r89e16fb45c79e575b0c335e71705694a9dac87c8 --- Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj (.../Core.Gui.TestUtil.csproj) (revision a0c510a8873c29a3f58fe45351565ea7ee72a778) +++ Core/Gui/test/Core.Gui.TestUtil/Core.Gui.TestUtil.csproj (.../Core.Gui.TestUtil.csproj) (revision 89e16fb45c79e575b0c335e71705694a9dac87c8) @@ -8,6 +8,7 @@ + Index: Core/Gui/test/Core.Gui.TestUtil/Map/TestMapView.cs =================================================================== diff -u --- Core/Gui/test/Core.Gui.TestUtil/Map/TestMapView.cs (revision 0) +++ Core/Gui/test/Core.Gui.TestUtil/Map/TestMapView.cs (revision 89e16fb45c79e575b0c335e71705694a9dac87c8) @@ -0,0 +1,85 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Windows.Forms; +using Core.Common.Base.Geometry; +using Core.Components.DotSpatial.Forms; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; + +namespace Core.Gui.TestUtil.Map +{ + /// + /// Simple implementation which can be used in tests. + /// + public class TestMapView : Control, IMapView + { + private readonly MapControl mapControl; + + /// + /// Creates a new instance of and initializes some . + /// + public TestMapView() + { + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(new MapPointData("test points") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(2, 2) + } + }) + }), + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(4, 4) + } + }) + }) + } + }); + + mapControl = new MapControl + { + Data = mapDataCollection + }; + + Controls.Add(mapControl); + } + + public object Data { get; set; } + + public IMapControl Map => mapControl; + } +} \ No newline at end of file