Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs
===================================================================
diff -u -rc842725e65946a75ed597bc0320f0fae5df69625 -rf7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3
--- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision c842725e65946a75ed597bc0320f0fae5df69625)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision f7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3)
@@ -82,7 +82,8 @@
throw new NotSupportedException();
}
- return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result ?? RoundedDouble.NaN;
+ return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result
+ ?? RoundedDouble.NaN;
}
}
}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs
===================================================================
diff -u -r871a2151d7a49d6f50699b6dea82c3e20ba6e409 -rf7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3
--- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision 871a2151d7a49d6f50699b6dea82c3e20ba6e409)
+++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision f7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3)
@@ -21,8 +21,11 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
-using Core.Common.Util.Extensions;
+using Core.Common.Base.Data;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.Hydraulics;
namespace Ringtoets.GrassCoverErosionOutwards.Data
@@ -59,5 +62,66 @@
failureMechanism.HydraulicBoundaryLocations.AddRange(hydraulicBoundaryLocations);
}
+
+ ///
+ /// Gets the normative assessment level for a .
+ ///
+ /// The assessment section to get the normative assessment level from.
+ /// The failure mechanism to get the normative assessment level from.
+ /// The hydraulic boundary location to get the normative assessment level for.
+ /// The normative assessment level or when:
+ ///
+ /// - is null;
+ /// - is not part of ;
+ /// - is not part of ;
+ /// - contains no corresponding calculation output.
+ ///
+ ///
+ /// Thrown when
+ /// or is null.
+ /// Thrown when
+ /// contains an invalid value of .
+ /// Thrown when
+ /// contains a valid value of , but unsupported.
+ public static RoundedDouble GetNormativeAssessmentLevel(this GrassCoverErosionOutwardsFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection,
+ HydraulicBoundaryLocation hydraulicBoundaryLocation)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ NormType normType = assessmentSection.FailureMechanismContribution.NormativeNorm;
+
+ if (!Enum.IsDefined(typeof(NormType), normType))
+ {
+ throw new InvalidEnumArgumentException(nameof(normType),
+ (int)normType,
+ typeof(NormType));
+ }
+
+ IEnumerable calculations;
+
+ switch (normType)
+ {
+ case NormType.Signaling:
+ calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm;
+ break;
+ case NormType.LowerLimit:
+ calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm;
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result
+ ?? RoundedDouble.NaN;
+ }
}
}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismExtensionsTest.cs
===================================================================
diff -u -r871a2151d7a49d6f50699b6dea82c3e20ba6e409 -rf7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3
--- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismExtensionsTest.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensionsTest.cs) (revision 871a2151d7a49d6f50699b6dea82c3e20ba6e409)
+++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismExtensionsTest.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensionsTest.cs) (revision f7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3)
@@ -20,9 +20,17 @@
// All rights reserved.
using System;
+using System.ComponentModel;
using System.Linq;
+using Core.Common.Base.Data;
+using Core.Common.TestUtil;
using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.GrassCoverErosionOutwards.Util.TestUtil;
namespace Ringtoets.GrassCoverErosionOutwards.Data.Test
{
@@ -98,5 +106,158 @@
Assert.AreEqual(2, failureMechanism.HydraulicBoundaryLocations.Count);
CollectionAssert.AreEqual(locations, failureMechanism.HydraulicBoundaryLocations);
}
+
+ [Test]
+ public void GetNormativeAssessmentLevel_FailureMechanismnNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate test = () => GrassCoverErosionOutwardsFailureMechanismExtensions.GetNormativeAssessmentLevel(null, assessmentSection,
+ new TestHydraulicBoundaryLocation());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("failureMechanism", paramName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GetNormativeAssessmentLevel_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ TestDelegate test = () => failureMechanism.GetNormativeAssessmentLevel(null, new TestHydraulicBoundaryLocation());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("assessmentSection", paramName);
+ }
+
+ [Test]
+ public void GetNormativeAssessmentLevel_AssessmentSectionWithInvalidNormType_ThrowsInvalidEnumArgumentException()
+ {
+ // Setup
+ const int invalidValue = 9999;
+
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = (NormType) invalidValue;
+
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ TestDelegate test = () => failureMechanism.GetNormativeAssessmentLevel(assessmentSection, new TestHydraulicBoundaryLocation());
+
+ // Assert
+ string expectedMessage = $"The value of argument 'normType' ({invalidValue}) is invalid for Enum type '{nameof(NormType)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage).ParamName;
+ Assert.AreEqual("normType", parameterName);
+ }
+
+ [Test]
+ public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeSignaling_ReturnsCorrespondingAssessmentLevel()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = NormType.Signaling;
+
+ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AddHydraulicBoundaryLocations(
+ failureMechanism, assessmentSection,
+ new[]
+ {
+ hydraulicBoundaryLocation
+ }, true);
+
+ // Call
+ RoundedDouble normativeAssessmentLevel = failureMechanism.GetNormativeAssessmentLevel(assessmentSection, hydraulicBoundaryLocation);
+
+ // Assert
+ Assert.AreEqual(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm.ElementAt(0).Output.Result, normativeAssessmentLevel);
+ }
+
+ [Test]
+ public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeLowerLimit_ReturnsCorrespondingAssessmentLevel()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = NormType.LowerLimit;
+
+ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AddHydraulicBoundaryLocations(
+ failureMechanism, assessmentSection,
+ new[]
+ {
+ hydraulicBoundaryLocation
+ }, true);
+
+ // Call
+ RoundedDouble normativeAssessmentLevel = failureMechanism.GetNormativeAssessmentLevel(assessmentSection, hydraulicBoundaryLocation);
+
+ // Assert
+ Assert.AreEqual(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0).Output.Result, normativeAssessmentLevel);
+ }
+
+ [TestCase(NormType.Signaling)]
+ [TestCase(NormType.LowerLimit)]
+ public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNull_ReturnsNaN(NormType normType)
+ {
+ // Setup
+ var assessmentSection = new AssessmentSectionStub();
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ RoundedDouble normativeAssessmentLevel = failureMechanism.GetNormativeAssessmentLevel(assessmentSection, null);
+
+ // Assert
+ Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel);
+ }
+
+ [TestCase(NormType.Signaling)]
+ [TestCase(NormType.LowerLimit)]
+ public void GetNormativeAssessmentLevel_NoCorrespondingCalculation_ReturnsNaN(NormType normType)
+ {
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = normType;
+
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ RoundedDouble normativeAssessmentLevel = failureMechanism.GetNormativeAssessmentLevel(assessmentSection, new TestHydraulicBoundaryLocation());
+
+ // Assert
+ Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel);
+ }
+
+ [TestCase(NormType.Signaling)]
+ [TestCase(NormType.LowerLimit)]
+ public void GetNormativeAssessmentLevel_NoCorrespondingAssessmentLevelOutput_ReturnsNaN(NormType normType)
+ {
+ var assessmentSection = new AssessmentSectionStub();
+ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
+
+ assessmentSection.FailureMechanismContribution.NormativeNorm = normType;
+ assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
+ {
+ hydraulicBoundaryLocation
+ });
+
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ RoundedDouble normativeAssessmentLevel = failureMechanism.GetNormativeAssessmentLevel(assessmentSection, hydraulicBoundaryLocation);
+
+ // Assert
+ Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/Ringtoets.GrassCoverErosionOutwards.Data.Test.csproj
===================================================================
diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -rf7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3
--- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/Ringtoets.GrassCoverErosionOutwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Data.Test.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479)
+++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Data.Test/Ringtoets.GrassCoverErosionOutwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Data.Test.csproj) (revision f7d73da8b5830eb8d37f50e94eb85e22f3e6b1c3)
@@ -87,5 +87,9 @@
{D1234D03-76BC-437D-B941-DFF14A2A108D}
Ringtoets.GrassCoverErosionOutwards.Data.TestUtil
+
+ {C700ED66-8565-48B2-9A4E-B0D33FB2B26D}
+ Ringtoets.GrassCoverErosionOutwards.Util.TestUtil
+
\ No newline at end of file