Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs =================================================================== diff -u -rdcf38b56892032a9330058f71a7778bb550b0d30 -r8d1f6694d35a5bab21feedea51bdad3a6125a8c2 --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision dcf38b56892032a9330058f71a7778bb550b0d30) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision 8d1f6694d35a5bab21feedea51bdad3a6125a8c2) @@ -151,7 +151,9 @@ } var affectedItems = new List(); - foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) + foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>() + .Where(c => hydraulicBoundaryLocations.Contains( + c.InputParameters.HydraulicBoundaryLocation))) { affectedItems.AddRange(RiskeerCommonDataSynchronizationService.ClearCalculationOutput(calculation)); affectedItems.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocation(calculation.InputParameters)); Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs =================================================================== diff -u -r1bcc783d2896788b05cd13e7c2aa500ddcae8826 -r8d1f6694d35a5bab21feedea51bdad3a6125a8c2 --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision 1bcc783d2896788b05cd13e7c2aa500ddcae8826) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision 8d1f6694d35a5bab21feedea51bdad3a6125a8c2) @@ -298,170 +298,60 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup - var failureMechanism = new ClosingStructuresFailureMechanism(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); - var calculation1 = new StructuresCalculation + ClosingStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(hydraulicBoundaryLocation1); + failureMechanism.CalculationsGroup.Children.AddRange(new[] { - InputParameters = + new StructuresCalculationScenario { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation2 + } }, - Output = new TestStructuresOutput() - }; - - var calculation2 = new StructuresCalculation - { - InputParameters = + new StructuresCalculationScenario { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - }, - Output = new TestStructuresOutput() - }; - - var calculation3 = new StructuresCalculation(); - - failureMechanism.CalculationsGroup.Children.Add(calculation1); - failureMechanism.CalculationsGroup.Children.Add(calculation2); - failureMechanism.CalculationsGroup.Children.Add(calculation3); - - // Call - IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations( - failureMechanism, Enumerable.Empty()); - - // 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: - foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast>()) - { - Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); - Assert.IsNull(calculation.Output); - } - - CollectionAssert.AreEquivalent(new IObservable[] - { - calculation1, - calculation1.InputParameters, - calculation2, - calculation2.InputParameters - }, affectedItems); - } - - [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedInputs() - { - // Setup - var failureMechanism = new ClosingStructuresFailureMechanism(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); - - var calculation1 = new StructuresCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation2 + }, + Output = new TestStructuresOutput() } - }; + }); - var calculation2 = new StructuresCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - } - }; + IEnumerable> calculations = failureMechanism.Calculations.Cast>() + .ToArray(); - var calculation3 = new StructuresCalculation(); + IEnumerable> expectedAffectedCalculations = calculations.Where( + c => c.InputParameters.HydraulicBoundaryLocation == hydraulicBoundaryLocation1 + && c.HasOutput).ToArray(); - failureMechanism.CalculationsGroup.Children.Add(calculation1); - failureMechanism.CalculationsGroup.Children.Add(calculation2); - failureMechanism.CalculationsGroup.Children.Add(calculation3); + var expectedAffectedItems = new List(expectedAffectedCalculations); + expectedAffectedItems.AddRange(calculations.Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation == hydraulicBoundaryLocation1)); // Call IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations( - failureMechanism, Enumerable.Empty()); + failureMechanism, new[] + { + hydraulicBoundaryLocation1 + }); // 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: - foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast>()) - { - Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); - } + Assert.IsTrue(expectedAffectedCalculations.All(c => !c.HasOutput)); + Assert.IsTrue(calculations.All(c => c.InputParameters.HydraulicBoundaryLocation != hydraulicBoundaryLocation1)); - CollectionAssert.AreEqual(new[] - { - calculation1.InputParameters, - calculation2.InputParameters - }, affectedItems); + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOutputAndReturnsAffectedCalculations() - { - // Setup - var failureMechanism = new ClosingStructuresFailureMechanism(); - - var calculation1 = new StructuresCalculation - { - Output = new TestStructuresOutput() - }; - - var calculation2 = new StructuresCalculation - { - Output = new TestStructuresOutput() - }; - - var calculation3 = new StructuresCalculation(); - - failureMechanism.CalculationsGroup.Children.Add(calculation1); - failureMechanism.CalculationsGroup.Children.Add(calculation2); - failureMechanism.CalculationsGroup.Children.Add(calculation3); - - // Call - IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations( - failureMechanism, Enumerable.Empty()); - - // 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: - foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast>()) - { - Assert.IsNull(calculation.Output); - } - - CollectionAssert.AreEqual(new[] - { - calculation1, - calculation2 - }, affectedItems); - } - - [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationWithoutOutputAndHydraulicBoundaryLocation_ReturnNoAffectedCalculations() - { - // Setup - var failureMechanism = new ClosingStructuresFailureMechanism(); - - var calculation1 = new StructuresCalculation(); - var calculation2 = new StructuresCalculation(); - var calculation3 = new StructuresCalculation(); - - failureMechanism.CalculationsGroup.Children.Add(calculation1); - failureMechanism.CalculationsGroup.Children.Add(calculation2); - failureMechanism.CalculationsGroup.Children.Add(calculation3); - - // Call - IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations( - failureMechanism, Enumerable.Empty()); - - // Assert - CollectionAssert.IsEmpty(affectedItems); - } - - [Test] public void ClearReferenceLineDependentData_FailureMechanismNull_ThrowArgumentNullException() { // Call @@ -506,7 +396,7 @@ CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects); } - private ClosingStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() + private ClosingStructuresFailureMechanism CreateFullyConfiguredFailureMechanism(HydraulicBoundaryLocation hydraulicBoundaryLocation = null) { var section1 = new FailureMechanismSection("A", new[] { @@ -540,7 +430,10 @@ section2 }); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + if (hydraulicBoundaryLocation == null) + { + hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + } var calculation = new StructuresCalculationScenario {