Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.Designer.cs =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -r06ebe792539a9463beb33a304ffc9b33dbf2fb5a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.Designer.cs (.../WmtsConnectionDialog.Designer.cs) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.Designer.cs (.../WmtsConnectionDialog.Designer.cs) (revision 06ebe792539a9463beb33a304ffc9b33dbf2fb5a) @@ -37,36 +37,27 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WmtsConnectionDialog)); - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.nameTextBox = new System.Windows.Forms.TextBox(); this.urlTextBox = new System.Windows.Forms.TextBox(); this.nameLabel = new System.Windows.Forms.Label(); this.urlLabel = new System.Windows.Forms.Label(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.cancelButton = new System.Windows.Forms.Button(); this.actionButton = new System.Windows.Forms.Button(); - this.tableLayoutPanel1.SuspendLayout(); - this.tableLayoutPanel3.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // - // tableLayoutPanel1 + // tableLayoutPanel2 // - resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); - this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel3, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 2); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + resources.ApplyResources(this.tableLayoutPanel2, "tableLayoutPanel2"); + this.tableLayoutPanel2.Controls.Add(this.nameTextBox, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.urlTextBox, 1, 1); + this.tableLayoutPanel2.Controls.Add(this.nameLabel, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.urlLabel, 0, 1); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; // - // tableLayoutPanel3 - // - resources.ApplyResources(this.tableLayoutPanel3, "tableLayoutPanel3"); - this.tableLayoutPanel3.Controls.Add(this.nameTextBox, 1, 0); - this.tableLayoutPanel3.Controls.Add(this.urlTextBox, 1, 1); - this.tableLayoutPanel3.Controls.Add(this.nameLabel, 0, 0); - this.tableLayoutPanel3.Controls.Add(this.urlLabel, 0, 1); - this.tableLayoutPanel3.Name = "tableLayoutPanel3"; - // // nameTextBox // resources.ApplyResources(this.nameTextBox, "nameTextBox"); @@ -90,7 +81,6 @@ // flowLayoutPanel1 // resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1"); - this.tableLayoutPanel1.SetColumnSpan(this.flowLayoutPanel1, 2); this.flowLayoutPanel1.Controls.Add(this.cancelButton); this.flowLayoutPanel1.Controls.Add(this.actionButton); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; @@ -111,26 +101,24 @@ // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.tableLayoutPanel1); + this.Controls.Add(this.tableLayoutPanel2); + this.Controls.Add(this.flowLayoutPanel1); this.Name = "WmtsConnectionDialog"; - this.tableLayoutPanel1.ResumeLayout(false); - this.tableLayoutPanel1.PerformLayout(); - this.tableLayoutPanel3.ResumeLayout(false); - this.tableLayoutPanel3.PerformLayout(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); this.flowLayoutPanel1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } #endregion - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.TextBox urlTextBox; private System.Windows.Forms.TextBox nameTextBox; private System.Windows.Forms.Button actionButton; private System.Windows.Forms.Button cancelButton; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.Label nameLabel; private System.Windows.Forms.Label urlLabel; } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.cs =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -r06ebe792539a9463beb33a304ffc9b33dbf2fb5a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.cs (.../WmtsConnectionDialog.cs) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.cs (.../WmtsConnectionDialog.cs) (revision 06ebe792539a9463beb33a304ffc9b33dbf2fb5a) @@ -39,23 +39,19 @@ : base(dialogParent, CoreCommonGuiResources.RenameIcon, 250, 150) { InitializeComponent(); + UpdateActionButton(); + InitializeEventHandlers(); } - public string WmtsConnectionName - { - get - { - return nameTextBox.Text; - } - } + /// + /// Gets the name that was set in the dialog. + /// + public string WmtsConnectionName { get; private set; } - public string WmtsConnectionUrl - { - get - { - return urlTextBox.Text; - } - } + /// + /// Gets the URL that was set in the dialog. + /// + public string WmtsConnectionUrl { get; private set; } protected override void Dispose(bool disposing) { @@ -70,5 +66,40 @@ { return cancelButton; } + + private void UpdateActionButton() + { + actionButton.Enabled = !(string.IsNullOrWhiteSpace(nameTextBox.Text) || string.IsNullOrWhiteSpace(urlTextBox.Text)); + } + + #region Event handling + + private void InitializeEventHandlers() + { + actionButton.Click += ActionButton_Click; + nameTextBox.TextChanged += NameTextbox_Changed; + urlTextBox.TextChanged += UrlTextbox_Changed; + } + + private void NameTextbox_Changed(object sender, EventArgs e) + { + UpdateActionButton(); + } + + private void UrlTextbox_Changed(object sender, EventArgs e) + { + UpdateActionButton(); + } + + private void ActionButton_Click(object sender, EventArgs e) + { + WmtsConnectionName = nameTextBox.Text; + WmtsConnectionUrl = urlTextBox.Text; + + DialogResult = DialogResult.OK; + Close(); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.resx =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -r06ebe792539a9463beb33a304ffc9b33dbf2fb5a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.resx (.../WmtsConnectionDialog.resx) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.resx (.../WmtsConnectionDialog.resx) (revision 06ebe792539a9463beb33a304ffc9b33dbf2fb5a) @@ -118,21 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - 1 - - - True - - + 2 - - Fill + + Top, Left, Right @@ -141,11 +132,14 @@ 6, 3, 6, 3 + + 50, 4 + - 308, 20 + 288, 20 - 3 + 1 nameTextBox @@ -154,22 +148,25 @@ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tableLayoutPanel3 + tableLayoutPanel2 0 - - Fill + + Top, Left, Right 79, 29 6, 3, 6, 3 + + 50, 4 + - 308, 20 + 288, 20 2 @@ -181,7 +178,7 @@ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tableLayoutPanel3 + tableLayoutPanel2 1 @@ -199,7 +196,7 @@ 67, 13 - 4 + 5 Omschrijving @@ -211,7 +208,7 @@ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tableLayoutPanel3 + tableLayoutPanel2 2 @@ -229,7 +226,7 @@ 29, 13 - 5 + 6 URL @@ -241,52 +238,52 @@ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tableLayoutPanel3 + tableLayoutPanel2 3 - + Fill - - 3, 3 + + 0, 0 - - 1 + + 3 - - 393, 52 + + 373, 113 - + 0 - - tableLayoutPanel3 + + tableLayoutPanel2 - + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tableLayoutPanel1 + + $this - + 0 - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="nameTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="urlTextBox" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="nameLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="urlLabel" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,AutoSize,0" /><Rows Styles="AutoSize,0,AutoSize,0" /></TableLayoutSettings> + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="nameTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="urlTextBox" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="nameLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="urlLabel" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> True - 315, 3 + 295, 3 75, 23 - 5 + 4 Annuleren @@ -304,13 +301,13 @@ 0 - 234, 3 + 214, 3 75, 23 - 4 + 3 Toevoegen @@ -331,13 +328,13 @@ Bottom - 3, 112 + 0, 113 Yes - 393, 29 + 373, 29 2 @@ -349,49 +346,19 @@ System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tableLayoutPanel1 + $this 1 - - Fill - - - 0, 0 - - - 1 - - - 399, 144 - - - 1 - - - tableLayoutPanel1 - - - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="tableLayoutPanel3" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="flowLayoutPanel1" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /></Controls><Columns Styles="AutoSize,0" /><Rows Styles="AutoSize,0,Absolute,0,AutoSize,0" /></TableLayoutSettings> - True 6, 13 - 399, 144 + 373, 142 WmtsConnectionDialog Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -r06ebe792539a9463beb33a304ffc9b33dbf2fb5a --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/BackgroundMapDataSelectionDialogTest.cs (.../BackgroundMapDataSelectionDialogTest.cs) (revision 06ebe792539a9463beb33a304ffc9b33dbf2fb5a) @@ -111,12 +111,12 @@ { // Given Button cancelButton = null; + DialogBoxHandler = (name, wnd) => { - using (var openedDialog = new FormTester(name)) + using (new FormTester(name)) { - var form = (Form) openedDialog.TheObject; - var button = new ButtonTester("cancelButton", form); + var button = new ButtonTester("cancelButton", name); cancelButton = (Button) button.TheObject; button.Click(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsConnectionDialogTest.cs =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -r06ebe792539a9463beb33a304ffc9b33dbf2fb5a --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsConnectionDialogTest.cs (.../WmtsConnectionDialogTest.cs) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsConnectionDialogTest.cs (.../WmtsConnectionDialogTest.cs) (revision 06ebe792539a9463beb33a304ffc9b33dbf2fb5a) @@ -31,7 +31,7 @@ namespace Ringtoets.Integration.Forms.Test.Views { [TestFixture] - public class WmtsConnectionDialogTest :NUnitFormTest + public class WmtsConnectionDialogTest : NUnitFormTest { [Test] public void Constructor_WithoutDialogParent_ThrowsArgumentNullException() @@ -45,7 +45,7 @@ } [Test] - public void WmtsConnectionAddDialog_WithDialogParent_ExpectedProperties() + public void WmtsConnection_WithDialogParent_ExpectedProperties() { // Setup var mocks = new MockRepository(); @@ -57,24 +57,25 @@ { // Assert Assert.IsInstanceOf(dialog); - Assert.IsEmpty(dialog.WmtsConnectionName); - Assert.IsEmpty(dialog.WmtsConnectionUrl); + Assert.IsNull(dialog.WmtsConnectionName); + Assert.IsNull(dialog.WmtsConnectionUrl); var nameLabel = new LabelTester("nameLabel", dialog); Assert.AreEqual("Omschrijving", nameLabel.Text); - + var urlLabel = new LabelTester("urlLabel", dialog); Assert.AreEqual("URL", urlLabel.Text); - - var actionButton = new ButtonTester("actionButton", dialog); + + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; Assert.AreEqual("Toevoegen", actionButton.Text); - + Assert.IsFalse(actionButton.Enabled); + var cancelButton = new ButtonTester("cancelButton", dialog); Assert.AreEqual("Annuleren", cancelButton.Text); - + var nameTextBox = new TextBoxTester("nameTextBox", dialog); Assert.IsEmpty(nameTextBox.Text); - + var urlTextBox = new TextBoxTester("urlTextBox", dialog); Assert.IsEmpty(urlTextBox.Text); } @@ -89,7 +90,7 @@ // Setup DialogBoxHandler = (name, wnd) => { - using (new FormTester(name)){} + using (new FormTester(name)) {} }; using (var dialogParent = new Form()) @@ -105,6 +106,134 @@ } [Test] + [Apartment(ApartmentState.STA)] + public void ActionButton_WithoutValidText_ButtonIsDisabled( + [Values("", " ", null)] string name, + [Values("", " ", null)] string url) + { + // Setup + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", dialog).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", dialog).TheObject; + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + + // Call + nameTextBox.Text = name; + urlTextBox.Text = url; + + // Assert + Assert.IsFalse(actionButton.Enabled); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ActionButton_WithValidText_ButtonIsEnabled() + { + // Setup + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", dialog).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", dialog).TheObject; + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + + // Call + nameTextBox.Text = @"nameTextBox"; + urlTextBox.Text = @"urlTextBox"; + + // Assert + Assert.IsTrue(actionButton.Enabled); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ActionButtonCick_WithValidText_SetsPropertiesAndClosesForm() + { + // Setup + const string urltextbox = @"urlTextBox"; + const string nametextbox = @"nameTextBox"; + var dialogResult = DialogResult.None; + + DialogBoxHandler = (formName, wnd) => + { + using (var formTester = new FormTester(formName)) + { + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", formName).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", formName).TheObject; + nameTextBox.Text = nametextbox; + urlTextBox.Text = urltextbox; + + var actionButton = new ButtonTester("actionButton", formName); + + // Call + actionButton.Click(); + + dialogResult = formTester.DialogResult; + } + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + // Assert + Assert.AreEqual(nametextbox, dialog.WmtsConnectionName); + Assert.AreEqual(urltextbox, dialog.WmtsConnectionUrl); + Assert.AreEqual(DialogResult.OK, dialogResult); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenValidDialog_WhenCancelPressed_ThenWmtsConnectionDataNull() + { + // Given + Button cancelButton = null; + + DialogBoxHandler = (name, wnd) => + { + using (new FormTester(name)) + { + var button = new ButtonTester("cancelButton", name); + cancelButton = (Button) button.TheObject; + button.Click(); + } + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + // When + dialog.ShowDialog(); + + // Then + Assert.IsNull(dialog.WmtsConnectionName); + Assert.IsNull(dialog.WmtsConnectionUrl); + + Assert.AreEqual(dialog.CancelButton, cancelButton); + } + } + + [Test] public void Dispose_AlreadyDisposed_DoesNotThrowException() { // Setup