Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -r92ce91281efab19772bd3e2d7ecea2c0a6c8ea97 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 92ce91281efab19772bd3e2d7ecea2c0a6c8ea97) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -178,7 +178,6 @@ - MainWindow.xaml Fisheye: Tag f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Gui/Forms/IPropertyGrid.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Gui/Forms/MainWindow/IMainWindow.cs =================================================================== diff -u -r223b2a4edc4ac816051c7eeecb735c34a6246574 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Core/Common/src/Core.Common.Gui/Forms/MainWindow/IMainWindow.cs (.../IMainWindow.cs) (revision 223b2a4edc4ac816051c7eeecb735c34a6246574) +++ Core/Common/src/Core.Common.Gui/Forms/MainWindow/IMainWindow.cs (.../IMainWindow.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -20,6 +20,7 @@ // All rights reserved. using System.Windows.Forms; +using Core.Common.Controls.Views; using Core.Common.Gui.Forms.MessageWindow; using Core.Common.Gui.Forms.ViewHost; @@ -38,7 +39,7 @@ /// /// Gets the property grid tool window. /// - IPropertyGrid PropertyGrid { get; } + IView PropertyGrid { get; } /// /// Gets the log messages tool window. Index: Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c) +++ Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -30,6 +30,7 @@ using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media.Imaging; +using Core.Common.Controls.Views; using Core.Common.Gui.Commands; using Core.Common.Gui.Forms.MessageWindow; using Core.Common.Gui.Forms.ViewHost; @@ -163,7 +164,7 @@ } } - public IPropertyGrid PropertyGrid + public IView PropertyGrid { get { @@ -285,7 +286,7 @@ } propertyGrid.Text = Properties.Resources.Properties_Title; - propertyGrid.Data = propertyGrid.GetObjectProperties(applicationSelection.Selection); + propertyGrid.Data = applicationSelection.Selection; viewController.ViewHost.AddToolView(propertyGrid, ToolViewLocation.Right); viewController.ViewHost.SetImage(propertyGrid, Properties.Resources.PropertiesHS); Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs =================================================================== diff -u -r2144738ceac62325ae78fbbdfcf953c6cf7d7949 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision 2144738ceac62325ae78fbbdfcf953c6cf7d7949) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -26,6 +26,7 @@ using System.Security.Permissions; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Controls.Views; using Core.Common.Gui.Properties; using Core.Common.Gui.PropertyBag; using Core.Common.Gui.Selection; @@ -35,7 +36,7 @@ /// /// View for displaying the properties of an data object. /// - public class PropertyGridView : PropertyGrid, IPropertyGrid, IObserver + public class PropertyGridView : PropertyGrid, IView, IObserver { /// /// This delegate enabled asynchronous calls to methods without arguments. @@ -45,6 +46,8 @@ private readonly IApplicationSelection applicationSelection; private readonly IPropertyResolver propertyResolver; + private object data; + private IObservable observable; /// @@ -115,16 +118,16 @@ return; } - Data = GetObjectProperties(selection); + Data = selection; //GetObjectProperties(selection); } - #region IPropertyGrid Members + #region IView Members public object Data { get { - return SelectedObject; + return data; } set { @@ -134,7 +137,8 @@ observable = null; } - SelectedObject = value; + data = value; + SelectedObject = GetObjectProperties(value); var dynamicPropertyBag = SelectedObject as DynamicPropertyBag; if (dynamicPropertyBag != null) @@ -149,11 +153,12 @@ observable.Attach(this); } } + ; } } } - public object GetObjectProperties(object sourceData) + private object GetObjectProperties(object sourceData) { return propertyResolver.GetObjectProperties(sourceData); } Index: Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs =================================================================== diff -u -r0a30c1488bb2d215a84c02566382244fa2dcfd52 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 0a30c1488bb2d215a84c02566382244fa2dcfd52) +++ Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -332,7 +332,7 @@ Assert.IsNull(viewHost.ActiveDocumentView); Assert.AreSame(viewHost.ToolViews.ElementAt(0), mainWindow.PropertyGrid, "PropertyGrid instance should remain the same."); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); - Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); + Assert.AreEqual(selectedObject, mainWindow.PropertyGrid.Data); } mocks.VerifyAll(); } @@ -374,7 +374,7 @@ Assert.IsNull(viewHost.ActiveDocumentView); Assert.AreSame(originalPropertyGrid, mainWindow.PropertyGrid, "PropertyGrid instance should remain the same."); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); - Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); + Assert.AreEqual(selectedObject, mainWindow.PropertyGrid.Data); } mocks.VerifyAll(); @@ -427,7 +427,7 @@ // Assert Assert.IsInstanceOf(mainWindow.PropertyGrid); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); - Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); + Assert.AreEqual(selectedObject, mainWindow.PropertyGrid.Data); Assert.IsInstanceOf(mainWindow.MessageWindow); Assert.AreEqual("Berichten", mainWindow.MessageWindow.Text); Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Core.Common.Utils.Extensions; using Ringtoets.GrassCoverErosionInwards.Data; @@ -38,8 +39,14 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearAllCalculationOutput(GrassCoverErosionInwardsFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.HasOutput) @@ -70,8 +77,14 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearHydraulicBoundaryLocations(GrassCoverErosionInwardsFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.InputParameters.HydraulicBoundaryLocation != null) @@ -82,6 +95,46 @@ return affectedItems; } + /// + /// Clears the and output for all the calculations in the . + /// + /// The which contains the calculations. + /// An of calculations which are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(GrassCoverErosionInwardsFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + + Collection affectedItems = new Collection(); + + foreach (var calculation in failureMechanism.Calculations.Cast()) + { + var calculationChanged = false; + + if (calculation.HasOutput) + { + ClearCalculationOutput(calculation); + calculationChanged = true; + } + + if (calculation.InputParameters.HydraulicBoundaryLocation != null) + { + ClearHydraulicBoundaryLocation(calculation); + calculationChanged = true; + } + + if (calculationChanged) + { + affectedItems.Add(calculation); + } + } + + return affectedItems; + } + private static void ClearHydraulicBoundaryLocation(GrassCoverErosionInwardsCalculation calculation) { calculation.InputParameters.HydraulicBoundaryLocation = null; Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -34,6 +34,17 @@ public class GrassCoverErosionInwardsDataSynchronizationServiceTest { [Test] + public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearAllCalculationOutput_WithOutput_ClearsCalculationsOutputAndReturnsAffectedCalculations() { // Setup @@ -93,6 +104,17 @@ } [Test] + public void ClearHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionInwardsDataSynchronizationService.ClearHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearHydraulicBoundaryLocations_WithHydraulicBoundaryLocation_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() { // Setup @@ -135,5 +157,144 @@ calculation2 }, affectedItems); } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + GrassCoverErosionInwardsCalculation calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) + }; + + GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) + }; + + GrassCoverErosionInwardsCalculation calculation3 = new GrassCoverErosionInwardsCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + GrassCoverErosionInwardsCalculation calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + GrassCoverErosionInwardsCalculation calculation3 = new GrassCoverErosionInwardsCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOuputAndReturnsAffectedCalculations() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + GrassCoverErosionInwardsCalculation calculation1 = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) + }; + + GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) + }; + + GrassCoverErosionInwardsCalculation calculation3 = new GrassCoverErosionInwardsCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Core.Common.Utils.Extensions; using Ringtoets.HeightStructures.Data; @@ -38,8 +39,14 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearAllCalculationOutput(HeightStructuresFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.HasOutput) @@ -70,8 +77,14 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearHydraulicBoundaryLocations(HeightStructuresFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.InputParameters.HydraulicBoundaryLocation != null) @@ -82,6 +95,46 @@ return affectedItems; } + /// + /// Clears the and output for all the calculations in the . + /// + /// The which contains the calculations. + /// An of calculations which are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(HeightStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + + Collection affectedItems = new Collection(); + + foreach (var calculation in failureMechanism.Calculations.Cast()) + { + var calculationChanged = false; + + if (calculation.HasOutput) + { + ClearCalculationOutput(calculation); + calculationChanged = true; + } + + if (calculation.InputParameters.HydraulicBoundaryLocation != null) + { + ClearHydraulicBoundaryLocation(calculation); + calculationChanged = true; + } + + if (calculationChanged) + { + affectedItems.Add(calculation); + } + } + + return affectedItems; + } + private static void ClearHydraulicBoundaryLocation(HeightStructuresCalculation calculation) { calculation.InputParameters.HydraulicBoundaryLocation = null; Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -33,6 +33,17 @@ public class HeightStructuresDataSynchronizationServiceTest { [Test] + public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearAllCalculationOutput_WithOutput_ClearsCalculationsOutput() { // Setup @@ -92,6 +103,17 @@ } [Test] + public void ClearHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearHydraulicBoundaryLocations_WithHydraulicBoundaryLocation_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() { // Setup @@ -134,5 +156,144 @@ calculation2 }, affectedItems); } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOuputAndReturnsAffectedCalculations() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = new HeightStructuresFailureMechanism(); + + HeightStructuresCalculation calculation1 = new HeightStructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation2 = new HeightStructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; + + HeightStructuresCalculation calculation3 = new HeightStructuresCalculation(); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (HeightStructuresCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r89f4fbf4c0868773f7a011605df141f042b0ad9c -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 89f4fbf4c0868773f7a011605df141f042b0ad9c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -349,15 +349,15 @@ /// /// Looks up a localized string similar to De uitvoer van {0} berekeningen is verwijderd.. /// - public static string FailureMechanismContributionView_NormValueChanged_Results_of_0_calculations_cleared { + public static string FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared { get { - return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Results_of_0_calculations_clear" + - "ed", resourceCulture); + return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations" + + "_0_calculations_cleared", resourceCulture); } } /// - /// Looks up a localized string similar to De berekende toetspeilen en golfhoogte van alle hydraulische randvoorwaarden locaties zijn verwijderd.. + /// Looks up a localized string similar to De berekende toetspeilen en golfhoogtes van alle hydraulische randvoorwaarden locaties zijn verwijderd.. /// public static string FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared { get { Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx =================================================================== diff -u -r89f4fbf4c0868773f7a011605df141f042b0ad9c -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 89f4fbf4c0868773f7a011605df141f042b0ad9c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -323,10 +323,10 @@ Hs [m] - + De uitvoer van {0} berekeningen is verwijderd. - De berekende toetspeilen en golfhoogte van alle hydraulische randvoorwaarden locaties zijn verwijderd. + De berekende toetspeilen en golfhoogtes van alle hydraulische randvoorwaarden locaties zijn verwijderd. \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/DesignWaterLevelContextProperties.cs =================================================================== diff -u -r2144738ceac62325ae78fbbdfcf953c6cf7d7949 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/DesignWaterLevelContextProperties.cs (.../DesignWaterLevelContextProperties.cs) (revision 2144738ceac62325ae78fbbdfcf953c6cf7d7949) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/DesignWaterLevelContextProperties.cs (.../DesignWaterLevelContextProperties.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -26,17 +26,16 @@ using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.Properties; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.PresentationObjects; namespace Ringtoets.Integration.Forms.PropertyClasses { /// - /// ViewModel of for properties panel. + /// ViewModel of for properties panel. /// public class DesignWaterLevelContextProperties : ObjectProperties { /// - /// Gets the from the . + /// Gets the from the . /// [TypeConverter(typeof(ExpandableArrayConverter))] [ResourcesCategory(typeof(Resources), "Categories_General")] Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/WaveHeightContextProperties.cs =================================================================== diff -u -r2144738ceac62325ae78fbbdfcf953c6cf7d7949 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/WaveHeightContextProperties.cs (.../WaveHeightContextProperties.cs) (revision 2144738ceac62325ae78fbbdfcf953c6cf7d7949) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/WaveHeightContextProperties.cs (.../WaveHeightContextProperties.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -26,17 +26,16 @@ using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.Properties; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.PresentationObjects; namespace Ringtoets.Integration.Forms.PropertyClasses { /// - /// ViewModel of for properties panel. + /// ViewModel of for properties panel. /// public class WaveHeightContextProperties : ObjectProperties { /// - /// Gets the from the . + /// Gets the from the . /// [TypeConverter(typeof(ExpandableArrayConverter))] [ResourcesCategory(typeof(Resources), "Categories_General")] Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs =================================================================== diff -u -re698c3556018a5be473e4773177c79b7c723da86 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision e698c3556018a5be473e4773177c79b7c723da86) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -26,6 +26,7 @@ using Core.Common.Base; using Core.Common.Controls.Views; using Core.Common.Gui.Commands; +using Core.Common.Utils.Extensions; using Core.Common.Utils.Reflection; using log4net; using Ringtoets.Common.Data.AssessmentSection; @@ -273,11 +274,11 @@ { data.Norm = Convert.ToInt32(normInput.Value); var affectedCalculations = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection).ToArray(); - RingtoetsDataSynchronizationService.NotifyCalculationObservers(affectedCalculations); if (affectedCalculations.Length > 0) { - log.InfoFormat(RingtoetsIntegrationFormsResources.FailureMechanismContributionView_NormValueChanged_Results_of_0_calculations_cleared, affectedCalculations.Length); + affectedCalculations.ForEachElementDo(ac => ac.NotifyObservers()); + log.InfoFormat(RingtoetsIntegrationFormsResources.FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared, affectedCalculations.Length); } if (assessmentSection.HydraulicBoundaryDatabase != null) @@ -408,23 +409,6 @@ assessmentSection.NotifyObservers(); } -// -// private void ClearCalculationOutputForChangedContributions(double[] originalFailureMechanismContributions) -// { -// var allFailureMechanisms = assessmentSection.GetFailureMechanisms().ToArray(); -// for (int i = 0; i < allFailureMechanisms.Length; i++) -// { -// IFailureMechanism failureMechanism = allFailureMechanisms[i]; -// if (originalFailureMechanismContributions[i] != failureMechanism.Contribution) -// { -// foreach (ICalculation calculation in failureMechanism.Calculations) -// { -// calculation.ClearOutput(); -// calculation.NotifyObservers(); -// } -// } -// } -// } #endregion } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r4851d9c2b000de0707f6cce0872979ecc1e3dead -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 4851d9c2b000de0707f6cce0872979ecc1e3dead) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -25,6 +25,7 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.IO; using Core.Common.Controls.TreeView; @@ -35,6 +36,7 @@ using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Plugin; using Core.Common.IO.Exceptions; +using Core.Common.Utils.Extensions; using log4net; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; @@ -1167,9 +1169,8 @@ private static void ClearCalculations(IAssessmentSection nodeData) { var affectedCalculations = new List(); - affectedCalculations.AddRange(RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(nodeData)); - affectedCalculations.AddRange(RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationFromCalculations(nodeData)); - RingtoetsDataSynchronizationService.NotifyCalculationObservers(affectedCalculations.Distinct()); + affectedCalculations.AddRange(RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(nodeData)); + affectedCalculations.ForEachElementDo(ac => ac.NotifyObservers()); log.Info(RingtoetsFormsResources.Calculations_Cleared); } Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -20,10 +20,7 @@ // All rights reserved. using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; -using Core.Common.Utils.Extensions; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.GrassCoverErosionInwards.Data; @@ -45,8 +42,8 @@ /// Clears all the output data within the . /// /// The to clear the data for. - /// Thrown when is null. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearAssessmentSectionData(IAssessmentSection assessmentSection) { if (assessmentSection == null) @@ -59,60 +56,79 @@ } /// - /// Clears the output of all calculations in the . + /// Clears all the output data and hydraulic boundary locations within the . /// - /// The which contains the calculations. + /// The to clear the data for. /// An of calculations which are affected by clearing the output. - public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection) + /// /// Thrown when is null. + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(IAssessmentSection assessmentSection) { + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + List affectedItems = new List(); - var failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray(); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(fm))); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(fm))); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(fm))); + foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) + { + var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; + var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + if (pipingFailureMechanism != null) + { + affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism)); + } + if (grassCoverErosionInwardsFailureMechanism != null) + { + affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism)); + } + if (heightStructuresFailureMechanism != null) + { + affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism)); + } + } + return affectedItems; } /// - /// Clears the for all calculations in the . + /// Clears the output of all calculations in the . /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. - public static IEnumerable ClearHydraulicBoundaryLocationFromCalculations(IAssessmentSection assessmentSection) + /// Thrown when is null. + public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection) { + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + List affectedItems = new List(); - var failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray(); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(PipingDataSynchronizationService.ClearHydraulicBoundaryLocations(fm))); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearHydraulicBoundaryLocations(fm))); - failureMechanisms.OfType().ForEachElementDo(fm => affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearHydraulicBoundaryLocations(fm))); - - return affectedItems; - } - - /// - /// Notifies the observers of the calculation in the . - /// - /// The which contains the calculations. - public static void NotifyCalculationObservers(IAssessmentSection assessmentSection) - { - var failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray(); - - foreach (ICalculation calc in failureMechanisms.SelectMany(fm => fm.Calculations)) + foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) { - calc.NotifyObservers(); + var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; + var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + + if (pipingFailureMechanism != null) + { + affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism)); + } + if (grassCoverErosionInwardsFailureMechanism != null) + { + affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism)); + } + if (heightStructuresFailureMechanism != null) + { + affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism)); + } } - } - /// - /// Notifies the observers of the . - /// - /// An containing the calculations to notify. - public static void NotifyCalculationObservers(IEnumerable affectedCalculations) - { - affectedCalculations.ForEachElementDo(c => c.NotifyObservers()); + return affectedItems; } private static void ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs =================================================================== diff -u -r89f4fbf4c0868773f7a011605df141f042b0ad9c -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 89f4fbf4c0868773f7a011605df141f042b0ad9c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -49,6 +49,7 @@ { // Setup const int normValue = 200; + const int numberOfCalculations = 3; HydraulicBoundaryDatabase hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 0.0, 0.0) @@ -91,7 +92,7 @@ IObserver observerMock = mockRepository.StrictMock(); observerMock.Expect(o => o.UpdateObserver()); IObserver calculationObserver = mockRepository.StrictMock(); - calculationObserver.Expect(co => co.UpdateObserver()).Repeat.Times(3); + calculationObserver.Expect(co => co.UpdateObserver()).Repeat.Times(numberOfCalculations); IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver()); mockRepository.ReplayAll(); @@ -136,7 +137,7 @@ TestHelper.AssertLogMessages(call, msgs => { string[] messages = msgs.ToArray(); - Assert.AreEqual(string.Format(Resources.FailureMechanismContributionView_NormValueChanged_Results_of_0_calculations_cleared, 3), messages[0]); + Assert.AreEqual(string.Format(Resources.FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared, numberOfCalculations), messages[0]); Assert.AreEqual(Resources.FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared, messages[1]); }); Assert.AreEqual(normValue, failureMechanismContribution.Norm); Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using Core.Common.Base; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; @@ -119,7 +118,7 @@ assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); // Call - var affectedItems = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection); + IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection); // Assert Assert.IsNull(pipingCalculation.Output); @@ -162,8 +161,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection); // Assert - PipingCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as PipingCalculation; - PipingCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as PipingCalculation; + PipingCalculation calculation1 = (PipingCalculation) failureMechanism1.CalculationsGroup.Children[0]; + PipingCalculation calculation2 = (PipingCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -203,8 +202,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection); // Assert - GrassCoverErosionInwardsCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; - GrassCoverErosionInwardsCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; + GrassCoverErosionInwardsCalculation calculation1 = (GrassCoverErosionInwardsCalculation) failureMechanism1.CalculationsGroup.Children[0]; + GrassCoverErosionInwardsCalculation calculation2 = (GrassCoverErosionInwardsCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -244,8 +243,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAssessmentSectionData(assessmentSection); // Assert - HeightStructuresCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as HeightStructuresCalculation; - HeightStructuresCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as HeightStructuresCalculation; + HeightStructuresCalculation calculation1 = (HeightStructuresCalculation) failureMechanism1.CalculationsGroup.Children[0]; + HeightStructuresCalculation calculation2 = (HeightStructuresCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -257,6 +256,17 @@ } [Test] + public void ClearFailureMechanismCalculationOutputs_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void ClearFailureMechanismCalculationOutputs_WithAssessmentSection_ClearsFailureMechanismCalculationsOutputAndReturnsAffectedCalculations() { // Setup @@ -330,8 +340,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); // Assert - PipingCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as PipingCalculation; - PipingCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as PipingCalculation; + PipingCalculation calculation1 = (PipingCalculation) failureMechanism1.CalculationsGroup.Children[0]; + PipingCalculation calculation2 = (PipingCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -370,8 +380,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); // Assert - GrassCoverErosionInwardsCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; - GrassCoverErosionInwardsCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; + GrassCoverErosionInwardsCalculation calculation1 = (GrassCoverErosionInwardsCalculation) failureMechanism1.CalculationsGroup.Children[0]; + GrassCoverErosionInwardsCalculation calculation2 = (GrassCoverErosionInwardsCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -410,8 +420,8 @@ IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); // Assert - HeightStructuresCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as HeightStructuresCalculation; - HeightStructuresCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as HeightStructuresCalculation; + HeightStructuresCalculation calculation1 = (HeightStructuresCalculation) failureMechanism1.CalculationsGroup.Children[0]; + HeightStructuresCalculation calculation2 = (HeightStructuresCalculation) failureMechanism2.CalculationsGroup.Children[0]; Assert.IsNull(calculation1.Output); Assert.IsNull(calculation2.Output); CollectionAssert.AreEqual(new[] @@ -423,8 +433,19 @@ } [Test] - public void ClearHydraulicBoundaryLocationFromCalculations_WithAssessmentSection_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutAssessmentSection_ThrowsArgumentNullException() { + // Call + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + { // Setup AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -435,7 +456,8 @@ InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation - } + }, + Output = new TestPipingOutput() }; GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); @@ -444,7 +466,8 @@ InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation - } + }, + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) }; HeightStructuresCalculation emptyHeightStructuresCalculation = new HeightStructuresCalculation(); @@ -453,7 +476,8 @@ InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation - } + }, + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) }; assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); @@ -464,12 +488,15 @@ assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); // Call - IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationFromCalculations(assessmentSection); + IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection); // Assert Assert.IsNull(pipingCalculation.InputParameters.HydraulicBoundaryLocation); Assert.IsNull(grassCoverErosionInwardsCalculation.InputParameters.HydraulicBoundaryLocation); Assert.IsNull(heightStructuresCalculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(pipingCalculation.Output); + Assert.IsNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNull(heightStructuresCalculation.Output); CollectionAssert.AreEqual(new ICalculation[] { pipingCalculation, @@ -479,203 +506,105 @@ } [Test] - public void ClearHydraulicBoundaryLocationFromCalculations_WithMultiplePipingFailureMechanisms_ClearsHydraulicBoundaryLocationsAndReturnsAffectedItems() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() { // Setup - HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0); + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - PipingFailureMechanism failureMechanism1 = new PipingFailureMechanism(); - failureMechanism1.CalculationsGroup.Children.Add(new PipingCalculation(new GeneralPipingInput()) + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0); + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()) { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } - }); - PipingFailureMechanism failureMechanism2 = new PipingFailureMechanism(); - failureMechanism2.CalculationsGroup.Children.Add(new PipingCalculation(new GeneralPipingInput()) + }; + + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } - }); + }; - MockRepository mocks = new MockRepository(); - IAssessmentSection assessmentSection = mocks.StrictMock(); - assessmentSection.Expect(a => a.GetFailureMechanisms()).Return(new[] + HeightStructuresCalculation emptyHeightStructuresCalculation = new HeightStructuresCalculation(); + HeightStructuresCalculation heightStructuresCalculation = new HeightStructuresCalculation { - failureMechanism1, - failureMechanism2 - }); - mocks.ReplayAll(); - - // Call - IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationFromCalculations(assessmentSection); - - // Assert - PipingCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as PipingCalculation; - PipingCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as PipingCalculation; - Assert.IsNull(calculation1.InputParameters.HydraulicBoundaryLocation); - Assert.IsNull(calculation2.InputParameters.HydraulicBoundaryLocation); - CollectionAssert.AreEqual(new[] - { - calculation1, - calculation2 - }, affectedItems); - mocks.VerifyAll(); - } - - [Test] - public void ClearHydraulicBoundaryLocationFromCalculations_WithMultipleGrassCoverErosionInwardsFailureMechanisms_ClearsHydraulicBoundaryLocationsAndReturnsAffectedItems() - { - // Setup - HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0); - - GrassCoverErosionInwardsFailureMechanism failureMechanism1 = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism1.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation - { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } - }); - GrassCoverErosionInwardsFailureMechanism failureMechanism2 = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism2.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - } - }); + }; - MockRepository mocks = new MockRepository(); - IAssessmentSection assessmentSection = mocks.StrictMock(); - assessmentSection.Expect(a => a.GetFailureMechanisms()).Return(new[] - { - failureMechanism1, - failureMechanism2 - }); - mocks.ReplayAll(); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(pipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(grassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); // Call - IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationFromCalculations(assessmentSection); + IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection); // Assert - GrassCoverErosionInwardsCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; - GrassCoverErosionInwardsCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as GrassCoverErosionInwardsCalculation; - Assert.IsNull(calculation1.InputParameters.HydraulicBoundaryLocation); - Assert.IsNull(calculation2.InputParameters.HydraulicBoundaryLocation); - CollectionAssert.AreEqual(new[] + Assert.IsNull(pipingCalculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(grassCoverErosionInwardsCalculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(heightStructuresCalculation.InputParameters.HydraulicBoundaryLocation); + CollectionAssert.AreEqual(new ICalculation[] { - calculation1, - calculation2 + pipingCalculation, + grassCoverErosionInwardsCalculation, + heightStructuresCalculation }, affectedItems); - mocks.VerifyAll(); } [Test] - public void ClearHydraulicBoundaryLocationFromCalculations_WithMultipleHeightStructuresFailureMechanisms_ClearsHydraulicBoundaryLocationsAndReturnsAffectedItems() + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOuputAndReturnsAffectedCalculations() { // Setup - HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0); + AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - HeightStructuresFailureMechanism failureMechanism1 = new HeightStructuresFailureMechanism(); - failureMechanism1.CalculationsGroup.Children.Add(new HeightStructuresCalculation + PipingCalculation emptyPipingCalculation = new PipingCalculation(new GeneralPipingInput()); + PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()) { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - } - }); - HeightStructuresFailureMechanism failureMechanism2 = new HeightStructuresFailureMechanism(); - failureMechanism2.CalculationsGroup.Children.Add(new HeightStructuresCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - } - }); + Output = new TestPipingOutput() + }; - MockRepository mocks = new MockRepository(); - IAssessmentSection assessmentSection = mocks.StrictMock(); - assessmentSection.Expect(a => a.GetFailureMechanisms()).Return(new[] + GrassCoverErosionInwardsCalculation emptyGrassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); + GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation { - failureMechanism1, - failureMechanism2 - }); - mocks.ReplayAll(); + Output = new GrassCoverErosionInwardsOutput(0, false, new ProbabilityAssessmentOutput(0, 0, 0, 0, 0), 0) + }; - // Call - IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationFromCalculations(assessmentSection); - - // Assert - HeightStructuresCalculation calculation1 = failureMechanism1.CalculationsGroup.Children[0] as HeightStructuresCalculation; - HeightStructuresCalculation calculation2 = failureMechanism2.CalculationsGroup.Children[0] as HeightStructuresCalculation; - Assert.IsNull(calculation1.InputParameters.HydraulicBoundaryLocation); - Assert.IsNull(calculation2.InputParameters.HydraulicBoundaryLocation); - CollectionAssert.AreEqual(new[] + HeightStructuresCalculation emptyHeightStructuresCalculation = new HeightStructuresCalculation(); + HeightStructuresCalculation heightStructuresCalculation = new HeightStructuresCalculation { - calculation1, - calculation2 - }, affectedItems); - mocks.VerifyAll(); - } + Output = new ProbabilityAssessmentOutput(0, 0, 0, 0, 0) + }; - [Test] - public void NotifyCalculationObservers_Always_NotifiesAllCalculationsInAssessmentSection() - { - // Setup - MockRepository mocks = new MockRepository(); - IObserver observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()).Repeat.Times(3); - mocks.ReplayAll(); - - PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()); - pipingCalculation.Attach(observer); - GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); - grassCoverErosionInwardsCalculation.Attach(observer); - HeightStructuresCalculation heightStructuresCalculation = new HeightStructuresCalculation(); - heightStructuresCalculation.Attach(observer); - - AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(emptyPipingCalculation); assessmentSection.PipingFailureMechanism.CalculationsGroup.Children.Add(pipingCalculation); + assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(emptyGrassCoverErosionInwardsCalculation); assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(grassCoverErosionInwardsCalculation); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(emptyHeightStructuresCalculation); assessmentSection.HeightStructures.CalculationsGroup.Children.Add(heightStructuresCalculation); // Call - RingtoetsDataSynchronizationService.NotifyCalculationObservers(assessmentSection); + IEnumerable affectedItems = RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection); // Assert - mocks.VerifyAll(); - } - - [Test] - public void NotifyCalculationObservers_Always_NotifiesGivenCalculations() - { - // Setup - MockRepository mocks = new MockRepository(); - IObserver observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()).Repeat.Times(3); - mocks.ReplayAll(); - - PipingCalculation pipingCalculation = new PipingCalculation(new GeneralPipingInput()); - pipingCalculation.Attach(observer); - GrassCoverErosionInwardsCalculation grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); - grassCoverErosionInwardsCalculation.Attach(observer); - HeightStructuresCalculation heightStructuresCalculation = new HeightStructuresCalculation(); - heightStructuresCalculation.Attach(observer); - - // Call - RingtoetsDataSynchronizationService.NotifyCalculationObservers(new ICalculation[] + Assert.IsNull(pipingCalculation.Output); + Assert.IsNull(grassCoverErosionInwardsCalculation.Output); + Assert.IsNull(heightStructuresCalculation.Output); + CollectionAssert.AreEqual(new ICalculation[] { pipingCalculation, grassCoverErosionInwardsCalculation, heightStructuresCalculation - }); - - // Assert - mocks.VerifyAll(); + }, affectedItems); } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Core.Common.Utils.Extensions; using Ringtoets.HydraRing.Data; @@ -38,8 +39,14 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearAllCalculationOutput(PipingFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.HasOutput) @@ -70,18 +77,64 @@ /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. + /// Thrown when is null. public static IEnumerable ClearHydraulicBoundaryLocations(PipingFailureMechanism failureMechanism) { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + var affectedItems = failureMechanism.Calculations .Cast() .Where(c => c.InputParameters.HydraulicBoundaryLocation != null) .ToArray(); - + affectedItems.ForEachElementDo(ClearHydraulicBoundaryLocation); return affectedItems; } + /// + /// Clears the and output for all the calculations in the . + /// + /// The which contains the calculations. + /// An of calculations which are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(PipingFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException("failureMechanism"); + } + + Collection affectedItems = new Collection(); + + foreach (var calculation in failureMechanism.Calculations.Cast()) + { + var calculationChanged = false; + + if (calculation.HasOutput) + { + ClearCalculationOutput(calculation); + calculationChanged = true; + } + + if (calculation.InputParameters.HydraulicBoundaryLocation != null) + { + ClearHydraulicBoundaryLocation(calculation); + calculationChanged = true; + } + + if (calculationChanged) + { + affectedItems.Add(calculation); + } + } + + return affectedItems; + } + private static void ClearHydraulicBoundaryLocation(PipingCalculation calculation) { calculation.InputParameters.HydraulicBoundaryLocation = null; Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs =================================================================== diff -u -rd9e5e7ea1e028347a738fc8e3d9c158a9b53ce15 -rf7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a --- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision d9e5e7ea1e028347a738fc8e3d9c158a9b53ce15) +++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision f7b5ed585321bbc2249ec9c8ecd8af7f9eb1808a) @@ -33,6 +33,17 @@ public class PipingDataSynchronizationServiceTest { [Test] + public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingDataSynchronizationService.ClearAllCalculationOutput(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearAllCalculationOutput_WithOutput_ClearsCalculationsOutputAndReturnsAffectedCalculations() { // Setup @@ -92,6 +103,17 @@ } [Test] + public void ClearHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingDataSynchronizationService.ClearHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] public void ClearHydraulicBoundaryLocations_WithHydraulicBoundaryLocation_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() { // Setup @@ -134,5 +156,144 @@ calculation2 }, affectedItems); } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedCalculations() + { + // Setup + PipingFailureMechanism failureMechanism = new PipingFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + PipingCalculation calculation1 = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new TestPipingOutput() + }; + + PipingCalculation calculation2 = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + }, + Output = new TestPipingOutput() + }; + + PipingCalculation calculation3 = new PipingCalculation(new GeneralPipingInput()); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (PipingCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationNoOutput_ClearsHydraulicBoundaryLocationAndReturnsAffectedCalculations() + { + // Setup + PipingFailureMechanism failureMechanism = new PipingFailureMechanism(); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); + + PipingCalculation calculation1 = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + PipingCalculation calculation2 = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + PipingCalculation calculation3 = new PipingCalculation(new GeneralPipingInput()); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (PipingCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOuputAndReturnsAffectedCalculations() + { + // Setup + PipingFailureMechanism failureMechanism = new PipingFailureMechanism(); + + PipingCalculation calculation1 = new PipingCalculation(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }; + + PipingCalculation calculation2 = new PipingCalculation(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }; + + PipingCalculation calculation3 = new PipingCalculation(new GeneralPipingInput()); + + failureMechanism.CalculationsGroup.Children.Add(calculation1); + failureMechanism.CalculationsGroup.Children.Add(calculation2); + failureMechanism.CalculationsGroup.Children.Add(calculation3); + + // Call + IEnumerable affectedItems = PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); + + // Assert + foreach (PipingCalculation calculation in failureMechanism.CalculationsGroup.Children.Cast()) + { + Assert.IsNull(calculation.Output); + } + CollectionAssert.AreEqual(new[] + { + calculation1, + calculation2 + }, affectedItems); + } } } \ No newline at end of file