Index: Riskeer/Piping/src/Riskeer.Piping.Service/PipingDataSynchronizationService.cs =================================================================== diff -u -re2b60a183f95fefe71686ac319c22bb7ad644bca -raa2451eef5ed94eca2be5e7fcbed50517d870ff8 --- Riskeer/Piping/src/Riskeer.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision e2b60a183f95fefe71686ac319c22bb7ad644bca) +++ Riskeer/Piping/src/Riskeer.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision aa2451eef5ed94eca2be5e7fcbed50517d870ff8) @@ -30,6 +30,7 @@ using Riskeer.Common.IO.SoilProfile; using Riskeer.Common.Service; using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; using Riskeer.Piping.Data.SoilProfile; using Riskeer.Piping.Primitives; @@ -41,6 +42,31 @@ public static class PipingDataSynchronizationService { /// + /// Clears the output of the given . + /// + /// The to clear the output for. + /// Thrown when is null. + /// All objects that have been changed. + public static IEnumerable ClearCalculationOutput(IPipingCalculationScenario calculation) + { + if (calculation == null) + { + throw new ArgumentNullException(nameof(calculation)); + } + + if (calculation.HasOutput) + { + calculation.ClearOutput(); + return new[] + { + calculation + }; + } + + return Enumerable.Empty(); + } + + /// /// Clears the output for all calculations in the . /// /// The which contains the calculations. @@ -60,28 +86,22 @@ } /// - /// Clears the output of the given . + /// Clears the output for all in the . /// - /// The to clear the output for. - /// Thrown when is null. - /// All objects that have been changed. - public static IEnumerable ClearCalculationOutput(IPipingCalculationScenario calculation) + /// The which contains the calculations. + /// An of calculations which are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearAllProbabilisticCalculationOutput(PipingFailureMechanism failureMechanism) { - if (calculation == null) + if (failureMechanism == null) { - throw new ArgumentNullException(nameof(calculation)); + throw new ArgumentNullException(nameof(failureMechanism)); } - if (calculation.HasOutput) - { - calculation.ClearOutput(); - return new[] - { - calculation - }; - } - - return Enumerable.Empty(); + return failureMechanism.Calculations + .OfType() + .SelectMany(ClearCalculationOutput) + .ToArray(); } /// Index: Riskeer/Piping/test/Riskeer.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs =================================================================== diff -u -r1250f75d43f878e4ad35f226cea3c68f556964c2 -raa2451eef5ed94eca2be5e7fcbed50517d870ff8 --- Riskeer/Piping/test/Riskeer.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision 1250f75d43f878e4ad35f226cea3c68f556964c2) +++ Riskeer/Piping/test/Riskeer.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision aa2451eef5ed94eca2be5e7fcbed50517d870ff8) @@ -27,6 +27,7 @@ using Riskeer.Common.Data.Calculation; using Riskeer.Common.Service; using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; using Riskeer.Piping.Data.SoilProfile; using Riskeer.Piping.Data.TestUtil; using Riskeer.Piping.Primitives; @@ -41,10 +42,10 @@ public void ClearCalculationOutput_CalculationNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => PipingDataSynchronizationService.ClearCalculationOutput(null); + void Call() => PipingDataSynchronizationService.ClearCalculationOutput(null); // Assert - var exception = Assert.Throws(test); + var exception = Assert.Throws(Call); Assert.AreEqual("calculation", exception.ParamName); } @@ -85,10 +86,10 @@ public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() { // Call - TestDelegate call = () => PipingDataSynchronizationService.ClearAllCalculationOutput(null); + void Call() => PipingDataSynchronizationService.ClearAllCalculationOutput(null); // Assert - var exception = Assert.Throws(call); + var exception = Assert.Throws(Call); Assert.AreEqual("failureMechanism", exception.ParamName); } @@ -113,13 +114,60 @@ } [Test] + public void ClearAllProbabilisticCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + void Call() => PipingDataSynchronizationService.ClearAllProbabilisticCalculationOutput(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearAllProbabilisticCalculationOutput_WithVariousCalculations_ClearsProbabilisticCalculationsOutputAndReturnsAffectedCalculations() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + failureMechanism.CalculationsGroup.Children.AddRange(new[] + { + new ProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithIllustrationPoints() + }, + new ProbabilisticPipingCalculationScenario + { + Output = PipingTestDataGenerator.GetRandomProbabilisticPipingOutputWithoutIllustrationPoints() + }, + new ProbabilisticPipingCalculationScenario() + }); + + ProbabilisticPipingCalculationScenario[] expectedAffectedCalculations = failureMechanism.Calculations + .OfType() + .Where(c => c.HasOutput) + .ToArray(); + + // Call + IEnumerable affectedItems = PipingDataSynchronizationService.ClearAllProbabilisticCalculationOutput(failureMechanism); + + // Assert + // Note: To make sure the clear is performed regardless of what is done with + // the return result, no ToArray() should be called before these assertions: + Assert.IsTrue(failureMechanism.Calculations + .OfType() + .All(c => !c.HasOutput)); + + CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems); + } + + [Test] public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() { // Call - TestDelegate call = () => PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + void Call() => PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); // Assert - var exception = Assert.Throws(call); + var exception = Assert.Throws(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }