Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Merge/AssessmentSectionMergeHandler.cs =================================================================== diff -u -r840f6ddca0edcb0e0effd1567df7291367d339cb -r8536b5bd3d91298dc866db708d7c75ae10fc84de --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Merge/AssessmentSectionMergeHandler.cs (.../AssessmentSectionMergeHandler.cs) (revision 840f6ddca0edcb0e0effd1567df7291367d339cb) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Merge/AssessmentSectionMergeHandler.cs (.../AssessmentSectionMergeHandler.cs) (revision 8536b5bd3d91298dc866db708d7c75ae10fc84de) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Gui.Commands; +using Core.Common.Util.Extensions; using log4net; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.AssessmentSection; @@ -92,47 +93,58 @@ } BeforeMerge(targetAssessmentSection); - MergeHydraulicBoundaryLocations(targetAssessmentSection, sourceAssessmentSection); + + var changedObjects = new List + { + targetAssessmentSection + }; + + changedObjects.AddRange(MergeHydraulicBoundaryLocations(targetAssessmentSection, sourceAssessmentSection)); MergeFailureMechanisms(targetAssessmentSection, failureMechanismsToMerge); - AfterMerge(targetAssessmentSection); + + AfterMerge(changedObjects); } private void BeforeMerge(AssessmentSection assessmentSection) { viewCommands.RemoveAllViewsForItem(assessmentSection); } - private static void AfterMerge(AssessmentSection targetAssessmentSection) + private static void AfterMerge(IEnumerable changedObjects) { - targetAssessmentSection.NotifyObservers(); + changedObjects.ForEachElementDo(co => co.NotifyObservers()); } #region HydraulicBoundaryLocationCalculations - private static void MergeHydraulicBoundaryLocations(IAssessmentSection targetAssessmentSection, IAssessmentSection sourceAssessmentSection) + private static IEnumerable MergeHydraulicBoundaryLocations(IAssessmentSection targetAssessmentSection, IAssessmentSection sourceAssessmentSection) { - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, - sourceAssessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForSignalingNorm, - sourceAssessmentSection.WaterLevelCalculationsForSignalingNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForLowerLimitNorm, - sourceAssessmentSection.WaterLevelCalculationsForLowerLimitNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, - sourceAssessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm); + var changedObjects = new List(); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, - sourceAssessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForSignalingNorm, - sourceAssessmentSection.WaveHeightCalculationsForSignalingNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForLowerLimitNorm, - sourceAssessmentSection.WaveHeightCalculationsForLowerLimitNorm); - MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, - sourceAssessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, + sourceAssessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForSignalingNorm, + sourceAssessmentSection.WaterLevelCalculationsForSignalingNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForLowerLimitNorm, + sourceAssessmentSection.WaterLevelCalculationsForLowerLimitNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, + sourceAssessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, + sourceAssessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForSignalingNorm, + sourceAssessmentSection.WaveHeightCalculationsForSignalingNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForLowerLimitNorm, + sourceAssessmentSection.WaveHeightCalculationsForLowerLimitNorm)); + changedObjects.AddRange(MergeHydraulicBoundaryLocationCalculations(targetAssessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, + sourceAssessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm)); + log.Info(Resources.AssessmentSectionMergeHandler_MergeHydraulicBoundaryLocations_HydraulicBoundaryLocations_merged); + + return changedObjects; } - private static void MergeHydraulicBoundaryLocationCalculations(IEnumerable targetCalculations, + private static IEnumerable MergeHydraulicBoundaryLocationCalculations(IEnumerable targetCalculations, IEnumerable sourceCalculations) { for (var i = 0; i < targetCalculations.Count(); i++) @@ -144,6 +156,7 @@ { targetCalculation.InputParameters.ShouldIllustrationPointsBeCalculated = sourceCalculation.InputParameters.ShouldIllustrationPointsBeCalculated; targetCalculation.Output = sourceCalculation.Output; + yield return targetCalculation; } } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Merge/AssessmentSectionMergeHandlerTest.cs =================================================================== diff -u -rb2591925535d27b3d900f571bf7ffa80070b1aaa -r8536b5bd3d91298dc866db708d7c75ae10fc84de --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Merge/AssessmentSectionMergeHandlerTest.cs (.../AssessmentSectionMergeHandlerTest.cs) (revision b2591925535d27b3d900f571bf7ffa80070b1aaa) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Merge/AssessmentSectionMergeHandlerTest.cs (.../AssessmentSectionMergeHandlerTest.cs) (revision 8536b5bd3d91298dc866db708d7c75ae10fc84de) @@ -654,6 +654,44 @@ mocks.VerifyAll(); } + [Test] + [TestCaseSource(nameof(GetCalculationsFuncs))] + public void PerformMerge_HydraulicBoundaryLocationCalculationsMerged_ObserversNotified( + Func> getCalculationsFunc) + { + // Setup + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()).Repeat.Twice(); + mocks.ReplayAll(); + + HydraulicBoundaryLocation[] locations = + { + new TestHydraulicBoundaryLocation(), + new TestHydraulicBoundaryLocation() + }; + + AssessmentSection targetAssessmentSection = CreateAssessmentSection(locations); + AssessmentSection sourceAssessmentSection = CreateAssessmentSection(locations); + + IEnumerable targetCalculations = getCalculationsFunc(targetAssessmentSection); + IEnumerable sourceCalculations = getCalculationsFunc(sourceAssessmentSection); + + targetCalculations.ForEachElementDo(calculation => calculation.Attach(observer)); + + SetOutput(targetCalculations); + SetOutput(sourceCalculations, true); + + var handler = new AssessmentSectionMergeHandler(viewCommands); + + // Call + handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); + + // Assert + mocks.VerifyAll(); + } + private static void SetOutput(IEnumerable calculations, bool illustrationPoints = false) { foreach (HydraulicBoundaryLocationCalculation calculation in calculations)