Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs
===================================================================
diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -rc3a67fb890682c3747d265cf082c279801e886af
--- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1)
+++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs (.../GrassCoverErosionInwardsDataSynchronizationService.cs) (revision c3a67fb890682c3747d265cf082c279801e886af)
@@ -61,22 +61,31 @@
///
/// Clears the and output for all the calculations
- /// in the .
+ /// in the that uses an
+ /// from .
///
/// The
/// which contains the calculations.
+ /// The hydraulic boundary locations to clear for.
/// An of objects which are affected by removal of data.
- /// Thrown when
- /// is null.
- public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(GrassCoverErosionInwardsFailureMechanism failureMechanism)
+ /// Thrown when any parameter is null.
+ public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(GrassCoverErosionInwardsFailureMechanism failureMechanism,
+ IEnumerable hydraulicBoundaryLocations)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
+ if (hydraulicBoundaryLocations == null)
+ {
+ throw new ArgumentNullException(nameof(hydraulicBoundaryLocations));
+ }
+
var affectedItems = new List();
- foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.Calculations.Cast())
+ foreach (GrassCoverErosionInwardsCalculation calculation in failureMechanism.Calculations.Cast()
+ .Where(c => hydraulicBoundaryLocations.Contains(
+ c.InputParameters.HydraulicBoundaryLocation)))
{
affectedItems.AddRange(RiskeerCommonDataSynchronizationService.ClearCalculationOutput(calculation)
.Concat(ClearHydraulicBoundaryLocation(calculation.InputParameters)));
Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs
===================================================================
diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -rc3a67fb890682c3747d265cf082c279801e886af
--- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1)
+++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs (.../GrassCoverErosionInwardsDataSynchronizationServiceTest.cs) (revision c3a67fb890682c3747d265cf082c279801e886af)
@@ -75,43 +75,75 @@
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call
- void Call() => GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null);
+ void Call() => GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null, Enumerable.Empty());
// Assert
var exception = Assert.Throws(Call);
Assert.AreEqual("failureMechanism", exception.ParamName);
}
[Test]
+ public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_HydraulicBoundaryLocationsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ void Call() => GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(new GrassCoverErosionInwardsFailureMechanism(), null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("hydraulicBoundaryLocations", exception.ParamName);
+ }
+
+ [Test]
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects()
{
// Setup
- GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism();
- 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();
+ var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation();
+ var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation();
+ GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(hydraulicBoundaryLocation1);
+ failureMechanism.CalculationsGroup.Children.AddRange(new[]
+ {
+ new GrassCoverErosionInwardsCalculationScenario
+ {
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = hydraulicBoundaryLocation2
+ }
+ },
+ new GrassCoverErosionInwardsCalculationScenario
+ {
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = hydraulicBoundaryLocation2
+ },
+ Output = new TestGrassCoverErosionInwardsOutput()
+ }
+ });
+ IEnumerable calculations = failureMechanism.Calculations.Cast()
+ .ToArray();
+
+ IEnumerable expectedAffectedCalculations = calculations.Where(
+ c => c.InputParameters.HydraulicBoundaryLocation == hydraulicBoundaryLocation1
+ && c.HasOutput).ToArray();
+
+ var expectedAffectedItems = new List(expectedAffectedCalculations);
+ expectedAffectedItems.AddRange(calculations.Select(c => c.InputParameters)
+ .Where(i => i.HydraulicBoundaryLocation == hydraulicBoundaryLocation1));
+
// Call
- IEnumerable affectedItems =
- GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism);
+ IEnumerable affectedItems = GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(
+ failureMechanism, new[]
+ {
+ hydraulicBoundaryLocation1
+ });
// Assert
// Note: To make sure the clear is performed regardless of what is done with
// the return result, no ToArray() should be called before these assertions:
- Assert.IsTrue(failureMechanism.Calculations.Cast()
- .All(c => c.InputParameters.HydraulicBoundaryLocation == null
- && !c.HasOutput));
+ Assert.IsTrue(expectedAffectedCalculations.All(c => !c.HasOutput));
+ Assert.IsTrue(calculations.All(c => c.InputParameters.HydraulicBoundaryLocation != hydraulicBoundaryLocation1));
- CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs),
- affectedItems);
+ CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems);
}
[Test]
@@ -395,7 +427,7 @@
CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
}
- private static GrassCoverErosionInwardsFailureMechanism CreateFullyConfiguredFailureMechanism()
+ private static GrassCoverErosionInwardsFailureMechanism CreateFullyConfiguredFailureMechanism(HydraulicBoundaryLocation hydraulicBoundaryLocation = null)
{
DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile("Profile 1", "ID 1");
DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile("Profile 2", "ID 2");
@@ -423,7 +455,10 @@
section2
}, "some/path/to/sections");
- var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0);
+ if (hydraulicBoundaryLocation == null)
+ {
+ hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
+ }
var calculation = new GrassCoverErosionInwardsCalculation();
var calculationWithOutput = new GrassCoverErosionInwardsCalculation
Index: Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs
===================================================================
diff -u -r21c7e49c38a6fb16110f00f6714b882fe02def3b -rc3a67fb890682c3747d265cf082c279801e886af
--- Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (.../RiskeerDataSynchronizationService.cs) (revision 21c7e49c38a6fb16110f00f6714b882fe02def3b)
+++ Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (.../RiskeerDataSynchronizationService.cs) (revision c3a67fb890682c3747d265cf082c279801e886af)
@@ -94,7 +94,8 @@
pipingFailureMechanism, hydraulicBoundaryLocations));
break;
case GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwardsFailureMechanism:
- changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism));
+ changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(
+ grassCoverErosionInwardsFailureMechanism, hydraulicBoundaryLocations));
break;
case StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism:
changedObservables.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(stabilityStoneCoverFailureMechanism));