Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -33,6 +33,17 @@ public class HeightStructuresDataSynchronizationServiceTest { [Test] + public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearAllCalculationOutput_WithOutput_ClearsCalculationsOutput() { // Setup @@ -92,6 +103,17 @@ } [Test] + public void ClearHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearHydraulicBoundaryLocations_WithHydraulicBoundaryLocation_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() { // Setup @@ -134,5 +156,144 @@ calculation2 }, affectedItems); } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOuputAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } } } \ No newline at end of file