Index: Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs =================================================================== diff -u -r4f023f921130657163dbbad9b13e765e6d37cbb5 -r2e44b5f8b451848159b33dd4e8f53aba2130eb7b --- Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision 4f023f921130657163dbbad9b13e765e6d37cbb5) +++ Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision 2e44b5f8b451848159b33dd4e8f53aba2130eb7b) @@ -33,8 +33,10 @@ using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.Gui.TestUtil; +using Core.Common.Utils.Reflection; using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.PropertyClasses; using DotSpatial.Data; @@ -235,5 +237,65 @@ Dispatcher.CurrentDispatcher.InvokeShutdown(); } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_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 gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var view1 = new TestMapView(); + var view2 = new TestMapView(); + var plugin = new MapPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + // When + IViewHost guiViewHost = gui.ViewHost; + + guiViewHost.AddDocumentView(view1); + guiViewHost.AddDocumentView(view2); + + MapLegendView mapLegendView = guiViewHost.ToolViews.OfType().First(); + var mapRibbon = (MapRibbon) plugin.RibbonCommandHandler; + + // Precondition + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view2.Map, GetMapControl(mapRibbon)); + + // When + guiViewHost.BringToFront(view1); + + // Then + Assert.AreSame(view1.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view1.Map, GetMapControl(mapRibbon)); + + mocks.VerifyAll(); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + } + + private static IMapControl GetMapControl(MapRibbon mapRibbon) + { + return TypeUtils.GetProperty(mapRibbon, "Map"); + } + + private static IMapControl GetMapControl(MapLegendView mapLegendView) + { + return TypeUtils.GetProperty(mapLegendView, "MapControl"); + } } } \ No newline at end of file