Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u -rf70611f9af51a6ffc8cb4d8d28d1ea806104937b -rad4a977be1c898ddc8bebd75252212538f77035f --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision f70611f9af51a6ffc8cb4d8d28d1ea806104937b) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision ad4a977be1c898ddc8bebd75252212538f77035f) @@ -53,6 +53,7 @@ private static readonly string validDataFilepath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); #region Parameter name mappings + private static readonly Dictionary parameterNames = new Dictionary() { { @@ -104,6 +105,7 @@ "widthFlowApertures", "breedte van doorstroomopening" } }; + #endregion [Test] @@ -207,8 +209,9 @@ } }; - // Call bool isValid = false; + + // Call Action call = () => isValid = ClosingStructuresCalculationService.Validate(calculation, assessmentSectionStub); // Assert @@ -245,58 +248,8 @@ Name = name }; - calculation.InputParameters.DeviationWaveDirection = RoundedDouble.NaN; - calculation.InputParameters.FactorStormDurationOpenStructure = (RoundedDouble) value; - calculation.InputParameters.ModelFactorSuperCriticalFlow.Mean = (RoundedDouble) value; - calculation.InputParameters.StructureNormalOrientation = RoundedDouble.NaN; + SetInvalidInputParameters(calculation, (RoundedDouble) value); - calculation.InputParameters.LevelCrestStructureNotClosing.Mean = (RoundedDouble) value; - calculation.InputParameters.WidthFlowApertures.Mean = (RoundedDouble) value; - - if (double.IsNegativeInfinity(value)) - { - calculation.InputParameters.StormDuration.Mean = RoundedDouble.NaN; - calculation.InputParameters.StormDuration.CoefficientOfVariation = RoundedDouble.NaN; - calculation.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation = RoundedDouble.NaN; - calculation.InputParameters.LevelCrestStructureNotClosing.StandardDeviation = RoundedDouble.NaN; - - calculation.InputParameters.AllowedLevelIncreaseStorage.Mean = RoundedDouble.NaN; - calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation = RoundedDouble.NaN; - - calculation.InputParameters.StorageStructureArea.Mean = RoundedDouble.NaN; - calculation.InputParameters.StorageStructureArea.CoefficientOfVariation = RoundedDouble.NaN; - - calculation.InputParameters.FlowWidthAtBottomProtection.Mean = RoundedDouble.NaN; - calculation.InputParameters.FlowWidthAtBottomProtection.StandardDeviation = RoundedDouble.NaN; - - calculation.InputParameters.CriticalOvertoppingDischarge.Mean = RoundedDouble.NaN; - calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = RoundedDouble.NaN; - - calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation = RoundedDouble.NaN; - } - else - { - calculation.InputParameters.StormDuration.Mean = (RoundedDouble) value; - calculation.InputParameters.StormDuration.CoefficientOfVariation = (RoundedDouble) value; - - calculation.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation = (RoundedDouble) value; - calculation.InputParameters.LevelCrestStructureNotClosing.StandardDeviation = (RoundedDouble) value; - - calculation.InputParameters.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) value; - calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) value; - - calculation.InputParameters.StorageStructureArea.Mean = (RoundedDouble) value; - calculation.InputParameters.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) value; - - calculation.InputParameters.FlowWidthAtBottomProtection.Mean = (RoundedDouble) value; - calculation.InputParameters.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) value; - - calculation.InputParameters.CriticalOvertoppingDischarge.Mean = (RoundedDouble) value; - calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) value; - - calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation = (RoundedDouble) value; - } - // Call bool isValid = false; Action call = () => isValid = ClosingStructuresCalculationService.Validate(calculation, assessmentSectionStub); @@ -334,6 +287,68 @@ } [Test] + [TestCase(double.NaN)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + public void Validate_InvalidLowSillCalculation_LogsErrorAndReturnsFalse(double value) + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(new ClosingStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + const string name = ""; + + var calculation = new TestClosingStructuresCalculation() + { + Name = name, + InputParameters = + { + InflowModelType = ClosingStructureInflowModelType.LowSill + } + }; + SetInvalidInputParameters(calculation, (RoundedDouble) value); + + bool isValid = false; + + // Call + Action call = () => isValid = ClosingStructuresCalculationService.Validate(calculation, assessmentSectionStub); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(21, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterNames["stormDuration"]), msgs[1]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["stormDuration"]), msgs[2]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", parameterNames["insideWaterLevel"]), msgs[3]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["insideWaterLevel"]), msgs[4]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", parameterNames["modelFactorSuperCriticalFlow"]), msgs[5]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["modelFactorSuperCriticalFlow"]), msgs[6]); + StringAssert.StartsWith(string.Format("Validatie mislukt: Er is geen concreet getal ingevoerd voor '{0}'.", parameterNames["factorStormDurationOpenStructure"]), msgs[7]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", parameterNames["widthFlowApertures"]), msgs[8]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["widthFlowApertures"]), msgs[9]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterNames["flowWidthAtBottomProtection"]), msgs[10]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["flowWidthAtBottomProtection"]), msgs[11]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterNames["storageStructureArea"]), msgs[12]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["storageStructureArea"]), msgs[13]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterNames["allowedLevelIncreaseStorage"]), msgs[14]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["allowedLevelIncreaseStorage"]), msgs[15]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", parameterNames["thresholdHeightOpenWeir"]), msgs[16]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["thresholdHeightOpenWeir"]), msgs[17]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterNames["criticalOvertoppingDischarge"]), msgs[18]); + StringAssert.StartsWith(string.Format("Validatie mislukt: De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterNames["criticalOvertoppingDischarge"]), msgs[19]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[20]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] public void Validate_InvalidInFlowModelType_ThrowsNotSupportedException() { // Setup @@ -361,6 +376,7 @@ // Assert var exception = Assert.Throws(call); Assert.AreEqual("inputParameters", exception.ParamName); + StringAssert.StartsWith("The value of argument 'inputParameters' (9001) is invalid for Enum type 'ClosingStructureInflowModelType'.", exception.Message); Assert.IsFalse(isValid); mockRepository.VerifyAll(); } @@ -855,5 +871,61 @@ }; return assessmentSectionStub; } + + private static void SetInvalidInputParameters(StructuresCalculation input, RoundedDouble value) + { + input.InputParameters.DeviationWaveDirection = RoundedDouble.NaN; + input.InputParameters.DrainCoefficient.Mean = value; + input.InputParameters.FactorStormDurationOpenStructure = value; + input.InputParameters.InsideWaterLevel.Mean = value; + input.InputParameters.LevelCrestStructureNotClosing.Mean = value; + input.InputParameters.ModelFactorSuperCriticalFlow.Mean = value; + input.InputParameters.StructureNormalOrientation = RoundedDouble.NaN; + input.InputParameters.ThresholdHeightOpenWeir.Mean = value; + input.InputParameters.WidthFlowApertures.Mean = value; + + if (double.IsNegativeInfinity(value)) + { + input.InputParameters.AllowedLevelIncreaseStorage.Mean = RoundedDouble.NaN; + input.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.AreaFlowApertures.Mean = RoundedDouble.NaN; + input.InputParameters.AreaFlowApertures.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.CriticalOvertoppingDischarge.Mean = RoundedDouble.NaN; + input.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = RoundedDouble.NaN; + input.InputParameters.DrainCoefficient.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.FlowWidthAtBottomProtection.Mean = RoundedDouble.NaN; + input.InputParameters.FlowWidthAtBottomProtection.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.InsideWaterLevel.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.LevelCrestStructureNotClosing.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.StorageStructureArea.Mean = RoundedDouble.NaN; + input.InputParameters.StorageStructureArea.CoefficientOfVariation = RoundedDouble.NaN; + input.InputParameters.StormDuration.Mean = RoundedDouble.NaN; + input.InputParameters.StormDuration.CoefficientOfVariation = RoundedDouble.NaN; + input.InputParameters.ThresholdHeightOpenWeir.StandardDeviation = RoundedDouble.NaN; + input.InputParameters.WidthFlowApertures.CoefficientOfVariation = RoundedDouble.NaN; + } + else + { + input.InputParameters.AllowedLevelIncreaseStorage.Mean = value; + input.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation = value; + input.InputParameters.AreaFlowApertures.Mean = value; + input.InputParameters.AreaFlowApertures.StandardDeviation = value; + input.InputParameters.CriticalOvertoppingDischarge.Mean = value; + input.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = value; + input.InputParameters.DrainCoefficient.StandardDeviation = value; + input.InputParameters.FlowWidthAtBottomProtection.Mean = value; + input.InputParameters.FlowWidthAtBottomProtection.StandardDeviation = value; + input.InputParameters.InsideWaterLevel.StandardDeviation = value; + input.InputParameters.LevelCrestStructureNotClosing.StandardDeviation = value; + input.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation = value; + input.InputParameters.StorageStructureArea.Mean = value; + input.InputParameters.StorageStructureArea.CoefficientOfVariation = value; + input.InputParameters.StormDuration.Mean = value; + input.InputParameters.StormDuration.CoefficientOfVariation = value; + input.InputParameters.ThresholdHeightOpenWeir.StandardDeviation = value; + input.InputParameters.WidthFlowApertures.CoefficientOfVariation = value; + } + } } } \ No newline at end of file