Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs =================================================================== diff -u -r57ef55e67931df024753fe19a636c02eaae148c1 -rdcd28600cb6af69cb49bf311b0fa61f78ad149be --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs) (revision 57ef55e67931df024753fe19a636c02eaae148c1) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs) (revision dcd28600cb6af69cb49bf311b0fa61f78ad149be) @@ -39,22 +39,22 @@ /// public class HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler : IObservablePropertyChangeHandler { - private readonly HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability; - private readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler)); + private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler)); /// /// Creates a new instance of . /// /// The calculations to change the target probability for. /// Thrown when is null. - public HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler(HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability) + public HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler( + HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability) { if (calculationsForTargetProbability == null) { throw new ArgumentNullException(nameof(calculationsForTargetProbability)); } - this.calculationsForTargetProbability = calculationsForTargetProbability; + CalculationsForTargetProbability = calculationsForTargetProbability; } public IEnumerable SetPropertyValueAfterConfirmation(SetObservablePropertyValueDelegate setValue) @@ -70,33 +70,40 @@ { setValue(); - affectedObjects.AddRange(ClearHydraulicBoundaryLocationCalculationOutput()); - affectedObjects.Add(calculationsForTargetProbability); + affectedObjects.AddRange(ClearHydraulicBoundaryLocationCalculationDependentOutput()); + affectedObjects.Add(CalculationsForTargetProbability); } return affectedObjects; } - private static bool ConfirmPropertyChange() - { - DialogResult result = MessageBox.Show(RiskeerCommonPluginResources.TargetProbabilityChangeHandler_Confirm_change_target_probability_and_clear_dependent_data, - CoreCommonBaseResources.Confirm, - MessageBoxButtons.OKCancel); - return result == DialogResult.OK; - } + /// + /// Gets the calculations to change the target probability for. + /// + protected HydraulicBoundaryLocationCalculationsForTargetProbability CalculationsForTargetProbability { get; } - private IEnumerable ClearHydraulicBoundaryLocationCalculationOutput() + /// + /// Clears the hydraulic boundary location calculation dependent output. + /// + /// The affected objects. + protected virtual IEnumerable ClearHydraulicBoundaryLocationCalculationDependentOutput() { - IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(calculationsForTargetProbability); + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(CalculationsForTargetProbability); if (affectedObjects.Any()) { log.Info(RiskeerCommonPluginResources.TargetProbabilityChangeHandler_Hydraulic_load_results_cleared); - - return affectedObjects; } - return Enumerable.Empty(); + return affectedObjects; } + + private static bool ConfirmPropertyChange() + { + DialogResult result = MessageBox.Show(RiskeerCommonPluginResources.TargetProbabilityChangeHandler_Confirm_change_target_probability_and_clear_dependent_data, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + return result == DialogResult.OK; + } } } \ No newline at end of file Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler.cs (revision dcd28600cb6af69cb49bf311b0fa61f78ad149be) @@ -0,0 +1,65 @@ +// Copyright (C) Stichting Deltares 2021. 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.Collections.Generic; +using Core.Common.Base; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Integration.Service; + +namespace Riskeer.Integration.Plugin.Handlers +{ + /// + /// Class responsible for changing the + /// value of a and clearing all dependent data. + /// + public class WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler : HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler + { + private readonly IAssessmentSection assessmentSection; + + /// + /// Creates a new instance of . + /// + /// The calculations to change the target probability for. + /// The the that contains the . + /// Thrown when any parameter is null. + public WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler( + HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability, IAssessmentSection assessmentSection) + : base(calculationsForTargetProbability) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + this.assessmentSection = assessmentSection; + } + + protected override IEnumerable ClearHydraulicBoundaryLocationCalculationDependentOutput() + { + var affectedObjects = new List(); + affectedObjects.AddRange(base.ClearHydraulicBoundaryLocationCalculationDependentOutput()); + affectedObjects.AddRange(RiskeerDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(assessmentSection, CalculationsForTargetProbability)); + return affectedObjects; + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs =================================================================== diff -u -r8c379b950333e45a56c901c937e705c8ac1e1c88 -rdcd28600cb6af69cb49bf311b0fa61f78ad149be --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs) (revision 8c379b950333e45a56c901c937e705c8ac1e1c88) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs) (revision dcd28600cb6af69cb49bf311b0fa61f78ad149be) @@ -114,10 +114,10 @@ }; HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability = CreateCalculationsForTargetProbabilityWithAndWithoutOutput(); - List expectedAffectedObjects = calculationsForTargetProbability.HydraulicBoundaryLocationCalculations - .Where(hblc => hblc.HasOutput) - .Cast() - .ToList(); + List expectedAffectedObjects = calculationsForTargetProbability.HydraulicBoundaryLocationCalculations + .Where(hblc => hblc.HasOutput) + .Cast() + .ToList(); expectedAffectedObjects.Add(calculationsForTargetProbability); @@ -134,7 +134,7 @@ "Alle bijbehorende hydraulische belastingen zijn verwijderd." }; TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1); - CollectionAssert.IsEmpty(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(hblc => hblc.HasOutput)); + CollectionAssert.IsEmpty(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(c => c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } @@ -217,7 +217,7 @@ // Assert Assert.AreEqual(0, propertySet); - Assert.AreEqual(2, calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Count(hblc => hblc.HasOutput)); + Assert.AreEqual(2, calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Count(c => c.HasOutput)); CollectionAssert.IsEmpty(affectedObjects); } Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest.cs (revision dcd28600cb6af69cb49bf311b0fa61f78ad149be) @@ -0,0 +1,180 @@ +// Copyright (C) Stichting Deltares 2021. 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.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.TestUtil; +using Core.Common.Util.Extensions; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.Integration.Data; +using Riskeer.Integration.Plugin.Handlers; +using Riskeer.Integration.TestUtil; +using Riskeer.Revetment.Data; +using Riskeer.StabilityStoneCover.Data; +using Riskeer.WaveImpactAsphaltCover.Data; + +namespace Riskeer.Integration.Plugin.Test.Handlers +{ + [TestFixture] + public class WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandlerTest : NUnitFormTest + { + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler( + new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var handler = new WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler( + new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1), assessmentSection); + + // Assert + Assert.IsInstanceOf(handler); + mocks.VerifyAll(); + } + + [Test] + public void SetPropertyValueAfterConfirmation_CalculationsForTargetProbabilityWithAndWithoutOutput_AllCalculationOutputClearedAndReturnsAllAffectedObjects() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities + .First(); + + var waveConditionsCalculations = new List>(); + waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations + .Cast()); + waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations + .Cast()); + waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations + .Cast()); + + waveConditionsCalculations.ForEachElementDo(c => + { + c.InputParameters.WaterLevelType = WaveConditionsInputWaterLevelType.UserDefinedTargetProbability; + c.InputParameters.CalculationsTargetProbability = calculationsForTargetProbability; + }); + + var expectedAffectedObjects = new List + { + calculationsForTargetProbability + }; + expectedAffectedObjects.AddRange(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(c => c.HasOutput)); + expectedAffectedObjects.AddRange(waveConditionsCalculations.Where(c => c.HasOutput)); + + var handler = new WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler(calculationsForTargetProbability, assessmentSection); + + IEnumerable affectedObjects = null; + + // Call + void Call() => affectedObjects = handler.SetPropertyValueAfterConfirmation(() => {}); + + // Assert + var expectedMessages = new[] + { + "Alle bijbehorende hydraulische belastingen zijn verwijderd." + }; + TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + CollectionAssert.IsEmpty(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.Where(c => c.HasOutput)); + CollectionAssert.IsEmpty(waveConditionsCalculations.Where(c => c.HasOutput)); + } + + [Test] + public void SetPropertyValueAfterConfirmation_CalculationsForTargetProbabilityWithoutOutput_ReturnsNoAffectedObjects() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities + .First(); + + var waveConditionsCalculations = new List>(); + waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations + .Cast()); + waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations + .Cast()); + waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations + .Cast()); + + waveConditionsCalculations.ForEachElementDo(c => + { + c.InputParameters.WaterLevelType = WaveConditionsInputWaterLevelType.UserDefinedTargetProbability; + c.InputParameters.CalculationsTargetProbability = calculationsForTargetProbability; + c.ClearOutput(); + }); + + calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.ForEachElementDo(c => c.Output = null); + + var handler = new WaterLevelHydraulicBoundaryLocationCalculationsForTargetProbabilityChangeHandler( + calculationsForTargetProbability, assessmentSection); + + HydraulicBoundaryLocationCalculationsForTargetProbability[] expectedAffectedObjects = + { + calculationsForTargetProbability + }; + + IEnumerable affectedObjects = null; + + // Call + void Call() => affectedObjects = handler.SetPropertyValueAfterConfirmation(() => {}); + + // Assert + TestHelper.AssertLogMessagesCount(Call, 0); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + } +} \ No newline at end of file