Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs =================================================================== diff -u -r0e50500bb017c821970b286992f14b03dca0e69d -r7dcf169799c42e16f0badadb62624806c4f7fb00 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 0e50500bb017c821970b286992f14b03dca0e69d) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 7dcf169799c42e16f0badadb62624806c4f7fb00) @@ -62,21 +62,6 @@ } [Test] - public void Constructor_WithoutParent_ThrowsArgumentNullException() - { - // Setup - mockRepository.ReplayAll(); - var imageBasedMapData = new TestImageBasedMapData("someMapData", true); - - // Call - TestDelegate test = () => new BackgroundMapDataSelectionDialog(null, imageBasedMapData); - - // Assert - string parameter = Assert.Throws(test).ParamName; - Assert.AreEqual("dialogParent", parameter); - } - - [Test] public void Constructor_MapDataNull_DefaultProperties() { // Setup @@ -89,26 +74,13 @@ // 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]); + AssertMapDataControls(dialog); } } @@ -142,13 +114,7 @@ using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, mapData)) { // Assert - Assert.AreSame(mapData, dialog.SelectedMapData); - var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; - 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]); + AssertMapDataControls(dialog); } } } @@ -169,17 +135,7 @@ 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.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]); + AssertMapDataControls(dialog); } } } @@ -190,16 +146,12 @@ { // Setup mockRepository.ReplayAll(); - DialogBoxHandler = (name, wnd) => - { - using (new FormTester(name)) {} - }; using (var dialogParent = new Form()) using (var dialog = new BackgroundMapDataSelectionDialog(dialogParent, null)) { // Call - dialog.ShowDialog(); + dialog.Show(); // Assert var mapLayerLabel = new LabelTester("mapLayerLabel", dialog); @@ -315,14 +267,17 @@ wmtsLocationControl.SelectedMapDataChanged += (sender, args) => { wmtsLocationControlSelectedMapDataChanged++; }; comboBox.SelectedItem = GetComboBoxItem(comboBox); + var wellKnownDataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; + wellKnownDataGridViewControl.ClearCurrentCell(); + var button = (Button) new ButtonTester("selectButton", dialog).TheObject; + Assert.IsFalse(button.Enabled); + // When wmtsDataGridViewControl.SetCurrentCell(wmtsDataGridViewControl.GetCell(0, 0)); - var button = new ButtonTester("selectButton", dialog); - button.Click(); // Then - Assert.IsInstanceOf(dialog.SelectedMapData); + Assert.IsFalse(button.Enabled); Assert.AreEqual(1, wmtsLocationControlSelectedMapDataChanged); } } @@ -393,6 +348,30 @@ Assert.DoesNotThrow(call); } + private static void AssertMapDataControls(BackgroundMapDataSelectionDialog dialog) + where T : UserControl, IBackgroundMapDataSelectionControl + { + var mapLayers = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; + Assert.AreEqual("DisplayName", mapLayers.DisplayMember); + Assert.AreEqual("UserControl", mapLayers.ValueMember); + Assert.AreEqual(ComboBoxStyle.DropDownList, mapLayers.DropDownStyle); + Assert.IsTrue(mapLayers.Sorted); + Assert.IsInstanceOf(mapLayers.SelectedItem); + + var backgroundMapDataSelectionControls = (IBackgroundMapDataSelectionControl[]) mapLayers.DataSource; + Assert.AreEqual(2, backgroundMapDataSelectionControls.Length); + Assert.IsInstanceOf(backgroundMapDataSelectionControls[0]); + Assert.IsInstanceOf(backgroundMapDataSelectionControls[1]); + + Assert.IsInstanceOf(mapLayers.DataSource); + Assert.AreEqual("DisplayName", mapLayers.DisplayMember); + + var groupBoxProperties = (GroupBox) new ControlTester("propertiesGroupBox", dialog).TheObject; + Assert.AreEqual(DockStyle.Fill, groupBoxProperties.Dock); + Assert.AreEqual(1, groupBoxProperties.Controls.Count); + Assert.AreSame(mapLayers.SelectedItem, groupBoxProperties.Controls[0]); + } + private static T GetComboBoxItem(ComboBox comboBox) { return ((IBackgroundMapDataSelectionControl[]) comboBox.DataSource).OfType().First();