Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs (.../StabilityPointStructuresDataSynchronizationServiceTest.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresDataSynchronizationServiceTest.cs (.../StabilityPointStructuresDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -62,7 +62,7 @@ // Assert // Note: To make sure the clear is performed regardless of what is done with - // the return result, no ToArray() should not be called before these assertions: + // the return result, no ToArray() should be called before these assertions: Assert.IsTrue(failureMechanism.Calculations.All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems); @@ -80,25 +80,31 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedObjects() { // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - StructuresCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast>() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + 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(); // Call - IEnumerable> affectedItems = + IEnumerable affectedItems = StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with - // the return result, no ToArray() should not be called before these assertions: + // the return result, no ToArray() should be called before these assertions: Assert.IsTrue(failureMechanism.Calculations.Cast>() .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); - CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems); + CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs), + affectedItems); } [Test] @@ -123,7 +129,7 @@ // Assert // Note: To make sure the clear is performed regardless of what is done with - // the return result, no ToArray() should not be called before these assertions: + // the return result, no ToArray() should be called before these assertions: CollectionAssert.IsEmpty(failureMechanism.Sections); CollectionAssert.IsEmpty(failureMechanism.SectionResults); CollectionAssert.IsEmpty(failureMechanism.CalculationsGroup.Children); @@ -144,26 +150,31 @@ // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); StabilityPointStructure structure = failureMechanism.StabilityPointStructures[0]; - StructuresCalculation[] calculatiosnWithStructure = failureMechanism.Calculations + StructuresCalculation[] calculationsWithStructure = failureMechanism.Calculations .Cast>() .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); StabilityPointStructuresFailureMechanismSectionResult[] sectionResultsWithStructure = failureMechanism.SectionResults - .Where(sr => calculatiosnWithStructure.Contains(sr.Calculation)) + .Where(sr => calculationsWithStructure.Contains(sr.Calculation)) .ToArray(); + int originalNumberOfSectionResultAssignments = failureMechanism.SectionResults.Count(sr => sr.Calculation != null); + StabilityPointStructuresFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .Where(sr => calculationsWithStructure.Contains(sr.Calculation)) + .ToArray(); + // Precondition - CollectionAssert.IsNotEmpty(calculatiosnWithStructure); + CollectionAssert.IsNotEmpty(calculationsWithStructure); CollectionAssert.IsNotEmpty(sectionResultsWithStructure); // Call IEnumerable affectedObjects = StabilityPointStructuresDataSynchronizationService.RemoveStructure(failureMechanism, structure); // Assert // Note: To make sure the clear is performed regardless of what is done with - // the return result, no ToArray() should not be called before these assertions: + // the return result, no ToArray() should be called before these assertions: CollectionAssert.DoesNotContain(failureMechanism.StabilityPointStructures, structure); - foreach (StructuresCalculation calculation in calculatiosnWithStructure) + foreach (StructuresCalculation calculation in calculationsWithStructure) { Assert.IsNull(calculation.InputParameters.Structure); } @@ -173,17 +184,19 @@ } IObservable[] array = affectedObjects.ToArray(); - Assert.AreEqual(1 + calculatiosnWithStructure.Length + sectionResultsWithStructure.Length, + Assert.AreEqual(1 + calculationsWithStructure.Length + sectionResultsWithStructure.Length, array.Length); CollectionAssert.Contains(array, failureMechanism.StabilityPointStructures); - foreach (StructuresCalculation calculation in calculatiosnWithStructure) + foreach (StructuresCalculation calculation in calculationsWithStructure) { CollectionAssert.Contains(array, calculation.InputParameters); } foreach (StabilityPointStructuresFailureMechanismSectionResult result in sectionResultsWithStructure) { CollectionAssert.Contains(array, result); } + Assert.AreEqual(originalNumberOfSectionResultAssignments - sectionResults.Length, failureMechanism.SectionResults.Count(sr => sr.Calculation != null), + "Other section results with a different calculation/structure should still have their association."); } private StabilityPointStructuresFailureMechanism CreateFullyConfiguredFailureMechanism()