Index: Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.Designer.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.Designer.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.Designer.cs (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -0,0 +1,140 @@
+// Copyright (C) Stichting Deltares and State of the Netherlands 2023. 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 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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.ComponentModel;
+using System.Windows.Forms;
+
+namespace Riskeer.Common.Forms.Controls
+{
+ partial class LengthEffectSettingsControl
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private IContainer components = null;
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
+ this.parameterALabel = new System.Windows.Forms.Label();
+ this.lengthEffectNRoundedLabel = new System.Windows.Forms.Label();
+ this.lengthEffectNRoundedTextBox = new System.Windows.Forms.TextBox();
+ this.parameterATextBox = new System.Windows.Forms.TextBox();
+ this.lengthEffectErrorProvider = new System.Windows.Forms.ErrorProvider(this);
+ ((System.ComponentModel.ISupportInitialize) (this.lengthEffectErrorProvider)).BeginInit();
+ this.tableLayoutPanel.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // tableLayoutPanel
+ //
+ this.tableLayoutPanel.ColumnCount = 2;
+ this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
+ this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
+ this.tableLayoutPanel.Controls.Add(this.parameterALabel, 0, 0);
+ this.tableLayoutPanel.Controls.Add(this.lengthEffectNRoundedLabel, 0, 1);
+ this.tableLayoutPanel.Controls.Add(this.lengthEffectNRoundedTextBox, 1, 1);
+ this.tableLayoutPanel.Controls.Add(this.parameterATextBox, 1, 0);
+ this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0);
+ this.tableLayoutPanel.Name = "tableLayoutPanel";
+ this.tableLayoutPanel.RowCount = 2;
+ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
+ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel.Size = new System.Drawing.Size(150, 150);
+ this.tableLayoutPanel.TabIndex = 0;
+ //
+ // parameterALabel
+ //
+ this.parameterALabel.AutoSize = true;
+ this.parameterALabel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.parameterALabel.Location = new System.Drawing.Point(3, 0);
+ this.parameterALabel.Name = "parameterALabel";
+ this.parameterALabel.Size = new System.Drawing.Size(35, 26);
+ this.parameterALabel.TabIndex = 0;
+ this.parameterALabel.Text = global::Riskeer.Common.Forms.Properties.Resources.LengthEffect_A_DisplayName;
+ this.parameterALabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // lengthEffectNRoundedLabel
+ //
+ this.lengthEffectNRoundedLabel.AutoSize = true;
+ this.lengthEffectNRoundedLabel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.lengthEffectNRoundedLabel.Location = new System.Drawing.Point(3, 26);
+ this.lengthEffectNRoundedLabel.Name = "lengthEffectNRoundedLabel";
+ this.lengthEffectNRoundedLabel.Size = new System.Drawing.Size(35, 124);
+ this.lengthEffectNRoundedLabel.TabIndex = 1;
+ this.lengthEffectNRoundedLabel.Text = global::Riskeer.Common.Forms.Properties.Resources.LengthEffect_RoundedNSection_DisplayName;
+ this.lengthEffectNRoundedLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // lengthEffectNRoundedTextBox
+ //
+ this.lengthEffectNRoundedTextBox.Dock = System.Windows.Forms.DockStyle.Left;
+ this.lengthEffectNRoundedTextBox.Enabled = false;
+ this.lengthEffectNRoundedTextBox.Location = new System.Drawing.Point(44, 29);
+ this.lengthEffectNRoundedTextBox.Name = "lengthEffectNRoundedTextBox";
+ this.lengthEffectNRoundedTextBox.Size = new System.Drawing.Size(69, 20);
+ this.lengthEffectNRoundedTextBox.TabIndex = 2;
+ //
+ // parameterATextBox
+ //
+ this.parameterATextBox.Dock = System.Windows.Forms.DockStyle.Left;
+ this.parameterATextBox.Location = new System.Drawing.Point(44, 3);
+ this.parameterATextBox.Name = "parameterATextBox";
+ this.parameterATextBox.Size = new System.Drawing.Size(69, 20);
+ this.parameterATextBox.TabIndex = 3;
+ this.parameterATextBox.Enabled = false;
+ this.parameterATextBox.KeyDown += ParameterATextBoxKeyDown;
+ this.parameterATextBox.Leave += ParameterATextBoxLeave;
+ //
+ // lengthEffectErrorProvider
+ //
+ this.lengthEffectErrorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;
+ this.lengthEffectErrorProvider.ContainerControl = this;
+ //
+ // LengthEffectSettingsControl
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.tableLayoutPanel);
+ this.Name = "LengthEffectSettingsControl";
+ this.tableLayoutPanel.ResumeLayout(false);
+ this.tableLayoutPanel.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize) (this.lengthEffectErrorProvider)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ private System.Windows.Forms.Label parameterALabel;
+ private System.Windows.Forms.Label lengthEffectNRoundedLabel;
+ private System.Windows.Forms.TextBox lengthEffectNRoundedTextBox;
+ private System.Windows.Forms.TextBox parameterATextBox;
+
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
+ private System.Windows.Forms.ErrorProvider lengthEffectErrorProvider;
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.cs (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -0,0 +1,195 @@
+// Copyright (C) Stichting Deltares and State of the Netherlands 2023. 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 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Base.Data;
+using Core.Common.Base.Exceptions;
+using Core.Common.Base.Helpers;
+using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.Probability;
+
+namespace Riskeer.Common.Forms.Controls
+{
+ ///
+ /// Control to display length effect properties.
+ ///
+ public partial class LengthEffectSettingsControl : UserControl
+ {
+ private const int lengthEffectNNrOfDecimals = 2;
+ private readonly double b;
+
+ private readonly Observer scenarioConfigurationObserver;
+ private ScenarioConfigurationPerFailureMechanismSection scenarioConfigurationPerFailureMechanismSection;
+
+ private bool isParameterAUpdating;
+
+ ///
+ /// Creates a new instance of
+ ///
+ public LengthEffectSettingsControl(double b)
+ {
+ this.b = b;
+
+ InitializeComponent();
+ scenarioConfigurationObserver = new Observer(UpdateLengthEffectData);
+ }
+
+ public void SetScenarioConfiguration(ScenarioConfigurationPerFailureMechanismSection scenarioConfiguration)
+ {
+ if (scenarioConfiguration == null)
+ {
+ throw new ArgumentNullException(nameof(scenarioConfiguration));
+ }
+
+ ClearLengthEffectErrorMessage();
+
+ scenarioConfigurationPerFailureMechanismSection = scenarioConfiguration;
+ scenarioConfigurationObserver.Observable = scenarioConfiguration;
+
+ UpdateLengthEffectData();
+
+ EnableControl();
+ }
+
+ ///
+ /// Clears the data on the control.
+ ///
+ public void ClearData()
+ {
+ isParameterAUpdating = true;
+ scenarioConfigurationPerFailureMechanismSection = null;
+
+ scenarioConfigurationObserver.Observable = scenarioConfigurationPerFailureMechanismSection;
+ ClearLengthEffectErrorMessage();
+ ClearLengthEffectData();
+
+ DisableControl();
+
+ isParameterAUpdating = false;
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ scenarioConfigurationObserver.Dispose();
+ }
+
+ base.Dispose(disposing);
+ }
+
+ private void ParameterATextBoxKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Enter)
+ {
+ parameterALabel.Focus(); // Focus on different component to raise a leave event on the text box
+ e.Handled = true;
+ }
+
+ if (e.KeyCode == Keys.Escape)
+ {
+ ClearLengthEffectErrorMessage();
+ UpdateLengthEffectData();
+ e.Handled = true;
+ }
+ }
+
+ private void ParameterATextBoxLeave(object sender, EventArgs e)
+ {
+ ClearLengthEffectErrorMessage();
+ ProcessParameterATextBox();
+ }
+
+ private void ProcessParameterATextBox()
+ {
+ if (isParameterAUpdating)
+ {
+ return;
+ }
+
+ try
+ {
+ scenarioConfigurationPerFailureMechanismSection.A = (RoundedDouble) DoubleParsingHelper.Parse(parameterATextBox.Text);
+ scenarioConfigurationPerFailureMechanismSection.NotifyObservers();
+
+ UpdateLengthEffectData();
+ }
+ catch (Exception exception) when (exception is ArgumentOutOfRangeException
+ || exception is DoubleParsingException)
+ {
+ ClearNRoundedData();
+ SetLengthEffectErrorMessage(exception.Message);
+ parameterATextBox.Focus();
+ }
+ }
+
+ private void ClearLengthEffectData()
+ {
+ parameterATextBox.Text = string.Empty;
+ ClearNRoundedData();
+ }
+
+ private void ClearNRoundedData()
+ {
+ lengthEffectNRoundedTextBox.Text = string.Empty;
+ }
+
+ private void UpdateLengthEffectData()
+ {
+ parameterATextBox.Text = scenarioConfigurationPerFailureMechanismSection.A.ToString();
+
+ double n = scenarioConfigurationPerFailureMechanismSection.GetN(b);
+ lengthEffectNRoundedTextBox.Text = new RoundedDouble(lengthEffectNNrOfDecimals, n).ToString();
+ }
+
+ private void SetLengthEffectErrorMessage(string errorMessage)
+ {
+ lengthEffectErrorProvider.SetIconPadding(parameterATextBox, 5);
+ lengthEffectErrorProvider.SetError(parameterATextBox, errorMessage);
+ }
+
+ private void ClearLengthEffectErrorMessage()
+ {
+ lengthEffectErrorProvider.SetError(parameterATextBox, string.Empty);
+ }
+
+ private void EnableControl()
+ {
+ parameterATextBox.Enabled = true;
+ parameterATextBox.Refresh();
+
+ lengthEffectNRoundedTextBox.Enabled = true;
+ lengthEffectNRoundedTextBox.Refresh();
+ }
+
+ private void DisableControl()
+ {
+ parameterATextBox.Enabled = false;
+ parameterATextBox.Refresh();
+
+ lengthEffectNRoundedTextBox.Enabled = false;
+ lengthEffectNRoundedTextBox.Refresh();
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.resx
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.resx (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.Forms/Controls/LengthEffectSettingsControl.resx (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.Forms/Riskeer.Common.Forms.csproj
===================================================================
diff -u -r1930606f48c2c45ef891fe6e249f9f3924cf3d63 -r40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7
--- Riskeer/Common/src/Riskeer.Common.Forms/Riskeer.Common.Forms.csproj (.../Riskeer.Common.Forms.csproj) (revision 1930606f48c2c45ef891fe6e249f9f3924cf3d63)
+++ Riskeer/Common/src/Riskeer.Common.Forms/Riskeer.Common.Forms.csproj (.../Riskeer.Common.Forms.csproj) (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -80,6 +80,9 @@
UserControl
+
+ UserControl
+
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Controls/LengthEffectSettingsControlTest.cs
===================================================================
diff -u
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/Controls/LengthEffectSettingsControlTest.cs (revision 0)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Controls/LengthEffectSettingsControlTest.cs (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -0,0 +1,493 @@
+// Copyright (C) Stichting Deltares and State of the Netherlands 2023. 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 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Base.Data;
+using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
+using Core.Common.Util.Reflection;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.Test.FailureMechanism;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Common.Forms.Controls;
+
+namespace Riskeer.Common.Forms.Test.Controls
+{
+ [TestFixture]
+ public class LengthEffectSettingsControlTest
+ {
+ private Form testForm;
+
+ [SetUp]
+ public void Setup()
+ {
+ testForm = new Form();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ testForm.Dispose();
+ }
+
+ [Test]
+ public void Constructor_LengthEffectControlsCorrectlyInitialized()
+ {
+ // Setup
+ var random = new Random(21);
+
+ // Call
+ ShowLengthEffectSettingsControl(random.NextDouble());
+
+ // Assert
+ var lengthEffectALabel = (Label) new LabelTester("parameterALabel").TheObject;
+ Assert.AreEqual("Lengte-effect parameter a [-]", lengthEffectALabel.Text);
+
+ var lengthEffectNRoundedLabel = (Label) new LabelTester("lengthEffectNRoundedLabel").TheObject;
+ Assert.AreEqual("Lengte-effect parameter Nvak* [-]", lengthEffectNRoundedLabel.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.IsFalse(lengthEffectNRoundedTextBox.Enabled);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void GivenControl_WhenSettingConfiguration_ThenControlUpdated()
+ {
+ // Given
+ const double a = 0.7;
+ const double b = 300.0;
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+
+ // Precondition
+ var parameterATextBox = (TextBox) GetParameterATextBox().TheObject;
+ Assert.IsEmpty(parameterATextBox.Text);
+ Assert.IsFalse(parameterATextBox.Enabled);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.IsEmpty(lengthEffectNRoundedTextBox.Text);
+
+ // When
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ // Then
+ Assert.AreEqual("0,700", parameterATextBox.Text);
+ Assert.IsTrue(parameterATextBox.Enabled);
+
+ Assert.AreEqual("1,23", lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void GivenControlWithConfiguration_WhenClearingData_ThenControlUpdated()
+ {
+ // Given
+ const double a = 0.7;
+ const double b = 300.0;
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ // Precondition
+ var parameterATextBox = (TextBox) GetParameterATextBox().TheObject;
+ Assert.AreEqual("0,700", parameterATextBox.Text);
+ Assert.IsTrue(parameterATextBox.Enabled);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual("1,23", lengthEffectNRoundedTextBox.Text);
+
+ // When
+ settingsControl.ClearData();
+
+ // Then
+ Assert.IsEmpty(parameterATextBox.Text);
+ Assert.IsFalse(parameterATextBox.Enabled);
+
+ Assert.IsEmpty(lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ public void GivenControlWithError_WhenClearingData_ThenErrorCleared()
+ {
+ // Given
+ var random = new Random(21);
+ RoundedDouble a = random.NextRoundedDouble();
+ double b = random.NextDouble();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ parameterATextBoxTester.Enter("NotADouble");
+
+ // Precondition
+ ErrorProvider errorProvider = GetLengthEffectErrorProvider(settingsControl);
+ var lengthEffectATextBox = (TextBox) GetParameterATextBox().TheObject;
+ string errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsNotEmpty(errorMessage);
+
+ // When
+ settingsControl.ClearData();
+
+ // Then
+ errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsEmpty(errorMessage);
+ }
+
+ [Test]
+ public void GivenControlWithError_WhenEnteringValidData_ThenErrorClearedAndControlsUpdated()
+ {
+ // Given
+ var random = new Random(21);
+ RoundedDouble a = random.NextRoundedDouble();
+ double b = random.NextDouble();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ parameterATextBoxTester.Enter("NotADouble");
+
+ // Precondition
+ ErrorProvider errorProvider = GetLengthEffectErrorProvider(settingsControl);
+ var lengthEffectATextBox = (TextBox) GetParameterATextBox().TheObject;
+ string errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsNotEmpty(errorMessage);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.IsEmpty(lengthEffectNRoundedTextBox.Text);
+
+ // When
+ parameterATextBoxTester.Enter("0,7");
+
+ // Then
+ errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsEmpty(errorMessage);
+ Assert.IsNotEmpty(lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ public void GivenControlWithError_WhenSettingData_ThenErrorCleared()
+ {
+ // Given
+ var random = new Random(21);
+ RoundedDouble a = random.NextRoundedDouble();
+ double b = random.NextDouble();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ parameterATextBoxTester.Enter("NotADouble");
+
+ // Precondition
+ ErrorProvider errorProvider = GetLengthEffectErrorProvider(settingsControl);
+ var lengthEffectATextBox = (TextBox) GetParameterATextBox().TheObject;
+ string errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsNotEmpty(errorMessage);
+
+ // When
+ var newConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection(),
+ random.NextRoundedDouble());
+ settingsControl.SetScenarioConfiguration(newConfiguration);
+
+ // Then
+ errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsEmpty(errorMessage);
+ }
+
+ [Test]
+ public void GivenControlWithoutError_WhenEnteringInvalidData_ThenErrorSetAndControlsUpdated()
+ {
+ // Given
+ var random = new Random(21);
+ RoundedDouble a = random.NextRoundedDouble();
+ double b = random.NextDouble();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+
+ // Precondition
+ ErrorProvider errorProvider = GetLengthEffectErrorProvider(settingsControl);
+ var lengthEffectATextBox = (TextBox) GetParameterATextBox().TheObject;
+ string errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsEmpty(errorMessage);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.IsNotEmpty(lengthEffectNRoundedTextBox.Text);
+
+ // When
+ parameterATextBoxTester.Enter("NotADouble");
+
+ // Then
+ errorMessage = errorProvider.GetError(lengthEffectATextBox);
+ Assert.IsNotEmpty(errorMessage);
+ Assert.IsEmpty(lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ public void GivenControlWithConfiguration_WhenSettingNewAValue_ThenControlsUpdatedAndObserversNotified()
+ {
+ // Given
+ const double a = 0.4;
+ const double b = 300;
+
+ var mocks = new MockRepository();
+ var observer = mocks.StrictMock();
+ observer.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+ scenarioConfiguration.Attach(observer);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ // Precondition
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ Assert.AreEqual("0,400", parameterATextBoxTester.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual("1,13", lengthEffectNRoundedTextBox.Text);
+
+ // When
+ parameterATextBoxTester.Enter("0,7");
+
+ // Then
+ Assert.AreEqual("1,23", lengthEffectNRoundedTextBox.Text);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void GivenControlWithConfiguration_WhenSettingInvalidAValueAndEscPressed_ThenControlsSetToInitialValue()
+ {
+ // Given
+ var mocks = new MockRepository();
+ var observer = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ const double a = 0.4;
+ const string initialAValue = "0,400";
+ const double b = 300;
+ const string lengthEffectNRoundedValue = "1,13";
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+ scenarioConfiguration.Attach(observer);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ const Keys keyData = Keys.Escape;
+
+ var parameterTextBox = (TextBox) parameterATextBoxTester.TheObject;
+ parameterTextBox.TextChanged += (sender, args) =>
+ {
+ parameterATextBoxTester.FireEvent("KeyDown", new KeyEventArgs(keyData));
+ };
+
+ // Precondition
+ Assert.AreEqual(initialAValue, parameterATextBoxTester.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual(lengthEffectNRoundedValue, lengthEffectNRoundedTextBox.Text);
+
+ // When
+ parameterTextBox.Text = "NotAProbability";
+
+ // Then
+ Assert.AreEqual(initialAValue, parameterATextBoxTester.Text);
+ Assert.AreEqual(lengthEffectNRoundedValue, lengthEffectNRoundedTextBox.Text);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenControlWithConfiguration_WhenConfigurationNotifiesObservers_ThenControlsUpdated()
+ {
+ // Given
+ const double a = 0.4;
+ const double b = 300;
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ // Precondition
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ Assert.AreEqual("0,400", parameterATextBoxTester.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual("1,13", lengthEffectNRoundedTextBox.Text);
+
+ // When
+ scenarioConfiguration.A = (RoundedDouble) 0.7;
+ scenarioConfiguration.NotifyObservers();
+
+ // Then
+ Assert.AreEqual("0,700", parameterATextBoxTester.Text);
+ Assert.AreEqual("1,23", lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ public void GivenControlWithConfiguration_WhenDataClearedAndConfigurationNotifiesObservers_ThenControlsNotUpdated()
+ {
+ // Given
+ const double a = 0.4;
+ const double b = 300;
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var scenarioConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(scenarioConfiguration);
+
+ // Precondition
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ Assert.AreEqual("0,400", parameterATextBoxTester.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual("1,13", lengthEffectNRoundedTextBox.Text);
+
+ // When
+ settingsControl.ClearData();
+ scenarioConfiguration.A = (RoundedDouble) 0.7;
+ scenarioConfiguration.NotifyObservers();
+
+ // Then
+ Assert.IsEmpty(parameterATextBoxTester.Text);
+ Assert.IsEmpty(lengthEffectNRoundedTextBox.Text);
+ }
+
+ [Test]
+ public void GivenControlWithConfiguration_WhenSettingNewConfigurationAndOldConfigurationNotifiesObservers_ThenControlsNotUpdated()
+ {
+ // Given
+ const double a = 0.4;
+ const double b = 300;
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(100, 0)
+ });
+ var oldConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a);
+
+ LengthEffectSettingsControl settingsControl = ShowLengthEffectSettingsControl(b);
+ settingsControl.SetScenarioConfiguration(oldConfiguration);
+
+ // Precondition
+ TextBoxTester parameterATextBoxTester = GetParameterATextBox();
+ Assert.AreEqual("0,400", parameterATextBoxTester.Text);
+
+ TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox();
+ Assert.AreEqual("1,13", lengthEffectNRoundedTextBox.Text);
+
+ // When
+ var newConfiguration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) 0.7);
+ settingsControl.SetScenarioConfiguration(newConfiguration);
+ oldConfiguration.NotifyObservers();
+
+ // Then
+ Assert.AreEqual("0,700", parameterATextBoxTester.Text);
+ Assert.AreEqual("1,23", lengthEffectNRoundedTextBox.Text);
+ }
+
+ private TextBoxTester GetParameterATextBox()
+ {
+ return new TextBoxTester("parameterATextBox");
+ }
+
+ private TextBox GetLengthEffectNRoundedTextBox()
+ {
+ return (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject;
+ }
+
+ private static ErrorProvider GetLengthEffectErrorProvider(LengthEffectSettingsControl settingsControl)
+ {
+ return TypeUtils.GetField(settingsControl, "lengthEffectErrorProvider");
+ }
+
+ private LengthEffectSettingsControl ShowLengthEffectSettingsControl(double b)
+ {
+ var control = new LengthEffectSettingsControl(b);
+
+ testForm.Controls.Add(control);
+ testForm.Show();
+
+ return control;
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Riskeer.Common.Forms.Test.csproj
===================================================================
diff -u -r230175547114c14da3d5516ace295d9d30cb4b04 -r40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7
--- Riskeer/Common/test/Riskeer.Common.Forms.Test/Riskeer.Common.Forms.Test.csproj (.../Riskeer.Common.Forms.Test.csproj) (revision 230175547114c14da3d5516ace295d9d30cb4b04)
+++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Riskeer.Common.Forms.Test.csproj (.../Riskeer.Common.Forms.Test.csproj) (revision 40a40a6f35b1fdf12a7a926c3c5a9f6df7de4cb7)
@@ -43,6 +43,7 @@
+