Index: Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs =================================================================== diff -u -r08432b412fb47916669a52095d9e20afb24994c6 -r0e50500bb017c821970b286992f14b03dca0e69d --- Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs (.../WellKnownMapDataControl.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) +++ Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs (.../WellKnownMapDataControl.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Components.Gis.Data; @@ -74,8 +73,8 @@ return; } DataGridViewRow dataGridViewRow = dataGridViewControl.Rows.OfType() - .FirstOrDefault(row => IsMatch((WellKnownTileSourceMapData) row.DataBoundItem, - activeWellKnownTileSourceMapData)); + .FirstOrDefault(row => IsMatch((WellKnownTileSourceMapData) row.DataBoundItem, + activeWellKnownTileSourceMapData)); if (dataGridViewRow == null) { return; @@ -86,15 +85,24 @@ private static bool IsMatch(WellKnownTileSourceMapData mapData, WellKnownTileSourceMapData otherMapData) { - return mapData.TileSource == otherMapData.TileSource && string.Equals(mapData.Name,otherMapData.Name); + return mapData.TileSource == otherMapData.TileSource && string.Equals(mapData.Name, otherMapData.Name); } + #region Event handlers + + private void InitializeEventHandlers() + { + dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewCurrentCellChangedHandler); + } + + #endregion + #region DataGridView private void InitializeDataGridView() { - dataGridViewControl.AddTextBoxColumn(nameof(WellKnownTileSourceMapData.Name), Resources.WellKnownTileSourceMapData_Description, - true, DataGridViewAutoSizeColumnMode.Fill); + dataGridViewControl.AddTextBoxColumn(nameof(WellKnownTileSourceMapData.Name), Resources.WellKnownTileSourceMapData_Description, + true, DataGridViewAutoSizeColumnMode.Fill); UpdateDataGridViewDataSource(); } @@ -109,7 +117,7 @@ private static WellKnownTileSourceMapData[] GetSortedWellKnownTileSourceMapDatas() { var enumValues = (WellKnownTileSource[]) Enum.GetValues(typeof(WellKnownTileSource)); - return enumValues.Select(enumValue => new WellKnownTileSourceMapData(enumValue)).ToList().OrderBy(w => w.Name).ToArray(); + return enumValues.Select(enumValue => new WellKnownTileSourceMapData(enumValue)).ToList().OrderBy(w => w.Name).ToArray(); } private void DataGridViewCurrentCellChangedHandler(object sender, EventArgs e) @@ -118,14 +126,5 @@ } #endregion - - #region Event handlers - - private void InitializeEventHandlers() - { - dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewCurrentCellChangedHandler); - } - #endregion - } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs =================================================================== diff -u -r08432b412fb47916669a52095d9e20afb24994c6 -r0e50500bb017c821970b286992f14b03dca0e69d --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs (.../BackgroundMapDataSelectionDialog.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs (.../BackgroundMapDataSelectionDialog.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -37,28 +37,33 @@ /// public partial class BackgroundMapDataSelectionDialog : DialogBase { - private readonly List mapDatas; + private readonly HashSet mapDatas; private IBackgroundMapDataSelectionControl currentBackgroundMapDataSelectionControl; + private bool mapLayerComboBoxUpdating; /// /// Creates a new instance of . /// /// The parent of the dialog. /// The active map data or null if none is active. /// Thrown when is null. - public BackgroundMapDataSelectionDialog(IWin32Window dialogParent, WmtsMapData mapData) + public BackgroundMapDataSelectionDialog(IWin32Window dialogParent, ImageBasedMapData mapData) : base(dialogParent, RingtoetsCommonFormsResources.SelectionDialogIcon, 500, 350) { - mapDatas = new List + mapDatas = new HashSet { - new WmtsLocationControl(mapData, new BruTileWmtsCapabilityFactory()) + new WellKnownMapDataControl(mapData as WellKnownTileSourceMapData), + new WmtsLocationControl(mapData as WmtsMapData, new BruTileWmtsCapabilityFactory()) }; SelectedMapData = mapData; InitializeComponent(); InitializeButtons(); InitializeComboBox(); + + IBackgroundMapDataSelectionControl controlToSelect = GetBackgroundMapDataControlToSelect(mapData); + PreSelectComboBox(controlToSelect); } /// @@ -75,6 +80,19 @@ base.Dispose(disposing); } + private IBackgroundMapDataSelectionControl GetBackgroundMapDataControlToSelect(ImageBasedMapData mapData) + { + if (mapData is WellKnownTileSourceMapData) + { + return mapDatas.OfType().First(); + } + if (mapData is WmtsMapData) + { + return mapDatas.OfType().First(); + } + return mapDatas.First(); + } + private void UpdatePropertiesGroupBox(IBackgroundMapDataSelectionControl newBackgroundMapDataSelectionControl) { if (currentBackgroundMapDataSelectionControl != null) @@ -114,17 +132,23 @@ private void InitializeComboBox() { - UpdateComboBoxDataSource(); - - mapLayerComboBox.Enabled = false; + mapLayerComboBox.ValueMember = nameof(IBackgroundMapDataSelectionControl.UserControl); } - private void UpdateComboBoxDataSource() + private void PreSelectComboBox(IBackgroundMapDataSelectionControl controlToSelect) { - mapLayerComboBox.DataSource = mapDatas; + mapLayerComboBox.BeginUpdate(); + + mapLayerComboBoxUpdating = true; + mapLayerComboBox.DataSource = mapDatas.ToArray(); mapLayerComboBox.DisplayMember = nameof(IBackgroundMapDataSelectionControl.DisplayName); + mapLayerComboBox.SelectedItem = null; + mapLayerComboBoxUpdating = false; - currentBackgroundMapDataSelectionControl = mapDatas.FirstOrDefault(); + mapLayerComboBox.EndUpdate(); + + mapLayerComboBox.SelectedItem = controlToSelect; + currentBackgroundMapDataSelectionControl = controlToSelect; } #endregion @@ -145,13 +169,12 @@ private void MapLayerComboBox_OnSelectedIndexChanged(object sender, EventArgs eventArgs) { - var selectedItem = mapLayerComboBox.SelectedItem as IBackgroundMapDataSelectionControl; - if (selectedItem == null) + if (mapLayerComboBoxUpdating || mapLayerComboBox.SelectedIndex == -1) { return; } - UpdatePropertiesGroupBox(selectedItem); + UpdatePropertiesGroupBox((IBackgroundMapDataSelectionControl) mapLayerComboBox.SelectedItem); } #endregion Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4 -r0e50500bb017c821970b286992f14b03dca0e69d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -918,6 +918,10 @@ private static void SetSelectedMapData(IAssessmentSection assessmentSection, ImageBasedMapData selectedMapData) { + if (selectedMapData is WellKnownTileSourceMapData) + { + return; + } assessmentSection.BackgroundData.Name = string.Empty; assessmentSection.BackgroundData.IsVisible = false; assessmentSection.BackgroundData.Parameters.Clear(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs =================================================================== diff -u -r5be1ab23e8cdc4eacc23d0ba5b4f921d6be4a9c1 -r0e50500bb017c821970b286992f14b03dca0e69d --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 5be1ab23e8cdc4eacc23d0ba5b4f921d6be4a9c1) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -20,18 +20,20 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Threading; using System.Windows.Forms; using BruTile; +using Core.Common.Controls.DataGrid; using Core.Common.Controls.Dialogs; +using Core.Common.Gui.TestUtil.Settings; using Core.Common.TestUtil; using Core.Components.BruTile.Configurations; using Core.Components.BruTile.TestUtil; using Core.Components.Gis.Data; using Core.Components.Gis.Forms.Views; +using Core.Components.Gis.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -64,10 +66,10 @@ { // Setup mockRepository.ReplayAll(); - WmtsMapData mapData = WmtsMapData.CreateDefaultPdokMapData(); + var imageBasedMapData = new TestImageBasedMapData("someMapData", true); // Call - TestDelegate test = () => new BackgroundMapDataSelectionDialog(null, mapData); + TestDelegate test = () => new BackgroundMapDataSelectionDialog(null, imageBasedMapData); // Assert string parameter = Assert.Throws(test).ParamName; @@ -85,7 +87,28 @@ using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null)) { // Assert + Assert.IsInstanceOf(dialog); + Assert.AreEqual("Selecteer achtergrondkaart", dialog.Text); Assert.IsNull(dialog.SelectedMapData); + + Icon icon = BitmapToIcon(RingtoetsCommonFormsResources.SelectionDialogIcon); + Bitmap expectedImage = icon.ToBitmap(); + Bitmap actualImage = dialog.Icon.ToBitmap(); + TestHelper.AssertImagesAreEqual(expectedImage, actualImage); + + var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + Assert.AreEqual(ComboBoxStyle.DropDownList, mapLayers.DropDownStyle); + Assert.AreEqual("DisplayName", mapLayers.DisplayMember); + Assert.IsTrue(mapLayers.Sorted); + + var backgroundMapDataSelectionControls = (IBackgroundMapDataSelectionControl[]) mapLayers.DataSource; + Assert.AreEqual(2, backgroundMapDataSelectionControls.Length); + Assert.IsInstanceOf(backgroundMapDataSelectionControls[0]); + Assert.IsInstanceOf(backgroundMapDataSelectionControls[1]); + + var groupBoxProperties = (GroupBox) new ControlTester("propertiesGroupBox", dialog).TheObject; + Assert.AreEqual(1, groupBoxProperties.Controls.Count); + Assert.AreSame(backgroundMapDataSelectionControls[0], groupBoxProperties.Controls[0]); } } @@ -94,45 +117,69 @@ { // Setup mockRepository.ReplayAll(); - WmtsMapData mapData = WmtsMapData.CreateDefaultPdokMapData(); + var imageBasedMapData = new TestImageBasedMapData("someMapData", true); // Call - TestDelegate test = () => new BackgroundMapDataSelectionDialog(null, mapData); + TestDelegate test = () => new BackgroundMapDataSelectionDialog(null, imageBasedMapData); // Assert string parameter = Assert.Throws(test).ParamName; Assert.AreEqual("dialogParent", parameter); } [Test] - public void MapDataConstructor_WithParents_DefaultProperties() + public void MapDataConstructor_WithWmtsMapData_DefaultProperties() { // Setup + var dialogParent = mockRepository.Stub(); WmtsMapData mapData = WmtsMapData.CreateDefaultPdokMapData(); tileFactory.Expect(tf => tf.GetWmtsTileSources(mapData.SourceCapabilitiesUrl)).Return(Enumerable.Empty()); mockRepository.ReplayAll(); using (new UseCustomTileSourceFactoryConfig(tileFactory)) - using (var dialogParent = new Form()) { // Call using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, mapData)) { // Assert - Assert.IsInstanceOf(dialog); - Assert.AreEqual("Selecteer achtergrondkaart", dialog.Text); Assert.AreSame(mapData, dialog.SelectedMapData); + var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + Assert.IsInstanceOf(mapLayers.SelectedItem); - Icon icon = BitmapToIcon(RingtoetsCommonFormsResources.SelectionDialogIcon); - Bitmap expectedImage = icon.ToBitmap(); - Bitmap actualImage = dialog.Icon.ToBitmap(); - TestHelper.AssertImagesAreEqual(expectedImage, actualImage); + var groupBoxProperties = (GroupBox) new ControlTester("propertiesGroupBox", dialog).TheObject; + Assert.AreEqual(1, groupBoxProperties.Controls.Count); + Assert.AreSame(mapLayers.SelectedItem, groupBoxProperties.Controls[0]); + } + } + } + [Test] + public void MapDataConstructor_WithWellKnownMapData_DefaultProperties() + { + // Setup + var dialogParent = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var random = new Random(124); + var mapData = new WellKnownTileSourceMapData(random.NextEnumValue()); + + using (new UseCustomTileSourceFactoryConfig(tileFactory)) + { + // Call + using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, mapData)) + { + // Assert + Assert.AreSame(mapData, dialog.SelectedMapData); var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; Assert.AreEqual(ComboBoxStyle.DropDownList, mapLayers.DropDownStyle); - Assert.IsInstanceOf>(mapLayers.DataSource); + Assert.IsInstanceOf(mapLayers.DataSource); Assert.AreEqual("DisplayName", mapLayers.DisplayMember); Assert.IsTrue(mapLayers.Sorted); + Assert.IsInstanceOf(mapLayers.SelectedItem); + + var groupBoxProperties = (GroupBox) new ControlTester("propertiesGroupBox", dialog).TheObject; + Assert.AreEqual(1, groupBoxProperties.Controls.Count); + Assert.AreSame(mapLayers.SelectedItem, groupBoxProperties.Controls[0]); } } } @@ -159,14 +206,14 @@ Assert.AreEqual("Type kaartlaag", mapLayerLabel.Text); var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; - Assert.IsFalse(mapLayers.Enabled); + Assert.IsTrue(mapLayers.Enabled); var groupBoxProperties = new ControlTester("propertiesGroupBox", dialog); Assert.AreEqual("Eigenschappen", groupBoxProperties.Text); Button buttonSelect = (Button) new ButtonTester("selectButton", dialog).TheObject; Assert.AreEqual("Selecteren", buttonSelect.Text); - Assert.IsFalse(buttonSelect.Enabled); + Assert.IsTrue(buttonSelect.Enabled); Button buttonCancel = (Button) new ButtonTester("cancelButton", dialog).TheObject; Assert.AreEqual("Annuleren", buttonCancel.Text); @@ -198,15 +245,135 @@ using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null)) { // When - dialog.ShowDialog(); + DialogResult dialogResult = dialog.ShowDialog(); // Then + Assert.AreEqual(DialogResult.Cancel, dialogResult); Assert.IsNull(dialog.SelectedMapData); Assert.AreEqual(dialog.CancelButton, cancelButton); } } [Test] + [Apartment(ApartmentState.STA)] + public void GivenValidDialog_WhenSelectPressed_ThenSelectedMapDataSet() + { + // Given + mockRepository.ReplayAll(); + + DialogBoxHandler = (name, wnd) => + { + using (new FormTester(name)) + { + var button = new ButtonTester("selectButton", name); + button.Click(); + } + }; + + using (var dialogParent = new Form()) + using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null)) + { + // When + DialogResult dialogResult = dialog.ShowDialog(); + + // Then + Assert.AreEqual(DialogResult.OK, dialogResult); + Assert.IsNotNull(dialog.SelectedMapData); + } + } + + [Test] + public void GivenValidDialog_WhenControlSwitched_ThenDoesNotListenToEventOfOldControl() + { + // Given + WmtsMapData activeWmtsMapData = WmtsMapData.CreateDefaultPdokMapData(); + + var capabilities = new[] + { + new TestWmtsTileSource(WmtsMapData.CreateAlternativePdokMapData()), + new TestWmtsTileSource(activeWmtsMapData) + }; + + tileFactory.Expect(tf => tf.GetWmtsTileSources(activeWmtsMapData.SourceCapabilitiesUrl)).Return(capabilities); + mockRepository.ReplayAll(); + + var wmtsLocationControlSelectedMapDataChanged = 0; + + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "noConfig") + })) + using (new UseCustomTileSourceFactoryConfig(tileFactory)) + using (var dialogParent = new Form()) + using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, activeWmtsMapData)) + { + dialog.Show(); + + var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + var wmtsLocationControl = (WmtsLocationControl) comboBox.SelectedItem; + var wmtsDataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; + wmtsLocationControl.SelectedMapDataChanged += (sender, args) => { wmtsLocationControlSelectedMapDataChanged++; }; + + comboBox.SelectedItem = GetComboBoxItem(comboBox); + + // When + wmtsDataGridViewControl.SetCurrentCell(wmtsDataGridViewControl.GetCell(0, 0)); + var button = new ButtonTester("selectButton", dialog); + button.Click(); + + // Then + Assert.IsInstanceOf(dialog.SelectedMapData); + Assert.AreEqual(1, wmtsLocationControlSelectedMapDataChanged); + } + } + + [Test] + public void GivenValidDialog_WhenControlSwitched_ThenListenToEventOfNewControl() + { + // Given + WmtsMapData activeWmtsMapData = WmtsMapData.CreateDefaultPdokMapData(); + + var capabilities = new[] + { + new TestWmtsTileSource(WmtsMapData.CreateAlternativePdokMapData()), + new TestWmtsTileSource(activeWmtsMapData) + }; + + tileFactory.Expect(tf => tf.GetWmtsTileSources(activeWmtsMapData.SourceCapabilitiesUrl)).Return(capabilities); + mockRepository.ReplayAll(); + + var wellKnownSelectedMapDataChanged = 0; + + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "noConfig") + })) + using (new UseCustomTileSourceFactoryConfig(tileFactory)) + using (var dialogParent = new Form()) + using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, activeWmtsMapData)) + { + dialog.Show(); + + var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + var wellKnownControl = GetComboBoxItem(comboBox); + + comboBox.SelectedItem = wellKnownControl; + + var wellKnownDataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; + wellKnownControl.SelectedMapDataChanged += (sender, args) => { wellKnownSelectedMapDataChanged++; }; + + // When + wellKnownDataGridViewControl.SetCurrentCell(wellKnownDataGridViewControl.GetCell(4, 0)); + var button = new ButtonTester("selectButton", dialog); + button.Click(); + + // Then + Assert.IsInstanceOf(dialog.SelectedMapData); + Assert.AreEqual(1, wellKnownSelectedMapDataChanged); + } + } + + [Test] public void Dispose_DisposedAlreadyCalled_DoesNotThrowException() { // Setup @@ -226,6 +393,11 @@ Assert.DoesNotThrow(call); } + private static T GetComboBoxItem(ComboBox comboBox) + { + return ((IBackgroundMapDataSelectionControl[]) comboBox.DataSource).OfType().First(); + } + private static Icon BitmapToIcon(Bitmap icon) { return Icon.FromHandle(icon.GetHicon()); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4 -r0e50500bb017c821970b286992f14b03dca0e69d --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -137,6 +137,10 @@ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Utils + + {26214BD0-DAFB-4CFC-8EB2-80C5D53C859E} + Core.Common.Gui.TestUtil + {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs =================================================================== diff -u -r7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4 -r0e50500bb017c821970b286992f14b03dca0e69d --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs (.../BackgroundDataTreeNodeInfoTest.cs) (revision 7a4f8ff71ae5f81177fe5ff9cd78fdc7f24c69f4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/BackgroundDataTreeNodeInfoTest.cs (.../BackgroundDataTreeNodeInfoTest.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) @@ -23,6 +23,7 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Controls.DataGrid; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.Commands; @@ -31,6 +32,7 @@ using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms.Views; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -347,7 +349,7 @@ } [Test] - public void GivenMapDataSet_WhenSelectingValidMapDataFromContextMenu_ThenMapDataSetAndNotifiesObserver() + public void GivenMapDataSet_WhenSelectingValidWmtsMapDataFromContextMenu_ThenMapDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); @@ -412,6 +414,71 @@ } [Test] + public void GivenMapDataSet_WhenSelectingValidWellKnownMapDataFromContextMenu_ThenMapDataNotSetAndNoNotifiesObserver() + { + // Given + var mockRepository = new MockRepository(); + var assessmentSectionObserver = mockRepository.StrictMock(); + var backgroundMapDataObserver = mockRepository.StrictMock(); + + WmtsMapData mapData = WmtsMapData.CreateUnconnectedMapData(); + + var assessmentSection = new ObservableTestAssessmentSectionStub(); + + using (var treeViewControl = new TreeViewControl()) + using (var plugin = new RingtoetsPlugin()) + { + var viewCommands = mockRepository.Stub(); + var mainWindow = mockRepository.Stub(); + + var gui = mockRepository.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + gui.Stub(cmp => cmp.Get(assessmentSection.BackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mockRepository.ReplayAll(); + + assessmentSection.Attach(assessmentSectionObserver); + assessmentSection.BackgroundData.Attach(backgroundMapDataObserver); + assessmentSection.BackgroundData.Name = mapData.Name; + assessmentSection.BackgroundData.IsVisible = mapData.IsVisible; + assessmentSection.BackgroundData.IsConfigured = mapData.IsConfigured; + assessmentSection.BackgroundData.Transparency = mapData.Transparency; + assessmentSection.BackgroundData.BackgroundMapDataType = BackgroundMapDataType.Wmts; + assessmentSection.BackgroundData.Parameters["SourceCapabilitiesUrl"] = mapData.SourceCapabilitiesUrl; + assessmentSection.BackgroundData.Parameters["SelectedCapabilityIdentifier"] = mapData.SelectedCapabilityIdentifier; + assessmentSection.BackgroundData.Parameters["PreferredFormat"] = mapData.PreferredFormat; + + DialogBoxHandler = (name, wnd) => + { + var dialog = (BackgroundMapDataSelectionDialog)new FormTester(name).TheObject; + + var comboBox = (ComboBox)new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + comboBox.SelectedItem = ((IBackgroundMapDataSelectionControl[])comboBox.DataSource).OfType().First(); + var wmtsDataGridViewControl = (DataGridViewControl)new ControlTester("dataGridViewControl", dialog).TheObject; + wmtsDataGridViewControl.SetCurrentCell(wmtsDataGridViewControl.GetCell(1, 0)); + + var button = new ButtonTester("selectButton", dialog); + button.Click(); + dialog.Close(); + }; + + TreeNodeInfo info = GetInfo(plugin); + plugin.Gui = gui; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(assessmentSection.BackgroundData, assessmentSection, treeViewControl)) + { + // When + contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); + + // Then + } + } + mockRepository.VerifyAll(); + } + + [Test] public void GivenMapDataSet_WhenSelectingMapDataFromContextMenuCancelled_ThenNoObserversNotified() { // Given