Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs (.../GrassCoverErosionOutwardsDataSynchronizationService.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs (.../GrassCoverErosionOutwardsDataSynchronizationService.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -24,7 +24,6 @@ using System.Linq; using Core.Common.Base; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionOutwards.Data; Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (.../AssessmentSectionCompositionChangeHandler.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (.../AssessmentSectionCompositionChangeHandler.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -27,6 +27,8 @@ using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; @@ -74,8 +76,34 @@ log.InfoFormat(Resources.ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, affectedObjects.OfType().Count()); } + + affectedObjects.AddRange(ClearHydraulicBoundaryLocationOutput(assessmentSection)); } return affectedObjects; } + + private IEnumerable ClearHydraulicBoundaryLocationOutput(IAssessmentSection assessmentSection) + { + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + IEnumerable hydraulicBoundaryLocationAffected = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput( + grassCoverErosionOutwardsFailureMechanism, duneErosionFailureMechanism); + if (hydraulicBoundaryLocationAffected.Any()) + { + log.Info(Resources.FailureMechanismContributionNormChangeHandler_Waveheight_and_design_water_level_results_cleared); + return new IObservable[] + { + grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, + duneErosionFailureMechanism.DuneLocations + }; + } + return Enumerable.Empty(); + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -187,14 +187,13 @@ /// /// Clears the output of the hydraulic boundary locations within the - /// and . + /// and . /// /// The wich contains the locations. /// The which contains the locations. /// The which contains locations. /// All objects affected by the operation. - /// Thrown when - /// or is null. + /// Thrown when any parameter is null. public static IEnumerable ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism, DuneErosionFailureMechanism duneErosionFailureMechanism) @@ -203,6 +202,25 @@ { throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); } + + IEnumerable affectedLocations = ClearHydraulicBoundaryLocationOutput(grassCoverErosionOutwardsFailureMechanism, duneErosionFailureMechanism); + + return RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(hydraulicBoundaryDatabase.Locations) + .Concat(affectedLocations) + .ToArray(); + } + + /// + /// Clears the output of the hydraulic boundary locations within the + /// and . + /// + /// The which contains the locations. + /// The which contains the locations. + /// All objects affected by the operation. + /// Thrown when any parameter is null. + public static IEnumerable ClearHydraulicBoundaryLocationOutput(GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism, + DuneErosionFailureMechanism duneErosionFailureMechanism) + { if (grassCoverErosionOutwardsFailureMechanism == null) { throw new ArgumentNullException(nameof(grassCoverErosionOutwardsFailureMechanism)); @@ -213,10 +231,7 @@ } return RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations) - .Concat(RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput( - hydraulicBoundaryDatabase.Locations)) - .Concat(DuneErosionDataSynchronizationService.ClearDuneLocationOutput( - duneErosionFailureMechanism.DuneLocations)) + .Concat(DuneErosionDataSynchronizationService.ClearDuneLocationOutput(duneErosionFailureMechanism.DuneLocations)) .ToArray(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs =================================================================== diff -u -rd712df3c2f4776b59592caaeb484824def9c2271 -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision d712df3c2f4776b59592caaeb484824def9c2271) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -28,6 +28,9 @@ using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.Integration.Service; @@ -127,6 +130,16 @@ .Where(c => c.HasOutput) .ToArray(); + DuneLocation[] duneLocationWithOutput = assessmentSection.GetFailureMechanisms().OfType() + .SelectMany(f => f.DuneLocations) + .Where(loc => loc.Output != null) + .ToArray(); + + HydraulicBoundaryLocation[] hblWithOutput = assessmentSection.GetFailureMechanisms().OfType() + .SelectMany(f => f.HydraulicBoundaryLocations) + .Where(loc => loc.DesignWaterLevelOutput != null || loc.WaveHeightOutput != null) + .ToArray(); + var handler = new AssessmentSectionCompositionChangeHandler(); // Call @@ -136,6 +149,9 @@ Assert.True(calculationsWithOutput.All(c => c.HasOutput), "All calculations that had output still have them."); + Assert.True(duneLocationWithOutput.All(loc => loc.Output != null)); + Assert.True(hblWithOutput.All(loc => loc.DesignWaterLevelOutput != null || loc.WaveHeightOutput != null)); + CollectionAssert.IsEmpty(affectedObjects); } @@ -149,12 +165,25 @@ // Precondition Assert.AreNotEqual(assessmentSection.Composition, newComposition); + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() .Concat(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)) .Concat(new[] { assessmentSection }) + .Concat(new IObservable[] + { + grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, + duneErosionFailureMechanism.DuneLocations + }) .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(); @@ -164,12 +193,28 @@ Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); // Assert - string expectedMessage = "De resultaten van 32 berekeningen zijn verwijderd."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + string[] expectedMessage = + { + "De resultaten van 32 berekeningen zijn verwijderd.", + "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd." + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessage, 2); Assert.AreEqual(newComposition, assessmentSection.Composition); Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + + foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) + { + Assert.IsNull(duneLocation.Output); + } } [Test] @@ -184,11 +229,24 @@ Assert.AreNotEqual(assessmentSection.Composition, newComposition); CollectionAssert.IsEmpty(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)); + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() .Concat(new[] { assessmentSection }) + .Concat(new IObservable[] + { + grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, + duneErosionFailureMechanism.DuneLocations + }) .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(); @@ -198,11 +256,60 @@ Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); // Assert - TestHelper.AssertLogMessagesCount(call, 0); + TestHelper.AssertLogMessageIsGenerated(call, "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.", 1); Assert.AreEqual(newComposition, assessmentSection.Composition); Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + + foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) + { + Assert.IsNull(duneLocation.Output); + } } + + [Test] + public void ChangeComposition_ChangeToDifferentValueAndNoHydraulicBoudaryLocationsWithOutput_ChangeCompositionAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(assessmentSection.GrassCoverErosionOutwards, + assessmentSection.DuneErosion); + var newComposition = AssessmentSectionComposition.Dune; + + // Precondition + Assert.AreNotEqual(assessmentSection.Composition, newComposition); + CollectionAssert.IsEmpty(assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Where(loc => loc.DesignWaterLevelOutput != null + || loc.WaveHeightOutput != null)); + CollectionAssert.IsEmpty(assessmentSection.DuneErosion.DuneLocations.Where(dl => dl.Output != null)); + + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() + .Concat(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)) + .Concat(new[] + { + assessmentSection + }) + .ToArray(); + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + IEnumerable affectedObjects = null; + Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "De resultaten van 32 berekeningen zijn verwijderd.", 1); + + Assert.AreEqual(newComposition, assessmentSection.Composition); + Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs =================================================================== diff -u -r11949f071abdcebaadf757c53a34b93299aefbaa -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 11949f071abdcebaadf757c53a34b93299aefbaa) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -286,7 +286,7 @@ .Concat(section.GetFailureMechanisms()) .Concat(new IObservable[] { - section.FailureMechanismContribution, + section.FailureMechanismContribution }); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }