Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -76,10 +76,10 @@ // 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: - foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) + // the return result, no ToArray() should be called before these assertions: + foreach (ICalculation calculation in failureMechanism.Calculations) { - Assert.IsNull(calculation.Output); + Assert.IsFalse(calculation.HasOutput); } CollectionAssert.AreEqual(new[] @@ -101,7 +101,7 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); @@ -136,22 +136,24 @@ // 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: foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) { Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); Assert.IsNull(calculation.Output); } - CollectionAssert.AreEqual(new[] + CollectionAssert.AreEquivalent(new IObservable[] { calculation1, - calculation2 + calculation1.InputParameters, + calculation2, + calculation2.InputParameters }, affectedItems); } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedInputs() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); @@ -184,16 +186,16 @@ // 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: foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) { Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); } CollectionAssert.AreEqual(new[] { - calculation1, - calculation2 + calculation1.InputParameters, + calculation2.InputParameters }, affectedItems); } @@ -224,10 +226,10 @@ // 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: - foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) + // the return result, no ToArray() should be called before these assertions: + foreach (ICalculation calculation in failureMechanism.Calculations) { - Assert.IsNull(calculation.Output); + Assert.IsFalse(calculation.HasOutput); } CollectionAssert.AreEqual(new[] @@ -280,7 +282,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); @@ -301,26 +303,31 @@ // Setup HeightStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); HeightStructure structure = failureMechanism.HeightStructures[0]; - StructuresCalculation[] calculatiosnWithStructure = failureMechanism.Calculations + StructuresCalculation[] calculationsWithStructure = failureMechanism.Calculations .Cast>() .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); HeightStructuresFailureMechanismSectionResult[] 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); + HeightStructuresFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .Where(sr => calculationsWithStructure.Contains(sr.Calculation)) + .ToArray(); + // Precondition - CollectionAssert.IsNotEmpty(calculatiosnWithStructure); + CollectionAssert.IsNotEmpty(calculationsWithStructure); CollectionAssert.IsNotEmpty(sectionResultsWithStructure); // Call IEnumerable affectedObjects = HeightStructuresDataSynchronizationService.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.HeightStructures, structure); - foreach (StructuresCalculation calculation in calculatiosnWithStructure) + foreach (StructuresCalculation calculation in calculationsWithStructure) { Assert.IsNull(calculation.InputParameters.Structure); } @@ -330,17 +337,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.HeightStructures); - foreach (StructuresCalculation calculation in calculatiosnWithStructure) + foreach (StructuresCalculation calculation in calculationsWithStructure) { CollectionAssert.Contains(array, calculation.InputParameters); } foreach (HeightStructuresFailureMechanismSectionResult 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 HeightStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() @@ -413,9 +422,9 @@ failureMechanism.AddSection(section1); failureMechanism.AddSection(section2); HeightStructuresFailureMechanismSectionResult result1 = failureMechanism.SectionResults - .First(sr => ReferenceEquals(sr.Section, section1)); + .First(sr => ReferenceEquals(sr.Section, section1)); HeightStructuresFailureMechanismSectionResult result2 = failureMechanism.SectionResults - .First(sr => ReferenceEquals(sr.Section, section2)); + .First(sr => ReferenceEquals(sr.Section, section2)); result1.Calculation = calculation1; result2.Calculation = calculation2;