Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs =================================================================== diff -u -r49de17d135736ea86269d5d384621cef6bac8888 -r0403b90b2a1c32b0a8e37a2ca14141ba76bba502 --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 49de17d135736ea86269d5d384621cef6bac8888) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 0403b90b2a1c32b0a8e37a2ca14141ba76bba502) @@ -28,6 +28,7 @@ using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.Contribution; +using Riskeer.Common.Data.Hydraulics; using Riskeer.Integration.Forms.PropertyClasses; using Riskeer.Integration.Plugin.Properties; using Riskeer.Integration.Service; @@ -78,7 +79,7 @@ () => { var affectedObjects = new List(); - affectedObjects.AddRange(ClearNormDependingHydraulicBoundaryLocationCalculationOutput()); + affectedObjects.AddRange(ClearNormDependingHydraulicBoundaryLocationCalculationOutput(true)); affectedObjects.AddRange(ClearAllNormDependentSemiProbabilisticCalculationOutput()); return affectedObjects; }); @@ -90,7 +91,7 @@ () => { var affectedObjects = new List(); - affectedObjects.AddRange(ClearNormDependingHydraulicBoundaryLocationCalculationOutput()); + affectedObjects.AddRange(ClearNormDependingHydraulicBoundaryLocationCalculationOutput(false)); return affectedObjects; }); } @@ -143,16 +144,29 @@ return affectedObjects; } - private IEnumerable ClearNormDependingHydraulicBoundaryLocationCalculationOutput() + private IEnumerable ClearNormDependingHydraulicBoundaryLocationCalculationOutput(bool normativeNorm) { - IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm(assessmentSection); + IEnumerable calculationsToClear = GetHydraulicBoundaryLocationCalculations(normativeNorm); + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(calculationsToClear); + if (affectedObjects.Any()) { log.Info(Resources.FailureMechanismContributionNormChangeHandler_ClearNormDependingHydraulicBoundaryLocationCalculationOutput_Calculation_results_cleared); } return affectedObjects; } + + private IEnumerable GetHydraulicBoundaryLocationCalculations(bool normativeNorm) + { + return normativeNorm + ? assessmentSection.FailureMechanismContribution.NormativeNorm == NormType.LowerLimit + ? assessmentSection.WaterLevelCalculationsForLowerLimitNorm + : assessmentSection.WaterLevelCalculationsForSignalingNorm + : assessmentSection.FailureMechanismContribution.NormativeNorm == NormType.LowerLimit + ? assessmentSection.WaterLevelCalculationsForSignalingNorm + : assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + } } } \ No newline at end of file Index: Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs =================================================================== diff -u -r4b889a77a0b2a44d9eadc54540334140415177c8 -r0403b90b2a1c32b0a8e37a2ca14141ba76bba502 --- Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (.../RiskeerDataSynchronizationService.cs) (revision 4b889a77a0b2a44d9eadc54540334140415177c8) +++ Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (.../RiskeerDataSynchronizationService.cs) (revision 0403b90b2a1c32b0a8e37a2ca14141ba76bba502) @@ -192,27 +192,20 @@ } /// - /// Clears the hydraulic boundary location calculation output belonging to the - /// . + /// Clears the hydraulic boundary location calculation output of the given . /// - /// The which contains the hydraulic boundary - /// location calculations and . - /// + /// The collection of to clear. /// All objects affected by the operation. - /// Thrown when is null. - public static IEnumerable ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm( - IAssessmentSection assessmentSection) + /// Thrown when is null. + public static IEnumerable ClearHydraulicBoundaryLocationCalculationOutput( + IEnumerable calculations) { - if (assessmentSection == null) + if (calculations == null) { - throw new ArgumentNullException(nameof(assessmentSection)); + throw new ArgumentNullException(nameof(calculations)); } - IObservableEnumerable locationCalculationsToClear = assessmentSection.FailureMechanismContribution.NormativeNorm == NormType.LowerLimit - ? assessmentSection.WaterLevelCalculationsForLowerLimitNorm - : assessmentSection.WaterLevelCalculationsForSignalingNorm; - - return RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(locationCalculationsToClear) + return RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(calculations) .ToArray(); } Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs =================================================================== diff -u -r4b889a77a0b2a44d9eadc54540334140415177c8 -r0403b90b2a1c32b0a8e37a2ca14141ba76bba502 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 4b889a77a0b2a44d9eadc54540334140415177c8) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 0403b90b2a1c32b0a8e37a2ca14141ba76bba502) @@ -30,6 +30,8 @@ using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Contribution; +using Riskeer.Common.Data.Hydraulics; using Riskeer.Integration.Data; using Riskeer.Integration.Forms.PropertyClasses; using Riskeer.Integration.Plugin.Handlers; @@ -272,7 +274,9 @@ } [Test] - public void GivenCalculationsWithOutput_WhenChangingNormativeNorm_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified() + [TestCaseSource(nameof(GetChangeNormativeNormCases))] + public void GivenCalculationsWithOutput_WhenChangingNormativeNorm_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified( + NormType normType, Func> getCalculationsFunc) { // Given DialogBoxHandler = (name, wnd) => @@ -282,6 +286,10 @@ }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + assessmentSection.FailureMechanismContribution.NormativeNorm = normType; + + IEnumerable expectedCalculationsToClear = getCalculationsFunc(assessmentSection); + ICalculation[] expectedAffectedCalculations = assessmentSection.Piping .Calculations .OfType() @@ -298,7 +306,7 @@ { assessmentSection.FailureMechanismContribution }) - .Concat(assessmentSection.WaterLevelCalculationsForLowerLimitNorm) + .Concat(expectedCalculationsToClear) .ToArray(); var mocks = new MockRepository(); @@ -311,7 +319,7 @@ var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection); // Precondition - CollectionAssert.IsNotEmpty(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.Where(c => c.HasOutput)); + CollectionAssert.IsNotEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); // When var actionPerformed = false; @@ -327,12 +335,14 @@ Assert.IsTrue(actionPerformed); CollectionAssert.IsEmpty(expectedAffectedCalculations.Where(c => c.HasOutput)); - CollectionAssert.IsEmpty(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.Where(c => c.HasOutput)); + CollectionAssert.IsEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); mocks.VerifyAll(); } [Test] - public void GivenCalculationsWithoutOutput_WhenChangingNormativeNorm_ThenActionPerformedAndContributionNotified() + [TestCaseSource(nameof(GetChangeNormativeNormCases))] + public void GivenCalculationsWithoutOutput_WhenChangingNormativeNorm_ThenActionPerformedAndContributionNotified( + NormType normType, Func> getCalculationsFunc) { // Given DialogBoxHandler = (name, wnd) => @@ -342,6 +352,10 @@ }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + assessmentSection.FailureMechanismContribution.NormativeNorm = normType; + + IEnumerable calculationsBelongingToNorm = getCalculationsFunc(assessmentSection); + ICalculation[] calculations = assessmentSection.Piping .Calculations .OfType() @@ -362,7 +376,7 @@ c.ClearOutput(); c.Attach(observer); }); - assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ForEachElementDo(c => + calculationsBelongingToNorm.ForEachElementDo(c => { c.Output = null; c.Attach(observer); @@ -435,7 +449,9 @@ } [Test] - public void GivenCalculationsWithOutput_WhenChangingNorm_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified() + [TestCaseSource(nameof(GetChangeNormCases))] + public void GivenCalculationsWithOutput_WhenChangingNorm_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified( + NormType normType, Func> getCalculationsFunc) { // Given DialogBoxHandler = (name, wnd) => @@ -445,12 +461,15 @@ }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + assessmentSection.FailureMechanismContribution.NormativeNorm = normType; + IEnumerable expectedCalculationsToClear = getCalculationsFunc(assessmentSection); + IEnumerable expectedAffectedObjects = new IObservable[] { assessmentSection.FailureMechanismContribution } - .Concat(assessmentSection.WaterLevelCalculationsForLowerLimitNorm) + .Concat(expectedCalculationsToClear) .ToArray(); var mocks = new MockRepository(); @@ -463,7 +482,7 @@ var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection); // Precondition - CollectionAssert.IsNotEmpty(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.Where(c => c.HasOutput)); + CollectionAssert.IsNotEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); // When var actionPerformed = false; @@ -477,12 +496,14 @@ TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1); Assert.IsTrue(actionPerformed); - CollectionAssert.IsEmpty(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.Where(c => c.HasOutput)); + CollectionAssert.IsEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); mocks.VerifyAll(); } [Test] - public void GivenCalculationsWithoutOutput_WhenChangingNorm_ThenActionPerformedAndContributionNotified() + [TestCaseSource(nameof(GetChangeNormCases))] + public void GivenCalculationsWithoutOutput_WhenChangingNorm_ThenActionPerformedAndContributionNotified( + NormType normType, Func> getCalculationsFunc) { // Given DialogBoxHandler = (name, wnd) => @@ -492,13 +513,16 @@ }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + assessmentSection.FailureMechanismContribution.NormativeNorm = normType; + IEnumerable calculationsBelongingToNorm = getCalculationsFunc(assessmentSection); + var mocks = new MockRepository(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()).Repeat.Once(); mocks.ReplayAll(); - assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ForEachElementDo(c => + calculationsBelongingToNorm.ForEachElementDo(c => { c.Output = null; c.Attach(observer); @@ -516,5 +540,25 @@ Assert.IsTrue(actionPerformed); mocks.VerifyAll(); } + + private static IEnumerable GetChangeNormativeNormCases() + { + yield return new TestCaseData( + NormType.LowerLimit, new Func>( + section => section.WaterLevelCalculationsForLowerLimitNorm)); + yield return new TestCaseData( + NormType.Signaling, new Func>( + section => section.WaterLevelCalculationsForSignalingNorm)); + } + + private static IEnumerable GetChangeNormCases() + { + yield return new TestCaseData( + NormType.LowerLimit, new Func>( + section => section.WaterLevelCalculationsForSignalingNorm)); + yield return new TestCaseData( + NormType.Signaling, new Func>( + section => section.WaterLevelCalculationsForLowerLimitNorm)); + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs =================================================================== diff -u -r4b889a77a0b2a44d9eadc54540334140415177c8 -r0403b90b2a1c32b0a8e37a2ca14141ba76bba502 --- Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs (.../RiskeerDataSynchronizationServiceTest.cs) (revision 4b889a77a0b2a44d9eadc54540334140415177c8) +++ Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs (.../RiskeerDataSynchronizationServiceTest.cs) (revision 0403b90b2a1c32b0a8e37a2ca14141ba76bba502) @@ -28,7 +28,6 @@ using Riskeer.ClosingStructures.Data; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.Contribution; using Riskeer.Common.Data.DikeProfiles; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; @@ -358,70 +357,42 @@ } [Test] - public void ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm_AssessmentSectionNull_ThrowsArgumentNullException() + public void ClearHydraulicBoundaryLocationCalculationOutput_CalculationsNull_ThrowsArgumentNullException() { // Call - void Call() => RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm(null); + void Call() => RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput((IEnumerable) null); // Assert var exception = Assert.Throws(Call); - Assert.AreEqual("assessmentSection", exception.ParamName); + Assert.AreEqual("calculations", exception.ParamName); } [Test] - [TestCase(NormType.LowerLimit)] - [TestCase(NormType.Signaling)] - public void ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm_NormativeNormIsLowerLimitNorm_ClearDataAndReturnAffectedObjects(NormType normType) + public void ClearHydraulicBoundaryLocationCalculationOutput_WithCalculations_ClearDataAndReturnAffectedObjects() { // Setup var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + var calculations = new[] { - HydraulicBoundaryDatabase = + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation1) { - Locations = - { - hydraulicBoundaryLocation1, - hydraulicBoundaryLocation2 - } + Output = new TestHydraulicBoundaryLocationCalculationOutput() }, - FailureMechanismContribution = + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation2) { - NormativeNorm = normType + Output = new TestHydraulicBoundaryLocationCalculationOutput() } }; - assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] - { - hydraulicBoundaryLocation1, - hydraulicBoundaryLocation2 - }); - - HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculationForLowerLimitNorm = assessmentSection.WaterLevelCalculationsForLowerLimitNorm - .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); - HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculationForSignalingNorm = assessmentSection.WaterLevelCalculationsForSignalingNorm - .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); - - hydraulicBoundaryLocationCalculationForLowerLimitNorm.Output = new TestHydraulicBoundaryLocationCalculationOutput(); - hydraulicBoundaryLocationCalculationForSignalingNorm.Output = new TestHydraulicBoundaryLocationCalculationOutput(); - - var expectedAffectedItems = new List - { - normType == NormType.LowerLimit - ? hydraulicBoundaryLocationCalculationForLowerLimitNorm - : hydraulicBoundaryLocationCalculationForSignalingNorm - }; - // Call - IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputForNormativeNorm( - assessmentSection); + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(calculations); // Assert - CollectionAssert.AreEquivalent(expectedAffectedItems, affectedObjects); - Assert.AreEqual(normType != NormType.LowerLimit, hydraulicBoundaryLocationCalculationForLowerLimitNorm.HasOutput); - Assert.AreEqual(normType != NormType.Signaling, hydraulicBoundaryLocationCalculationForSignalingNorm.HasOutput); + + CollectionAssert.AreEquivalent(calculations, affectedObjects); + Assert.IsTrue(calculations.All(c => !c.HasOutput)); } [Test] @@ -1861,7 +1832,7 @@ yield return sectionResult; } } - + private static IAssessmentSection GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations() { var assessmentSection = new AssessmentSectionStub();