Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs
===================================================================
diff -u -r0eddea1a45f0d9efb0a2a12e90eb99e814d1becb -re5c50bb83746132c8263dc016f768197f83c33c5
--- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 0eddea1a45f0d9efb0a2a12e90eb99e814d1becb)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision e5c50bb83746132c8263dc016f768197f83c33c5)
@@ -89,6 +89,58 @@
}
///
+ /// Gets the normative for a .
+ ///
+ /// The assessment section to get the from.
+ /// The hydraulic boundary location to get the normative
+ /// for.
+ /// The normative or null when:
+ ///
+ /// - is null;
+ /// - is not part of ;
+ /// - contains no corresponding calculation.
+ ///
+ ///
+ /// Thrown when
+ /// is null.
+ /// Thrown when
+ /// contains an invalid value of .
+ /// Thrown when
+ /// contains a valid value of , but unsupported.
+ public static HydraulicBoundaryLocationCalculation GetNormativeHydraulicBoundaryLocationCalculation(this IAssessmentSection assessmentSection,
+ HydraulicBoundaryLocation hydraulicBoundaryLocation)
+ {
+ 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 = assessmentSection.WaterLevelCalculationsForSignalingNorm;
+ break;
+ case NormType.LowerLimit:
+ calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm;
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ return GetHydraulicBoundaryLocationCalculationFromCalculations(hydraulicBoundaryLocation, calculations);
+ }
+
+ ///
/// Gets the assessment level for a based on .
///
/// The assessment section to get the assessment level from.
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs
===================================================================
diff -u -r346957cc101c65f06201d346eff71d3454aa7e31 -re5c50bb83746132c8263dc016f768197f83c33c5
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs (.../AssessmentSectionExtensionsTest.cs) (revision 346957cc101c65f06201d346eff71d3454aa7e31)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs (.../AssessmentSectionExtensionsTest.cs) (revision e5c50bb83746132c8263dc016f768197f83c33c5)
@@ -117,12 +117,12 @@
}
[Test]
- [TestCaseSource(nameof(GetNormativeAssessementLevelConfigurationPerNormType))]
+ [TestCaseSource(nameof(GetNormativeHydraulicBoundaryLocationCalculationPerNormType))]
public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutput_ReturnsCorrespondingAssessmentLevel(
IAssessmentSection assessmentSection,
HydraulicBoundaryLocation hydraulicBoundaryLocation,
NormType normType,
- RoundedDouble expectedNormativeAssessmentLevel)
+ HydraulicBoundaryLocationCalculation calculation)
{
// Setup
assessmentSection.FailureMechanismContribution.NormativeNorm = normType;
@@ -131,6 +131,7 @@
RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation);
// Assert
+ RoundedDouble expectedNormativeAssessmentLevel = calculation.Output.Result;
Assert.AreEqual(expectedNormativeAssessmentLevel, normativeAssessmentLevel);
}
@@ -312,6 +313,86 @@
}
[Test]
+ public void GetNormativeHydraulicBoundaryLocationCalculation_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssessmentSectionExtensions.GetNormativeHydraulicBoundaryLocationCalculation(null, new TestHydraulicBoundaryLocation());
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void GetNormativeHydraulicBoundaryLocationCalculation_AssessmentSectionWithInvalidNormType_ThrowsInvalidEnumArgumentException()
+ {
+ // Setup
+ const int invalidValue = 9999;
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ assessmentSection.FailureMechanismContribution.NormativeNorm = (NormType)invalidValue;
+
+ // Call
+ TestDelegate test = () => assessmentSection.GetNormativeHydraulicBoundaryLocationCalculation(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 GetNormativeHydraulicBoundaryLocationCalculation_HydraulicBoundaryLocationNull_ReturnsNull()
+ {
+ // Setup
+ var random = new Random(21);
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = random.NextEnumValue();
+
+ // Call
+ HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = assessmentSection.GetNormativeHydraulicBoundaryLocationCalculation(null);
+
+ // Assert
+ Assert.IsNull(hydraulicBoundaryLocationCalculation);
+ }
+
+ [Test]
+ public void GetNormativeHydraulicBoundaryLocationCalculation_NoCorrespondingCalculation_ReturnsNull()
+ {
+ // Setup
+ var random = new Random(21);
+ var assessmentSection = new AssessmentSectionStub();
+ assessmentSection.FailureMechanismContribution.NormativeNorm = random.NextEnumValue();
+
+ // Call
+ HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation =
+ assessmentSection.GetNormativeHydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
+
+ // Assert
+ Assert.IsNull(hydraulicBoundaryLocationCalculation);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetNormativeHydraulicBoundaryLocationCalculationPerNormType))]
+ public void GetNormativeHydraulicBoundaryLocationCalculation_HydraulicBoundaryLocation_ReturnsCorrespondingCalculation(
+ IAssessmentSection assessmentSection,
+ HydraulicBoundaryLocation hydraulicBoundaryLocation,
+ NormType normType,
+ HydraulicBoundaryLocationCalculation calculation)
+ {
+ // Setup
+ assessmentSection.FailureMechanismContribution.NormativeNorm = normType;
+
+ // Call
+ HydraulicBoundaryLocationCalculation normativeAssessmentLevel =
+ assessmentSection.GetNormativeHydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation);
+
+ // Assert
+ Assert.AreSame(calculation, normativeAssessmentLevel);
+ }
+
+ [Test]
public void GetNorm_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
@@ -354,8 +435,47 @@
Assert.AreEqual(expectedNorm, norm);
}
- private static IEnumerable GetNormativeAssessementLevelConfigurationPerNormType()
+ private static IEnumerable GetNormConfigurationPerAssessmentSectionCategoryType()
{
+ const double signalingNorm = 0.002;
+ const double lowerLimitNorm = 0.005;
+
+ var assessmentSection = new AssessmentSectionStub
+ {
+ FailureMechanismContribution =
+ {
+ LowerLimitNorm = lowerLimitNorm,
+ SignalingNorm = signalingNorm
+ }
+ };
+
+ yield return new TestCaseData(
+ assessmentSection,
+ AssessmentSectionCategoryType.FactorizedSignalingNorm,
+ signalingNorm / 30
+ ).SetName("FactorizedSignalingNorm");
+
+ yield return new TestCaseData(
+ assessmentSection,
+ AssessmentSectionCategoryType.SignalingNorm,
+ signalingNorm
+ ).SetName("SignalingNorm");
+
+ yield return new TestCaseData(
+ assessmentSection,
+ AssessmentSectionCategoryType.LowerLimitNorm,
+ lowerLimitNorm
+ ).SetName("LowerLimitNorm");
+
+ yield return new TestCaseData(
+ assessmentSection,
+ AssessmentSectionCategoryType.FactorizedLowerLimitNorm,
+ lowerLimitNorm * 30
+ ).SetName("FactorizedLowerLimitNorm");
+ }
+
+ private static IEnumerable GetNormativeHydraulicBoundaryLocationCalculationPerNormType()
+ {
var assessmentSection = new AssessmentSectionStub();
var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
@@ -368,53 +488,53 @@
assessmentSection,
hydraulicBoundaryLocation,
NormType.Signaling,
- assessmentSection.WaterLevelCalculationsForSignalingNorm.ElementAt(0).Output.Result
+ assessmentSection.WaterLevelCalculationsForSignalingNorm.ElementAt(0)
).SetName("SignalingNorm");
yield return new TestCaseData(
assessmentSection,
hydraulicBoundaryLocation,
NormType.LowerLimit,
- assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0).Output.Result
+ assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0)
).SetName("LowerLimitNorm");
}
- private static IEnumerable GetNormConfigurationPerAssessmentSectionCategoryType()
+ private static IEnumerable GetHydraulicBoundaryLocationCalculationConfigurationPerAssessmentSectionCategoryType()
{
- const double signalingNorm = 0.002;
- const double lowerLimitNorm = 0.005;
+ var assessmentSection = new AssessmentSectionStub();
+ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
- var assessmentSection = new AssessmentSectionStub
+ assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
{
- FailureMechanismContribution =
- {
- LowerLimitNorm = lowerLimitNorm,
- SignalingNorm = signalingNorm
- }
- };
+ hydraulicBoundaryLocation
+ }, true);
yield return new TestCaseData(
assessmentSection,
+ hydraulicBoundaryLocation,
AssessmentSectionCategoryType.FactorizedSignalingNorm,
- signalingNorm / 30
+ assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm.ElementAt(0)
).SetName("FactorizedSignalingNorm");
yield return new TestCaseData(
assessmentSection,
+ hydraulicBoundaryLocation,
AssessmentSectionCategoryType.SignalingNorm,
- signalingNorm
+ assessmentSection.WaterLevelCalculationsForSignalingNorm.ElementAt(0)
).SetName("SignalingNorm");
yield return new TestCaseData(
assessmentSection,
+ hydraulicBoundaryLocation,
AssessmentSectionCategoryType.LowerLimitNorm,
- lowerLimitNorm
+ assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0)
).SetName("LowerLimitNorm");
yield return new TestCaseData(
assessmentSection,
+ hydraulicBoundaryLocation,
AssessmentSectionCategoryType.FactorizedLowerLimitNorm,
- lowerLimitNorm * 30
+ assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm.ElementAt(0)
).SetName("FactorizedLowerLimitNorm");
}
}