Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -283,7 +283,8 @@ { if (data != null) { - normInput.Value = data.Norm; + // Note: Set the Text instead of value to ensure Value property is correct when handling Validating events. + normInput.Text = data.Norm.ToString(CultureInfo.CurrentCulture); } } @@ -418,7 +419,7 @@ private void NormNumericUpDown_Validating(object sender, CancelEventArgs e) { - if (normInput.Value != assessmentSection.FailureMechanismContribution.Norm) + if (Convert.ToInt32(normInput.Value) != assessmentSection.FailureMechanismContribution.Norm) { if (!changeHandler.ConfirmNormChange()) { Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -289,7 +289,7 @@ probabilityDistributionGrid - Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.4.1.6761, Culture=neutral, PublicKeyToken=null + Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.4.1.6918, Culture=neutral, PublicKeyToken=null tableLayoutPanel Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs (.../IFailureMechanismContributionNormChangeHandler.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs (.../IFailureMechanismContributionNormChangeHandler.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using Core.Common.Base; using Ringtoets.Common.Data.AssessmentSection; @@ -44,9 +45,13 @@ /// of the given and propagates the changes to /// underlying data structure. /// - /// The section to be updated. + /// The section to be updated. /// The new norm value. /// All objects that have been affected by the change. - IEnumerable ChangeNorm(IAssessmentSection section, int newNormValue); + /// Thrown when + /// is null. + /// Thrown when + /// is an invalid norm value. + IEnumerable ChangeNorm(IAssessmentSection assessmentSection, int newNormValue); } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -19,11 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Utils.Extensions; using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; @@ -52,28 +52,31 @@ return result == DialogResult.OK; } - public IEnumerable ChangeNorm(IAssessmentSection section, int newNormValue) + public IEnumerable ChangeNorm(IAssessmentSection assessmentSection, int newNormValue) { - var changedObjects = new List(); + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } - if (section.FailureMechanismContribution.Norm != newNormValue) + var changedObjects = new List(); + if (assessmentSection.FailureMechanismContribution.Norm != newNormValue) { - section.FailureMechanismContribution.Norm = newNormValue; + assessmentSection.FailureMechanismContribution.Norm = newNormValue; - changedObjects.AddRange(ClearAssessmentSectionData(section)); - changedObjects.Add(section.FailureMechanismContribution); - changedObjects.AddRange(section.GetFailureMechanisms()); + changedObjects.AddRange(ClearAllNormDependentCalculationOutput(assessmentSection)); + changedObjects.Add(assessmentSection.FailureMechanismContribution); + changedObjects.AddRange(assessmentSection.GetFailureMechanisms()); } - return changedObjects; } - private IEnumerable ClearAssessmentSectionData(IAssessmentSection assessmentSection) + private IEnumerable ClearAllNormDependentCalculationOutput(IAssessmentSection assessmentSection) { List affectedObjects = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToList(); if (affectedObjects.Count > 0) { - log.InfoFormat(Resources.FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared, + log.InfoFormat(Resources.FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, affectedObjects.Count); } @@ -94,7 +97,7 @@ grassCoverErosionOutwardsFailureMechanism); if (hydraulicBoundaryLocationAffected.Any()) { - log.Info(Resources.FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared); + log.Info(Resources.FailureMechanismContributionNormChangeHandler_Waveheight_and_design_water_level_results_cleared); return new IObservable[] { grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -rdee01f6d6c15af0cc124816bfe99c7658af8995d -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -88,7 +88,9 @@ } /// - /// Looks up a localized string similar to Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. Wilt u doorgaan?. + /// Looks up a localized string similar to Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. + /// + ///Wilt u doorgaan?. /// public static string FailureMechanismContributionNormChangeHandler_Confirm_change_norm_and_clear_dependent_data { get { @@ -100,20 +102,20 @@ /// /// Looks up a localized string similar to De resultaten van {0} berekeningen zijn verwijderd.. /// - public static string FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared { + public static string FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared { get { - return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations" + - "_0_calculations_cleared", resourceCulture); + return ResourceManager.GetString("FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_c" + + "alculations_cleared", resourceCulture); } } /// /// Looks up a localized string similar to Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.. /// - public static string FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared { + public static string FailureMechanismContributionNormChangeHandler_Waveheight_and_design_water_level_results_cleared { get { - return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_lev" + - "el_results_cleared", resourceCulture); + return ResourceManager.GetString("FailureMechanismContributionNormChangeHandler_Waveheight_and_design_water_level_r" + + "esults_cleared", resourceCulture); } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -rdee01f6d6c15af0cc124816bfe99c7658af8995d -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -147,13 +147,15 @@ Wilt u doorgaan? - + De resultaten van {0} berekeningen zijn verwijderd. - + Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd. - Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. Wilt u doorgaan? + Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. + +Wilt u doorgaan? \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -949,7 +949,7 @@ } [Test] - public void GivenView_WhenEnterAfterEnteringDifferentNormNotCommited_CommitValueAndChangeData() + public void GivenView_WhenEnterAfterEnteringDifferentNormNotCommitted_CommitValueAndChangeData() { // Given const int normValue = 200; Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -19,14 +19,24 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.Views; using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Integration.TestUtils; namespace Ringtoets.Integration.Plugin.Test.Handlers { [TestFixture] - public class FailureMechanismContributionNormChangeHandlerTest + public class FailureMechanismContributionNormChangeHandlerTest : NUnitFormTest { [Test] public void Constructor_ExpectedValues() @@ -37,5 +47,145 @@ // Assert Assert.IsInstanceOf(handler); } + + [Test] + public void ConfirmNormChange_ShownMessageBoxForConfirmation() + { + // Setup + string title = "", message = ""; + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + title = tester.Title; + message = tester.Text; + tester.ClickOk(); + }; + + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + handler.ConfirmNormChange(); + + // Assert + Assert.AreEqual("Bevestigen", title); + string expectedMessage = "Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden." + Environment.NewLine + + Environment.NewLine + + "Wilt u doorgaan?"; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + public void ConfirmNormChange_MessageBoxOk_ReturnTrue() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + bool isConfirmed = handler.ConfirmNormChange(); + + // Assert + Assert.IsTrue(isConfirmed); + } + + [Test] + public void ConfirmNormChange_MessageBoxCancelOk_ReturnFalse() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickCancel(); + }; + + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + bool isConfirmed = handler.ConfirmNormChange(); + + // Assert + Assert.IsFalse(isConfirmed); + } + + [Test] + public void ChangeNorm_AssessmentSectionNull_ThrownArgumentNullException() + { + // Setup + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + TestDelegate call = () => handler.ChangeNorm(null, 1000); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + [TestCase(-123456)] + [TestCase(0)] + public void ChangeNorm_InvalidNorm_ThrowArgumentOutOfRangeException(int invalidNorm) + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + TestDelegate call = () => handler.ChangeNorm(assessmentSection, invalidNorm); + + // Assert + const string expectedMessage = "De faalkansbijdrage kan alleen bepaald worden als de norm van het traject groter is dan 0."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void ChangeNorm_FullyConfiguredAssessmentSection_AllCalculationOutputClearedAndContributionsUpdatedAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection section = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + var expectedAffectedCalculations = section.GetFailureMechanisms() + .SelectMany(fm => fm.Calculations) + .Where(c => c.HasOutput) + .ToArray(); + var handler = new FailureMechanismContributionNormChangeHandler(); + + // Call + IEnumerable affectedObjects = null; + Action call = () => affectedObjects = handler.ChangeNorm(section, 1000); + + // Assert + var expectedMessages = new[] + { + "De resultaten van 32 berekeningen zijn verwijderd.", + "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd." + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages, 2); + + CollectionAssert.IsEmpty(section.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput), + "There should be no calculations with output."); + + var expectedAffectedObjects = expectedAffectedCalculations.Cast() + .Concat(section.GetFailureMechanisms()) + .Concat(new IObservable[] + { + section.FailureMechanismContribution, + section.GrassCoverErosionOutwards.HydraulicBoundaryLocations, + section.HydraulicBoundaryDatabase + }); + foreach (HydraulicBoundaryLocation location in section.HydraulicBoundaryDatabase.Locations + .Concat(section.GrassCoverErosionOutwards.HydraulicBoundaryLocations)) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs =================================================================== diff -u -rdee01f6d6c15af0cc124816bfe99c7658af8995d -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d --- Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) +++ Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) @@ -20,6 +20,7 @@ // All rights reserved. using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data; @@ -53,7 +54,13 @@ public static AssessmentSection GetFullyConfiguredAssessmentSection() { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0) + { + DesignWaterLevel = (RoundedDouble) 1.1, + DesignWaterLevelCalculationConvergence = CalculationConvergence.CalculatedConverged, + WaveHeight = (RoundedDouble) 2.2, + WaveHeightCalculationConvergence = CalculationConvergence.CalculatedConverged + }; assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { Locations = @@ -685,6 +692,17 @@ private static void SetFullyConfiguredFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism, HydraulicBoundaryLocation hydraulicBoundaryLocation) { + HydraulicBoundaryLocation internalHydroLocation = new HydraulicBoundaryLocation(hydraulicBoundaryLocation.Id, + hydraulicBoundaryLocation.Name, + hydraulicBoundaryLocation.Location.X, + hydraulicBoundaryLocation.Location.Y) + { + WaveHeight = (RoundedDouble) (hydraulicBoundaryLocation.WaveHeight + 0.2), + WaveHeightCalculationConvergence = hydraulicBoundaryLocation.WaveHeightCalculationConvergence, + DesignWaterLevel = (RoundedDouble) (hydraulicBoundaryLocation.DesignWaterLevel + 0.3), + DesignWaterLevelCalculationConvergence = hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence + }; + failureMechanism.HydraulicBoundaryLocations.Add(internalHydroLocation); var profile1 = new ForeshoreProfile(new Point2D(0, 0), new[] { @@ -718,7 +736,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation, + HydraulicBoundaryLocation = internalHydroLocation, ForeshoreProfile = profile1 }, Output = new GrassCoverErosionOutwardsWaveConditionsOutput(Enumerable.Empty()) @@ -727,7 +745,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation, + HydraulicBoundaryLocation = internalHydroLocation, ForeshoreProfile = profile2 }, Output = new GrassCoverErosionOutwardsWaveConditionsOutput(Enumerable.Empty()) @@ -736,7 +754,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + HydraulicBoundaryLocation = internalHydroLocation } }; @@ -745,7 +763,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation, + HydraulicBoundaryLocation = internalHydroLocation, ForeshoreProfile = profile2 }, Output = new GrassCoverErosionOutwardsWaveConditionsOutput(Enumerable.Empty()) @@ -754,7 +772,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation, + HydraulicBoundaryLocation = internalHydroLocation, ForeshoreProfile = profile1 }, Output = new GrassCoverErosionOutwardsWaveConditionsOutput(Enumerable.Empty()) @@ -763,7 +781,7 @@ { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + HydraulicBoundaryLocation = internalHydroLocation } };