Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs =================================================================== diff -u -r8e0365384823f022fbae3bb8104439c538fea0ba -r1d44f01d70bd2972c0499f0d8a19ae1e581baa9a --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs (.../StabilityPointStructuresDataSynchronizationService.cs) (revision 8e0365384823f022fbae3bb8104439c538fea0ba) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs (.../StabilityPointStructuresDataSynchronizationService.cs) (revision 1d44f01d70bd2972c0499f0d8a19ae1e581baa9a) @@ -149,7 +149,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/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -rf4512a03b7418c4171e76c6750d17ab8abb36351 -r1d44f01d70bd2972c0499f0d8a19ae1e581baa9a --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs (.../StabilityPointStructuresDataSynchronizationServiceTest.cs) (revision f4512a03b7418c4171e76c6750d17ab8abb36351) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs (.../StabilityPointStructuresDataSynchronizationServiceTest.cs) (revision 1d44f01d70bd2972c0499f0d8a19ae1e581baa9a) @@ -185,28 +185,54 @@ public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedObjects() { // Setup - StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - StructuresCalculation[] calculations = failureMechanism.Calculations.Cast>().ToArray(); - IObservable[] expectedAffectedCalculations = calculations.Where(c => c.HasOutput) - .Cast() - .ToArray(); - IObservable[] expectedAffectedCalculationInputs = calculations.Select(c => c.InputParameters) - .Where(i => i.HydraulicBoundaryLocation != null) - .Cast() - .ToArray(); + var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); + + StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(hydraulicBoundaryLocation1); + failureMechanism.CalculationsGroup.Children.AddRange(new[] + { + new StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation2 + } + }, + new StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation2 + }, + Output = new TestStructuresOutput() + } + }); + + StructuresCalculation[] calculations = failureMechanism.Calculations.Cast>() + .ToArray(); + + StructuresCalculation[] expectedAffectedCalculations = calculations.Where( + c => c.InputParameters.HydraulicBoundaryLocation == hydraulicBoundaryLocation1 + && c.HasOutput).ToArray(); + var expectedAffectedItems = new List(expectedAffectedCalculations); + expectedAffectedItems.AddRange(calculations.Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation == hydraulicBoundaryLocation1)); + // Call IEnumerable affectedItems = StabilityPointStructuresDataSynchronizationService.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: - Assert.IsTrue(failureMechanism.Calculations.Cast>() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(expectedAffectedCalculations.All(c => !c.HasOutput)); + Assert.IsTrue(calculations.All(c => c.InputParameters.HydraulicBoundaryLocation != hydraulicBoundaryLocation1)); - CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs), - affectedItems); + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); } [Test] @@ -326,7 +352,7 @@ } } - private StabilityPointStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() + private StabilityPointStructuresFailureMechanism CreateFullyConfiguredFailureMechanism(HydraulicBoundaryLocation hydraulicBoundaryLocation = null) { var section1 = new FailureMechanismSection("A", new[] { @@ -360,7 +386,10 @@ section2 }); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + if (hydraulicBoundaryLocation == null) + { + hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + } var calculation = new StructuresCalculationScenario {