Index: Riskeer/Common/src/Riskeer.Common.Service/RiskeerCommonDataSynchronizationService.cs =================================================================== diff -u -rc1a74b0264d164dc43c2fa7e29ee7f08dbc6d42f -r50f8289b961839168cca93a4ee70d97a49a2f337 --- Riskeer/Common/src/Riskeer.Common.Service/RiskeerCommonDataSynchronizationService.cs (.../RiskeerCommonDataSynchronizationService.cs) (revision c1a74b0264d164dc43c2fa7e29ee7f08dbc6d42f) +++ Riskeer/Common/src/Riskeer.Common.Service/RiskeerCommonDataSynchronizationService.cs (.../RiskeerCommonDataSynchronizationService.cs) (revision 50f8289b961839168cca93a4ee70d97a49a2f337) @@ -70,7 +70,7 @@ throw new ArgumentNullException(nameof(calculations)); } - var affectedCalculations = new List(); + var affectedCalculations = new List(); foreach (HydraulicBoundaryLocationCalculation calculation in calculations) { if (calculation.HasOutput && calculation.Output.HasGeneralResult) @@ -84,6 +84,36 @@ } /// + /// Clears the illustration points of the provided structure calculations. + /// + /// Object type of the structure calculation input. + /// Object type of the structure property of . + /// The calculations for which the illustration points need to be cleared. + /// All objects changed during the clear. + /// Thrown when is null. + public static IEnumerable ClearStructuresCalculationIllustrationPoints(IEnumerable> calculations) + where TStructureInput : StructuresInputBase, new() + where TStructure : StructureBase + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + var affectedCalculations = new List(); + foreach (StructuresCalculation calculation in calculations) + { + if (calculation.HasOutput && calculation.Output.HasGeneralResult) + { + calculation.ClearIllustrationPoints(); + affectedCalculations.Add(calculation); + } + } + + return affectedCalculations; + } + + /// /// Clears the output of the given . /// /// The to clear the output for. Index: Riskeer/Common/test/Riskeer.Common.Service.Test/RiskeerCommonDataSynchronizationServiceTest.cs =================================================================== diff -u -r74be61490932801465aed774fde44995db15dffc -r50f8289b961839168cca93a4ee70d97a49a2f337 --- Riskeer/Common/test/Riskeer.Common.Service.Test/RiskeerCommonDataSynchronizationServiceTest.cs (.../RiskeerCommonDataSynchronizationServiceTest.cs) (revision 74be61490932801465aed774fde44995db15dffc) +++ Riskeer/Common/test/Riskeer.Common.Service.Test/RiskeerCommonDataSynchronizationServiceTest.cs (.../RiskeerCommonDataSynchronizationServiceTest.cs) (revision 50f8289b961839168cca93a4ee70d97a49a2f337) @@ -167,6 +167,84 @@ } [Test] + public void ClearStructuresCalculationIllustrationPoints_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RiskeerCommonDataSynchronizationService.ClearStructuresCalculationIllustrationPoints(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void ClearStructuresCalculationIllustrationPoints_CalculationsWithAndWithoutIllustrationPoints_ClearsIllustrationPointAndReturnsAffectedCalculations() + { + // Setup + var originalOutputWithIllustrationPoints1 = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()); + var calculationWithIllustrationPoints1 = new TestStructuresCalculation + { + Output = originalOutputWithIllustrationPoints1 + }; + + var originalOutputWithIllustrationPoints2 = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()); + var calculationWithIllustrationPoints2 = new TestStructuresCalculation + { + Output = originalOutputWithIllustrationPoints2 + }; + + var originalOutput1 = new TestStructuresOutput(); + var calculationWithOutput1 = new TestStructuresCalculation + { + Output = originalOutput1 + }; + + var originalOutput2 = new TestStructuresOutput(); + var calculationWithOutput2 = new TestStructuresCalculation + { + Output = originalOutput2 + }; + + TestStructuresCalculation[] calculations = + { + new TestStructuresCalculation(), + calculationWithOutput1, + calculationWithIllustrationPoints1, + new TestStructuresCalculation(), + calculationWithOutput2, + calculationWithIllustrationPoints2, + new TestStructuresCalculation() + }; + + // Call + IEnumerable affectedObjects = RiskeerCommonDataSynchronizationService.ClearStructuresCalculationIllustrationPoints(calculations); + + // Assert + CollectionAssert.AreEquivalent(new[] + { + calculationWithIllustrationPoints1, + calculationWithIllustrationPoints2 + }, affectedObjects); + + TestStructuresCalculation[] calculationsWithOutput = + { + calculationWithOutput1, + calculationWithIllustrationPoints1, + calculationWithOutput2, + calculationWithIllustrationPoints2 + }; + + Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput)); + Assert.IsTrue(calculationsWithOutput.All(calc => !calc.Output.HasGeneralResult)); + + AssertStructuresOutput(originalOutput1, calculationWithOutput1.Output); + AssertStructuresOutput(originalOutput2, calculationWithOutput2.Output); + + AssertStructuresOutput(originalOutputWithIllustrationPoints1, calculationWithIllustrationPoints1.Output); + AssertStructuresOutput(originalOutputWithIllustrationPoints2, calculationWithIllustrationPoints2.Output); + } + + [Test] public void ClearCalculationOutput_CalculationNull_ThrowsArgumentNullException() { // Call @@ -226,37 +304,37 @@ var foreshoreProfileToBeRemoved = new TestForeshoreProfile(new Point2D(0, 0)); var foreshoreProfile = new TestForeshoreProfile(new Point2D(1, 1)); - var calculation1 = new StructuresCalculation + var calculation1 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfile } }; - var calculation2 = new StructuresCalculation + var calculation2 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfileToBeRemoved } }; - var calculation3 = new StructuresCalculation + var calculation3 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfileToBeRemoved }, Output = new TestStructuresOutput() }; - StructuresCalculation[] calculations = + StructuresCalculation[] calculations = { calculation1, calculation2, calculation3 }; // Call - IEnumerable affectedObjects = RiskeerCommonDataSynchronizationService.ClearForeshoreProfile( + IEnumerable affectedObjects = RiskeerCommonDataSynchronizationService.ClearForeshoreProfile( calculations, foreshoreProfileToBeRemoved); // Assert @@ -284,17 +362,9 @@ Assert.AreEqual(expectedOutput.CalculationConvergence, actualOutput.CalculationConvergence); } - private class TestStructureInput : StructuresInputBase + private static void AssertStructuresOutput(StructuresOutput expectedOutput, StructuresOutput actualOutput) { - public override bool IsStructureInputSynchronized - { - get - { - return false; - } - } - - public override void SynchronizeStructureInput() {} + Assert.AreEqual(expectedOutput.Reliability, actualOutput.Reliability); } } } \ No newline at end of file