Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs =================================================================== diff -u -rffe405e6b0f8b4d10e6be78cf7735c554eb42a93 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision ffe405e6b0f8b4d10e6be78cf7735c554eb42a93) +++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -81,7 +81,7 @@ observableTarget.NotifyObservers(); } - foreach (var changedObservableObject in AffectedNonTargetObservableInstances.Where(o => !ReferenceEquals(o, ImportTarget))) + foreach (var changedObservableObject in AffectedNonTargetObservableInstances) { changedObservableObject.NotifyObservers(); } @@ -108,7 +108,7 @@ /// /// Gets all objects that have been affected during the call - /// that implement and which are were not the targeted object + /// that implement and which are not the targeted object /// to import the data to. /// /// If no changes were made to the data model (for example during a cancel), Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -63,30 +63,23 @@ /// Clears the and output for all the calculations /// in the . /// - /// The + /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when /// is null. - public static IEnumerable> ClearAllCalculationOutputAndHydraulicBoundaryLocations(ClosingStructuresFailureMechanism failureMechanism) + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(ClosingStructuresFailureMechanism failureMechanism) { if (failureMechanism == null) { throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection>(); - + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast>()) { - var calculationChanged = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; @@ -125,24 +118,24 @@ /// Removes the given closing structure and all dependent data, either directly or indirectly, /// from the failure mechanism. /// - /// The failure mechanism with at least 1 structure. + /// The failure mechanism containing . /// The structure to be removed. /// All objects affected by the removal. public static IEnumerable RemoveStructure(ClosingStructuresFailureMechanism failureMechanism, ClosingStructure structure) { var changedObservables = new HashSet(); - StructuresCalculation[] heightStructureCalculations = failureMechanism.Calculations - .Cast>() - .ToArray(); - StructuresCalculation[] calculationWithRemovedClosingStructure = heightStructureCalculations + StructuresCalculation[] closingStructureCalculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedClosingStructure = closingStructureCalculations .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); foreach (StructuresCalculation calculation in calculationWithRemovedClosingStructure) { calculation.InputParameters.Structure = null; IEnumerable> affectedSectionResults = - StructuresHelper.Delete(failureMechanism.SectionResults, calculation, heightStructureCalculations); + StructuresHelper.Delete(failureMechanism.SectionResults, calculation, closingStructureCalculations); foreach (StructuresFailureMechanismSectionResult result in affectedSectionResults) { changedObservables.Add(result); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -76,7 +76,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: foreach (StructuresCalculation calculation in failureMechanism.Calculations.Cast>()) { Assert.IsNull(calculation.Output); @@ -101,7 +101,7 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); @@ -132,26 +132,28 @@ failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call - IEnumerable> affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.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: foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.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 ClosingStructuresFailureMechanism(); @@ -180,20 +182,20 @@ failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call - IEnumerable> affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.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: foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast>()) { Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); } CollectionAssert.AreEqual(new[] { - calculation1, - calculation2 + calculation1.InputParameters, + calculation2.InputParameters }, affectedItems); } @@ -220,11 +222,11 @@ failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call - IEnumerable> affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.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: foreach (StructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast>()) { Assert.IsNull(calculation.Output); @@ -252,7 +254,7 @@ failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call - IEnumerable> affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + IEnumerable affectedItems = ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); // Assert CollectionAssert.IsEmpty(affectedItems); @@ -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 ClosingStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); ClosingStructure structure = failureMechanism.ClosingStructures[0]; - StructuresCalculation[] calculatiosnWithStructure = failureMechanism.Calculations + StructuresCalculation[] calculationsWithStructure = failureMechanism.Calculations .Cast>() .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); ClosingStructuresFailureMechanismSectionResult[] 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); + ClosingStructuresFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .Where(sr => calculationsWithStructure.Contains(sr.Calculation)) + .ToArray(); + // Precondition - CollectionAssert.IsNotEmpty(calculatiosnWithStructure); + CollectionAssert.IsNotEmpty(calculationsWithStructure); CollectionAssert.IsNotEmpty(sectionResultsWithStructure); // Call IEnumerable affectedObjects = ClosingStructuresDataSynchronizationService.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.ClosingStructures, 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.ClosingStructures); - foreach (StructuresCalculation calculation in calculatiosnWithStructure) + foreach (StructuresCalculation calculation in calculationsWithStructure) { CollectionAssert.Contains(array, calculation.InputParameters); } foreach (ClosingStructuresFailureMechanismSectionResult 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 ClosingStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r853f384d81f2125022a669589fc993a7fd1dfe42 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 853f384d81f2125022a669589fc993a7fd1dfe42) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -1,4 +1,25 @@ -//------------------------------------------------------------------------------ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.18444 Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs =================================================================== diff -u -rffe405e6b0f8b4d10e6be78cf7735c554eb42a93 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision ffe405e6b0f8b4d10e6be78cf7735c554eb42a93) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -158,7 +158,7 @@ NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechanism_sections, 3, 3); } - changedObservables.AddRange(replacementHandler.Replace(ImportTarget, importedReferenceLine)); + changedObservables.AddRange(replacementHandler.Replace(ImportTarget, importedReferenceLine).Where(o => !ReferenceEquals(o, ImportTarget))); } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataSynchronizationService.cs (.../RingtoetsCommonDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataSynchronizationService.cs (.../RingtoetsCommonDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,10 +21,13 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; using Ringtoets.HydraRing.Data; @@ -76,6 +79,27 @@ return Enumerable.Empty(); } + /// + /// Clears the given foreshore profile from a collection. + /// + /// Object type of the structure calculation input. + /// Object type of the structure property of . + /// The calculations. + /// The profile to be cleared. + /// All affected objects by the clear. + public static IEnumerable ClearForeshoreProfile(IEnumerable> calculations, ForeshoreProfile profile) + where TStructureInput : StructuresInputBase, new() + where TStructure : StructureBase + { + var affectedObjects = new Collection(); + foreach (StructuresCalculation calculation in calculations.Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile))) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + return affectedObjects; + } + private static IEnumerable ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryLocation location) { if (!double.IsNaN(location.DesignWaterLevel) || Index: Ringtoets/Common/src/Ringtoets.Common.Utils/StructuresHelper.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/src/Ringtoets.Common.Utils/StructuresHelper.cs (.../StructuresHelper.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/Common/src/Ringtoets.Common.Utils/StructuresHelper.cs (.../StructuresHelper.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -106,6 +106,7 @@ /// The which has a location that has been updated. /// The of that were left after removing /// . + /// All affected objects by the deletion. /// Thrown when any input parameter is null or when an element /// in is null. /// Thrown when element in is Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs =================================================================== diff -u -rffe405e6b0f8b4d10e6be78cf7735c554eb42a93 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision ffe405e6b0f8b4d10e6be78cf7735c554eb42a93) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -155,11 +155,9 @@ var assessmentSection = mocks.Stub(); var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) - .Return(true) .Repeat.Never(); - handler.Expect(h => h.Replace(Arg.Is.Same(assessmentSection), - Arg.Is.NotNull)) - .Return(Enumerable.Empty()) + handler.Expect(h => h.Replace(null, null)) + .IgnoreArguments() .Repeat.Never(); mocks.ReplayAll(); @@ -187,11 +185,9 @@ var assessmentSection = mocks.Stub(); var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) - .Return(true) .Repeat.Never(); - handler.Expect(h => h.Replace(Arg.Is.Same(assessmentSection), - Arg.Is.NotNull)) - .Return(Enumerable.Empty()) + handler.Expect(h => h.Replace(null, null)) + .IgnoreArguments() .Repeat.Never(); mocks.ReplayAll(); @@ -222,9 +218,8 @@ assessmentSection.ReferenceLine = originalReferenceLine; var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()).Return(false); - handler.Expect(h => h.Replace(Arg.Is.Same(assessmentSection), - Arg.Is.NotNull)) - .Return(Enumerable.Empty()) + handler.Expect(h => h.Replace(null, null)) + .IgnoreArguments() .Repeat.Never(); mocks.ReplayAll(); @@ -257,9 +252,8 @@ handler.Expect(h => h.ConfirmReplace()) .WhenCalled(invocation => importer.Cancel()) .Return(acceptRemovalOfReferenceLineDependentData); - handler.Expect(h => h.Replace(Arg.Is.Anything, - Arg.Is.Anything)) - .Return(Enumerable.Empty()) + handler.Expect(h => h.Replace(null, null)) + .IgnoreArguments() .Repeat.Never(); mocks.ReplayAll(); @@ -279,7 +273,6 @@ var assessmentSection = mocks.Stub(); var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) - .Return(true) .Repeat.Never(); handler.Expect(h => h.Replace(Arg.Is.Same(assessmentSection), Arg.Is.NotNull)) @@ -378,9 +371,8 @@ handler.Expect(h => h.ConfirmReplace()) .WhenCalled(invocation => importer.Cancel()) .Return(true); - handler.Expect(h => h.Replace(Arg.Is.Same(assessmentSection), - Arg.Is.NotNull)) - .Return(Enumerable.Empty()) + handler.Expect(h => h.Replace(null, null)) + .IgnoreArguments() .Repeat.Never(); mocks.ReplayAll(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -ra91af2b4cf186d4c53e839f6ce44b2ffc2895831 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision a91af2b4cf186d4c53e839f6ce44b2ffc2895831) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -67,7 +67,7 @@ - + @@ -113,6 +113,10 @@ {74CBA865-9338-447F-BAD9-28312446AE84} Ringtoets.HydraRing.Calculation.TestUtil + + {c033c69a-a1e3-4438-9c2c-eecca27bcba3} + Ringtoets.HydraRing.Data.TestUtil + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Fisheye: Tag dee01f6d6c15af0cc124816bfe99c7658af8995d refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServices.Test.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -0,0 +1,234 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Data; +using Ringtoets.HydraRing.Data.TestUtil; + +namespace Ringtoets.Common.Service.Test +{ + [TestFixture] + public class RingtoetsCommonDataSynchronizationServiceTest + { + [Test] + public void ClearHydraulicBoundaryLocationOutput_LocationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("locations", exception.ParamName); + } + + [Test] + [TestCase(3.4, 5.3)] + [TestCase(3.4, double.NaN)] + [TestCase(double.NaN, 8.5)] + public void ClearHydraulicBoundaryLocationOutput_LocationWithData_ClearsDataAndReturnsTrue(double designWaterLevel, double waveHeight) + { + // Setup + var location = new HydraulicBoundaryLocation(1, string.Empty, 0, 0) + { + DesignWaterLevel = (RoundedDouble) designWaterLevel, + WaveHeight = (RoundedDouble) waveHeight + }; + + var locations = new ObservableList + { + location + }; + + // Call + IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); + + // Assert + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + + CollectionAssert.AreEqual(new[] + { + location + }, affectedObjects); + } + + [Test] + public void ClearHydraulicBoundaryLocationOutput_HydraulicBoundaryDatabaseWithoutLocations_ReturnsFalse() + { + // Setup + var locations = new ObservableList(); + + // Call + IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); + + // Assert + CollectionAssert.IsEmpty(affectedObjects); + } + + [Test] + public void ClearHydraulicBoundaryLocationOutput_LocationWithoutWaveHeightAndDesignWaterLevel_ReturnsFalse() + { + // Setup + var locations = new ObservableList + { + new TestHydraulicBoundaryLocation() + }; + + // Call + IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(locations); + + // Assert + CollectionAssert.IsEmpty(affectedObjects); + } + + [Test] + public void ClearCalculationOutput_CalculationNull_ThrowsArgumentNullException() + { + // Setup + StructuresCalculation calculation = null; + + // Call + TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculation", exception.ParamName); + } + + [Test] + public void ClearCalculationOutput_WithCalculation_ClearsOutput() + { + // Setup + var calculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(1, 1, 1, 1, 1) + }; + + // Call + IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); + + // 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.IsNull(calculation.Output); + + CollectionAssert.AreEqual(new[] + { + calculation + }, changedObjects); + } + + [Test] + public void ClearCalculationOutput_CalculationWithoutOutput_DoNothing() + { + // Setup + var calculation = new StructuresCalculation + { + Output = null + }; + + // Call + IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); + + // Assert + CollectionAssert.IsEmpty(changedObjects); + } + + [Test] + public void ClearForeshoreProfile_CalculationsWithForeshoreProfile_ClearForeshoreProfileAndReturnAffectedInputs() + { + // Setup + var foreshoreProfileToBeRemoved = new TestForeshoreProfile(new Point2D(0,0)); + var foreshoreProfile = new TestForeshoreProfile(new Point2D(1, 1)); + + var calculation1 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfile + } + }; + var calculation2 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfileToBeRemoved + } + }; + var calculations = new[] + { + calculation1, + calculation2 + }; + + // Call + IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile( + calculations, foreshoreProfileToBeRemoved); + + // Assert + Assert.IsNull(calculation2.InputParameters.ForeshoreProfile); + Assert.IsNotNull(calculation1.InputParameters.ForeshoreProfile); + + CollectionAssert.AreEqual(new[] + { + calculation2.InputParameters + }, affectedObjects); + } + + private class TestInput : ICalculationInput + { + public void Attach(IObserver observer) + { + throw new NotImplementedException(); + } + + public void Detach(IObserver observer) + { + throw new NotImplementedException(); + } + + public void NotifyObservers() + { + throw new NotImplementedException(); + } + } + + private class SimpleStructuresInput : StructuresInputBase + { + protected override void UpdateStructureParameters() + { + + } + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.GrassCoverErosionInwards.Data; @@ -88,8 +87,7 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removal of data. + /// An of objects which are affected by removal of data. /// Thrown when /// is null. public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(GrassCoverErosionInwardsFailureMechanism failureMechanism) @@ -99,16 +97,11 @@ throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection(); + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast()) { - bool calculationChanged = ClearCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(ClearCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -60,7 +60,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.IsNull(calculation.Output); CollectionAssert.AreEqual(new[] @@ -110,7 +110,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); @@ -128,26 +128,37 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - GrassCoverErosionInwardsCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + IEnumerable grassCoverErosionInwardsCalculations = + failureMechanism.Calculations + .Cast() + .ToArray(); + IObservable[] expectedAffectedCalculations = grassCoverErosionInwardsCalculations + .Where(c => c.HasOutput) + .Cast() + .ToArray(); + IObservable[] expectedAffectedCalculationInputs = grassCoverErosionInwardsCalculations + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null) + .Cast() + .ToArray(); // Call IEnumerable affectedItems = GrassCoverErosionInwardsDataSynchronizationService.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] @@ -172,7 +183,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); Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs (.../GrassCoverErosionOutwardsDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsDataSynchronizationService.cs (.../GrassCoverErosionOutwardsDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.GrassCoverErosionOutwards.Data; @@ -67,8 +66,7 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removal of data. + /// An of objects which are affected by removal of data. /// Thrown when /// is null. public static IEnumerable ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations( @@ -79,16 +77,11 @@ throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection(); + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast()) { - bool calculationChanged = ClearWaveConditionsCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(ClearWaveConditionsCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsDataSynchronizationServiceTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionOutwardsDataSynchronizationServiceTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionOutwardsDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -46,7 +46,7 @@ } [Test] - public void ClearWaveConditionsCalculation_WithCalculation_OutputNull() + public void ClearWaveConditionsCalculation_WithCalculation_OutputNullAndReturnAffectedCalculation() { // Setup var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation @@ -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.IsNull(calculation.Output); CollectionAssert.AreEqual(new[] @@ -72,7 +72,7 @@ } [Test] - public void ClearWaveConditionsCalculation_CalculationWithoutOutput_OutputNull() + public void ClearWaveConditionsCalculation_CalculationWithoutOutput_DoNothing() { // Setup var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation @@ -99,26 +99,32 @@ } [Test] - public void ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsOutputAndReturnsAffectedCalculations() + public void ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsOutputAndReturnsAffectedObjects() { // Setup GrassCoverErosionOutwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - GrassCoverErosionOutwardsWaveConditionsCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + GrassCoverErosionOutwardsWaveConditionsCalculation[] 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 = GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(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.AreEqual(expectedAffectedCalculations, affectedItems); + CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs), + affectedItems); } [Test] @@ -147,7 +153,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.AreEqual(expectedAffectedCalculations, affectedItems); @@ -175,7 +181,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.WaveConditionsCalculationGroup.Children); Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.Common.Data.Structures; @@ -65,8 +64,7 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when /// is null. public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(HeightStructuresFailureMechanism failureMechanism) @@ -76,16 +74,11 @@ throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection>(); + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast>()) { - var calculationChanged = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; } @@ -125,7 +118,7 @@ /// Removes the given height structure and all dependent data, either directly or indirectly, /// from the failure mechanism. /// - /// The failure mechanism with at least 1 structure. + /// The failure mechanism containing . /// The structure to be removed. /// All objects affected by the removal. public static IEnumerable RemoveStructure(HeightStructuresFailureMechanism failureMechanism, HeightStructure structure) 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; Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -147,7 +147,7 @@ } /// - /// Looks up a localized string similar to Na het importeren van een aangepaste ligging van de referentielijn zullen alle geimporteerde en berekende gegevens van faalmechanismen worden gewist. + /// Looks up a localized string similar to Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van faalmechanismen worden gewist. /// ///Wilt u doorgaan?. /// Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -143,7 +143,7 @@ Hs(norm) - Na het importeren van een aangepaste ligging van de referentielijn zullen alle geimporteerde en berekende gegevens van faalmechanismen worden gewist. + Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van faalmechanismen worden gewist. Wilt u doorgaan? Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -212,7 +212,7 @@ /// /// The assessment section. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// is null. public static IEnumerable ClearReferenceLine(IAssessmentSection assessmentSection) { @@ -272,7 +272,6 @@ } } - // Lastly: clear the reference line: assessmentSection.ReferenceLine = null; list.Add(assessmentSection); @@ -283,11 +282,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(HeightStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -301,17 +300,8 @@ } var changedObservables = new List(); - StructuresCalculation[] calculations = failureMechanism.Calculations - .Cast>() - .ToArray(); - StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations - .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) - .ToArray(); - foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) - { - calculation.InputParameters.ForeshoreProfile = null; - changedObservables.Add(calculation.InputParameters); - } + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); failureMechanism.ForeshoreProfiles.Remove(profile); changedObservables.Add(failureMechanism.ForeshoreProfiles); @@ -323,11 +313,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(ClosingStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -341,17 +331,8 @@ } var changedObservables = new List(); - StructuresCalculation[] calculations = failureMechanism.Calculations - .Cast>() - .ToArray(); - StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations - .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) - .ToArray(); - foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) - { - calculation.InputParameters.ForeshoreProfile = null; - changedObservables.Add(calculation.InputParameters); - } + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); failureMechanism.ForeshoreProfiles.Remove(profile); changedObservables.Add(failureMechanism.ForeshoreProfiles); @@ -363,11 +344,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(StabilityPointStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -381,17 +362,8 @@ } var changedObservables = new List(); - StructuresCalculation[] calculations = failureMechanism.Calculations - .Cast>() - .ToArray(); - StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations - .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) - .ToArray(); - foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) - { - calculation.InputParameters.ForeshoreProfile = null; - changedObservables.Add(calculation.InputParameters); - } + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); failureMechanism.ForeshoreProfiles.Remove(profile); changedObservables.Add(failureMechanism.ForeshoreProfiles); @@ -403,11 +375,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(StabilityStoneCoverFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -437,11 +409,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(WaveImpactAsphaltCoverFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -471,11 +443,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveForeshoreProfile(GrassCoverErosionOutwardsFailureMechanism failureMechanism, ForeshoreProfile profile) { @@ -505,11 +477,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one profile. + /// The failure mechanism containing . /// The profile residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveDikeProfile(GrassCoverErosionInwardsFailureMechanism failureMechanism, DikeProfile profile) { @@ -532,7 +504,7 @@ foreach (GrassCoverErosionInwardsCalculation calculation in calculationWithRemovedDikeProfile) { calculation.InputParameters.DikeProfile = null; - IEnumerable changedSectionResults = + IEnumerable changedSectionResults = GrassCoverErosionInwardsHelper.Delete(failureMechanism.SectionResults, calculation, calculations); foreach (GrassCoverErosionInwardsFailureMechanismSectionResult result in changedSectionResults) { Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineReplacementHandlerTest.cs =================================================================== diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineReplacementHandlerTest.cs (.../ReferenceLineReplacementHandlerTest.cs) (revision 666de532f451548d6fcf1c61f661a6715852ac5d) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineReplacementHandlerTest.cs (.../ReferenceLineReplacementHandlerTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -86,7 +86,7 @@ Assert.AreEqual(clickOk, result); Assert.AreEqual("Bevestigen", dialogTitle); - Assert.AreEqual("Na het importeren van een aangepaste ligging van de referentielijn zullen alle geimporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + + Assert.AreEqual("Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + Environment.NewLine + "Wilt u doorgaan?", dialogMessage); @@ -99,8 +99,8 @@ TestDelegate call = () => RingtoetsDataSynchronizationService.ClearReferenceLine(null); // Assert - string parmaName = Assert.Throws(call).ParamName; - Assert.AreEqual("assessmentSection", parmaName); + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); } [Test] Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -74,10 +74,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: + // the return result, no ToArray() should be called before these assertions: CollectionAssert.IsEmpty(assessmentSection.GetFailureMechanisms() - .SelectMany(f => f.Calculations) - .Where(c => c.HasOutput)); + .SelectMany(f => f.Calculations) + .Where(c => c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); } @@ -94,58 +94,90 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_VariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_VariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup var assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); - var expectedAffectedItems = new List(); + var expectedAffectedItems = new List(); expectedAffectedItems.AddRange(assessmentSection.ClosingStructures.Calculations .Cast>() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.ClosingStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionInwards.Calculations .Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionInwards.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations .Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.HeightStructures.Calculations .Cast>() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.HeightStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.PipingFailureMechanism.Calculations .Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.PipingFailureMechanism.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.StabilityPointStructures.Calculations .Cast>() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.StabilityPointStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.StabilityStoneCover.Calculations .Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.StabilityStoneCover.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); expectedAffectedItems.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations .Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput)); + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); // Call IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection); // 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(assessmentSection.ClosingStructures.Calculations.Cast>() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.GrassCoverErosionInwards.Calculations.Cast() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.GrassCoverErosionOutwards.Calculations.Cast() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.HeightStructures.Calculations.Cast>() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.PipingFailureMechanism.Calculations.Cast() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.StabilityPointStructures.Calculations.Cast>() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.StabilityStoneCover.Calculations.Cast() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); Assert.IsTrue(assessmentSection.WaveImpactAsphaltCover.Calculations.Cast() - .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); } @@ -182,7 +214,7 @@ [TestCase(1.0, 3.0)] [TestCase(3.8, double.NaN)] [TestCase(double.NaN, 6.9)] - public void ClearHydraulicBoundaryLocationOutput_LocationWithData_ClearsDataAndReturnsTrue( + public void ClearHydraulicBoundaryLocationOutput_LocationWithData_ClearsDataAndReturnsAffectedHydraulicBoundaryLocations( double waveHeight, double designWaterLevel) { // Setup @@ -203,7 +235,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.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); @@ -216,7 +248,7 @@ } [Test] - public void ClearHydraulicBoundaryLocationOutput_HydraulicBoundaryDatabaseWithoutLocations_ReturnsFalse() + public void ClearHydraulicBoundaryLocationOutput_HydraulicBoundaryDatabaseWithoutLocations_DoNothing() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) @@ -232,7 +264,7 @@ } [Test] - public void ClearHydraulicBoundaryLocationOutput_LocationWithoutWaveHeightAndDesignWaterLevel_ReturnsFalse() + public void ClearHydraulicBoundaryLocationOutput_LocationWithoutWaveHeightAndDesignWaterLevel_DoNothing() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) @@ -252,7 +284,7 @@ [Test] [TestCase(3.5, double.NaN)] [TestCase(double.NaN, 8.3)] - public void ClearHydraulicBoundaryLocationOutput_LocationWithoutDataAndGrassCoverErosionOutwardsLocationWithData_ClearDataAndReturnTrue( + public void ClearHydraulicBoundaryLocationOutput_LocationWithoutDataAndGrassCoverErosionOutwardsLocationWithData_ClearDataAndReturnAffectedHydraulicBoundaryLocations( double designWaterLevel, double waveHeight) { // Setup @@ -282,7 +314,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.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); @@ -295,7 +327,7 @@ } [Test] - public void ClearHydraulicBoundaryLocationOutput_LocationWithoutDataAndGrassCoverErosionOutwardsLocationWithoutData_ReturnFalse() + public void ClearHydraulicBoundaryLocationOutput_LocationWithoutDataAndGrassCoverErosionOutwardsLocationWithoutData_DoNothing() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0, 0); @@ -325,7 +357,7 @@ [Test] [TestCase(3.5, double.NaN)] [TestCase(double.NaN, 8.3)] - public void ClearHydraulicBoundaryLocationOutput_LocationWithDataAndGrassCoverErosionOutwardsLocationWithData_ClearDataAndReturnTrue( + public void ClearHydraulicBoundaryLocationOutput_LocationWithDataAndGrassCoverErosionOutwardsLocationWithData_ClearDataAndReturnAffectedHydraulicBoundaryLocations( double designWaterLevel, double waveHeight) { // Setup @@ -346,7 +378,8 @@ { DesignWaterLevel = (RoundedDouble) designWaterLevel, WaveHeight = (RoundedDouble) waveHeight - };; + }; + ; var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism { @@ -361,14 +394,14 @@ // 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.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); Assert.AreEqual(CalculationConvergence.NotCalculated, hydraulicBoundaryLocation.WaveHeightCalculationConvergence); // 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.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); @@ -388,8 +421,8 @@ TestDelegate call = () => RingtoetsDataSynchronizationService.ClearReferenceLine(null); // Assert - string parmaName = Assert.Throws(call).ParamName; - Assert.AreEqual("assessmentSection", parmaName); + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); } [Test] @@ -403,7 +436,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: PipingFailureMechanism pipingFailureMechanism = assessmentSection.PipingFailureMechanism; CollectionAssert.IsEmpty(pipingFailureMechanism.Sections); CollectionAssert.IsEmpty(pipingFailureMechanism.SectionResults); @@ -556,8 +589,6 @@ CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism.StabilityPointStructures); DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; - CollectionAssert.IsEmpty(duneErosionFailureMechanism.Sections); - CollectionAssert.IsEmpty(duneErosionFailureMechanism.SectionResults); CollectionAssert.Contains(observables, duneErosionFailureMechanism); MacrostabilityInwardsFailureMechanism macrostabilityInwardsFailureMechanism = assessmentSection.MacrostabilityInwards; @@ -587,7 +618,6 @@ TechnicalInnovationFailureMechanism technicalInnovationFailureMechanism = assessmentSection.TechnicalInnovation; CollectionAssert.Contains(observables, technicalInnovationFailureMechanism); - Assert.IsNull(assessmentSection.ReferenceLine); CollectionAssert.Contains(observables, assessmentSection); } @@ -639,7 +669,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (StabilityStoneCoverWaveConditionsCalculation calculation in calculations) { @@ -703,7 +733,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in calculations) { @@ -767,7 +797,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in calculations) { @@ -831,7 +861,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (StructuresCalculation calculation in calculations) { @@ -895,7 +925,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (StructuresCalculation calculation in calculations) { @@ -960,7 +990,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.DoesNotContain(failureMechanism.ForeshoreProfiles, profile); foreach (StructuresCalculation calculation in calculations) { @@ -1029,7 +1059,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.DoesNotContain(failureMechanism.DikeProfiles, profile); foreach (GrassCoverErosionInwardsCalculation calculation in calculations) { Index: Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs =================================================================== diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs (.../ReferenceLineImporterIntegrationTest.cs) (revision 666de532f451548d6fcf1c61f661a6715852ac5d) +++ Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs (.../ReferenceLineImporterIntegrationTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -41,9 +41,9 @@ public class ReferenceLineImporterIntegrationTest : NUnitFormsAssertTest { [Test] - public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToCancel_NoChanges() + public void GivenAssessmentSectionWithReferenceLine_WhenCancellingReferenceLineImport_ThenKeepOriginalReferenceLine() { - // Setup + // Given var originalReferenceLine = new ReferenceLine(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) @@ -66,21 +66,21 @@ messageBoxTester.ClickCancel(); }; - // Call + // When bool importSuccesful = importer.Import(); - // Assert + // Then Assert.IsFalse(importSuccesful); Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine); Assert.AreEqual("Bevestigen", messageBoxTitle); - var expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geimporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + + var expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + Environment.NewLine + "Wilt u doorgaan?"; Assert.AreEqual(expectedText, messageBoxText); } [Test] - public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_ClearDataDependentOnReferenceLine() + public void GivenAssessmentSectionWithReferenceLineAndOtherData_WhenImportingReferenceLine_ThenReferenceLineReplacedAndReferenceLineDependentDataCleared() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -153,43 +153,11 @@ CollectionAssert.IsEmpty(assessmentSection.PipingFailureMechanism.CalculationsGroup.Children); Assert.AreEqual("Bevestigen", messageBoxTitle); - var expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geimporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + + var expectedText = "Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van faalmechanismen worden gewist." + Environment.NewLine + Environment.NewLine + "Wilt u doorgaan?"; Assert.AreEqual(expectedText, messageBoxText); mocks.VerifyAll(); } - - [Test] - public void Import_CancellingImport_ReturnFalseAndNoChanges() - { - // Setup - var originalReferenceLine = new ReferenceLine(); - - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - ReferenceLine = originalReferenceLine - }; - - var handler = new ReferenceLineReplacementHandler(); - var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); - - var importer = new ReferenceLineImporter(assessmentSection, handler, path); - - DialogBoxHandler = (name, wnd) => - { - importer.Cancel(); - - var messageBoxTester = new MessageBoxTester(wnd); - messageBoxTester.ClickOk(); - }; - - // Call - bool importSuccesful = importer.Import(); - - // Assert - Assert.IsFalse(importSuccesful); - Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine); - } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -48,7 +48,7 @@ public static class TestDataGenerator { /// - /// Gets a fully configured assessment section. + /// Gets a fully configured . /// public static AssessmentSection GetFullyConfiguredAssessmentSection() { @@ -75,7 +75,7 @@ } /// - /// Gets a fully configured stability stone cover failure mechanism. + /// Gets a fully configured . /// public static StabilityStoneCoverFailureMechanism GetFullyConfiguredStabilityStoneCoverFailureMechanism() { @@ -87,7 +87,7 @@ } /// - /// Gets a fully configured asphalt cover failure mechanism. + /// Gets a fully configured . /// public static WaveImpactAsphaltCoverFailureMechanism GetFullyConfiguredWaveImpactAsphaltCoverFailureMechanism() { @@ -99,7 +99,7 @@ } /// - /// Gets a fully configured grass cover erosion outwards failure mechanism. + /// Gets a fully configured . /// public static GrassCoverErosionOutwardsFailureMechanism GetFullyConfiguredGrassCoverErosionOutwardsFailureMechanism() { @@ -111,7 +111,7 @@ } /// - /// Gets a fully configured height structures failure mechanism. + /// Gets a fully configured . /// public static HeightStructuresFailureMechanism GetFullyConfiguredHeightStructuresFailureMechanism() { @@ -123,7 +123,7 @@ } /// - /// Gets a fully configured closing structures failure mechanism. + /// Gets a fully configured . /// public static ClosingStructuresFailureMechanism GetFullyConfiguredClosingStructuresFailureMechanism() { @@ -135,7 +135,7 @@ } /// - /// Gets a fully configured stability point structures failure mechanism. + /// Gets a fully configured . /// public static StabilityPointStructuresFailureMechanism GetFullyConfiguredStabilityPointStructuresFailureMechanism() { @@ -147,7 +147,7 @@ } /// - /// Gets a fully configured grass cover erosion inwards failure mechanism. + /// Gets a fully configured . /// public static GrassCoverErosionInwardsFailureMechanism GetFullyConfiguredGrassCoverErosionInwardsFailureMechanism() { Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -82,8 +82,7 @@ /// Clears the and output for all the calculations in the . /// /// The which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when is null. public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(PipingFailureMechanism failureMechanism) { @@ -92,16 +91,11 @@ throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection(); + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast()) { - bool calculationChanged = ClearCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(ClearCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; @@ -142,11 +136,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one surfaceline. + /// The failure mechanism containing . /// The surfaceline residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveSurfaceLine(PipingFailureMechanism failureMechanism, RingtoetsPipingSurfaceLine surfaceLine) { @@ -178,11 +172,11 @@ /// Removes a given from the /// and clears all data that depends on it, either directly or indirectly. /// - /// The failure mechanism containing at least one stochastic soil model. + /// The failure mechanism containing . /// The soil model residing in /// that should be removed. /// All observable objects affected by this method. - /// Thrown when + /// Thrown when /// or is null. public static IEnumerable RemoveStochasticSoilModel(PipingFailureMechanism failureMechanism, StochasticSoilModel soilModel) { Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.TestUtils/PipingTestDataGenerator.cs =================================================================== diff -u -r52cdf6d3134a95bad594aa61c9ef062a97b1a2ab -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.TestUtils/PipingTestDataGenerator.cs (.../PipingTestDataGenerator.cs) (revision 52cdf6d3134a95bad594aa61c9ef062a97b1a2ab) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.TestUtils/PipingTestDataGenerator.cs (.../PipingTestDataGenerator.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -30,12 +30,12 @@ namespace Ringtoets.Piping.Integration.TestUtils { /// - /// class responsible for generating test data configurations. + /// Class responsible for generating test data configurations. /// public static class PipingTestDataGenerator { /// - /// Gets a fully configured piping failure mechanism. + /// Gets a fully configured . /// public static PipingFailureMechanism GetFullyConfiguredPipingFailureMechanism() { Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -48,7 +48,7 @@ } [Test] - public void ClearCalculationOutput_WithCalculation_ClearsOutput() + public void ClearCalculationOutput_WithCalculation_ClearsOutputAndReturnAffectedCaculations() { // Setup var calculation = new PipingCalculation(new GeneralPipingInput()) @@ -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.IsNull(calculation.Output); Assert.IsNull(calculation.SemiProbabilisticOutput); @@ -114,7 +114,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); @@ -132,26 +132,34 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetFullyConfiguredPipingFailureMechanism(); - PipingCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + PipingCalculation[] 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 = PipingDataSynchronizationService.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] @@ -166,7 +174,7 @@ } [Test] - public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentData() + public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveReferenceLineDependentDataAndReturnAffectedObjects() { // Setup PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetFullyConfiguredPipingFailureMechanism(); @@ -176,7 +184,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); @@ -207,7 +215,7 @@ } [Test] - public void RemoveSurfaceLine_PipingFailureMechanismProfileNull_ThrowsArgumentNullException() + public void RemoveSurfaceLine_SurfaceLineNull_ThrowsArgumentNullException() { // Setup PipingFailureMechanism failureMechanism = new PipingFailureMechanism(); @@ -239,7 +247,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.DoesNotContain(failureMechanism.SurfaceLines, surfaceLine); foreach (PipingCalculation calculation in calculations) { @@ -271,7 +279,7 @@ } [Test] - public void RemoveStochasticSoilModel_PipingFailureMechanismProfileNull_ThrowsArgumentNullException() + public void RemoveStochasticSoilModel_StochasticSoilModelNull_ThrowsArgumentNullException() { // Setup PipingFailureMechanism failureMechanism = new PipingFailureMechanism(); @@ -303,7 +311,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.DoesNotContain(failureMechanism.StochasticSoilModels, soilModel); foreach (PipingCalculation calculation in calculations) { Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs =================================================================== diff -u -r6f46ce9a263e50bca4ff0cb32973f330defd6f3b -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs (.../StabilityPointStructuresDataSynchronizationService.cs) (revision 6f46ce9a263e50bca4ff0cb32973f330defd6f3b) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresDataSynchronizationService.cs (.../StabilityPointStructuresDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.Common.Data.Structures; @@ -66,29 +65,22 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when /// is null. - public static IEnumerable> ClearAllCalculationOutputAndHydraulicBoundaryLocations( + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations( StabilityPointStructuresFailureMechanism failureMechanism) { if (failureMechanism == null) { throw new ArgumentNullException("failureMechanism"); } - var affectedItems = new Collection>(); - + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast>()) { - var calculationChanged = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; @@ -127,25 +119,25 @@ /// Removes the given stability point structure and all dependent data, either /// directly or indirectly, from the failure mechanism. /// - /// The failure mechanism with at least 1 structure. + /// The failure mechanism containing . /// The structure to be removed. /// All objects affected by the removal. public static IEnumerable RemoveStructure(StabilityPointStructuresFailureMechanism failureMechanism, StabilityPointStructure structure) { var changedObservables = new HashSet(); - StructuresCalculation[] heightStructureCalculations = failureMechanism.Calculations - .Cast>() - .ToArray(); - StructuresCalculation[] calculationWithRemovedStabilityPointStructure = heightStructureCalculations + StructuresCalculation[] stabilityPointStructureCalculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedStabilityPointStructure = stabilityPointStructureCalculations .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); foreach (StructuresCalculation calculation in calculationWithRemovedStabilityPointStructure) { calculation.InputParameters.Structure = null; IEnumerable> affectedSectionResults = - StructuresHelper.Delete(failureMechanism.SectionResults, calculation, heightStructureCalculations); + StructuresHelper.Delete(failureMechanism.SectionResults, calculation, stabilityPointStructureCalculations); foreach (StructuresFailureMechanismSectionResult result in affectedSectionResults) { changedObservables.Add(result); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PresentationObjects/StabilityPointStructuresContextTest.cs =================================================================== diff -u -rbc9af05d3eb0d40e5620b96f537ed92f3ae52e94 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PresentationObjects/StabilityPointStructuresContextTest.cs (.../StabilityPointStructuresContextTest.cs) (revision bc9af05d3eb0d40e5620b96f537ed92f3ae52e94) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PresentationObjects/StabilityPointStructuresContextTest.cs (.../StabilityPointStructuresContextTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -68,8 +68,8 @@ TestDelegate call = () => new StabilityPointStructuresContext(structures, null, assessmentSection); // Assert - string parmaName = Assert.Throws(call).ParamName; - Assert.AreEqual("failureMechanism", parmaName); + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); mocks.VerifyAll(); } 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() Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Service/StabilityStoneCoverDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Service/StabilityStoneCoverDataSynchronizationService.cs (.../StabilityStoneCoverDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Service/StabilityStoneCoverDataSynchronizationService.cs (.../StabilityStoneCoverDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.HydraRing.Data; @@ -67,8 +66,7 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when /// is null. public static IEnumerable ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations( @@ -79,17 +77,11 @@ throw new ArgumentNullException("failureMechanism"); } - Collection affectedItems = new Collection(); - + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast()) { - bool calculationChanged = ClearWaveConditionsCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(ClearWaveConditionsCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Service.Test/StabilityStoneCoverDataSynchronizationServiceTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Service.Test/StabilityStoneCoverDataSynchronizationServiceTest.cs (.../StabilityStoneCoverDataSynchronizationServiceTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Service.Test/StabilityStoneCoverDataSynchronizationServiceTest.cs (.../StabilityStoneCoverDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -46,7 +46,7 @@ } [Test] - public void ClearWaveConditionsCalculationOutput_WithCalculation_OutputNull() + public void ClearWaveConditionsCalculationOutput_WithCalculation_OutputNullAndReturnAffectedCalculations() { // Setup var calculation = new StabilityStoneCoverWaveConditionsCalculation @@ -68,7 +68,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.IsNull(calculation.Output); CollectionAssert.AreEqual(new[] @@ -105,25 +105,31 @@ } [Test] - public void ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsAndReturnsAffectedCalculations() + public void ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsAndReturnsAffectedObjects() { // Setup StabilityStoneCoverFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - StabilityStoneCoverWaveConditionsCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + StabilityStoneCoverWaveConditionsCalculation[] 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 = StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(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] @@ -152,7 +158,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); @@ -185,7 +191,7 @@ } [Test] - public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentData() + public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentDataAndReturnAffectedObjects() { // Setup StabilityStoneCoverFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); @@ -195,7 +201,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.WaveConditionsCalculationGroup.Children); Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Service/WaveImpactAsphaltCoverDataSynchronizationService.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Service/WaveImpactAsphaltCoverDataSynchronizationService.cs (.../WaveImpactAsphaltCoverDataSynchronizationService.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Service/WaveImpactAsphaltCoverDataSynchronizationService.cs (.../WaveImpactAsphaltCoverDataSynchronizationService.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base; using Ringtoets.HydraRing.Data; @@ -67,8 +66,7 @@ /// /// The /// which contains the calculations. - /// An of calculations which are affected by - /// removing data. + /// An of objects which are affected by removing data. /// Thrown when /// is null. public static IEnumerable ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations( @@ -79,17 +77,11 @@ throw new ArgumentNullException("failureMechanism"); } - Collection affectedItems = new Collection(); - + var affectedItems = new List(); foreach (var calculation in failureMechanism.Calculations.Cast()) { - var calculationChanged = ClearWaveConditionsCalculationOutput(calculation) - .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)) - .Any(); - if (calculationChanged) - { - affectedItems.Add(calculation); - } + affectedItems.AddRange(ClearWaveConditionsCalculationOutput(calculation) + .Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters))); } return affectedItems; Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverDataSynchronizationServiceTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -rdee01f6d6c15af0cc124816bfe99c7658af8995d --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverDataSynchronizationServiceTest.cs (.../WaveImpactAsphaltCoverDataSynchronizationServiceTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverDataSynchronizationServiceTest.cs (.../WaveImpactAsphaltCoverDataSynchronizationServiceTest.cs) (revision dee01f6d6c15af0cc124816bfe99c7658af8995d) @@ -46,7 +46,7 @@ } [Test] - public void ClearWaveConditionsCalculation_WithCalculation_OutputNull() + public void ClearWaveConditionsCalculation_WithCalculation_OutputNullAndReturnAffectedCalculations() { // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation @@ -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.IsNull(calculation.Output); CollectionAssert.AreEqual(new[] @@ -100,26 +100,33 @@ } [Test] - public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsOutputAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsOutputAndReturnsAffectedObjects() { // Setup WaveImpactAsphaltCoverFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); - WaveImpactAsphaltCoverWaveConditionsCalculation[] expectedAffectedCalculations = failureMechanism.Calculations.Cast() - .Where(c => c.InputParameters.HydraulicBoundaryLocation != null || c.HasOutput) - .ToArray(); + WaveImpactAsphaltCoverWaveConditionsCalculation[] 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 = WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(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.AreEqual(expectedAffectedCalculations, affectedItems); + CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs), + affectedItems); } [Test] @@ -147,7 +154,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); @@ -175,7 +182,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.WaveConditionsCalculationGroup.Children);