Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -rf2184f65cf8300b422f8bbf67d6b8aaafd0647e6 -r00a81cf63e2bee520315ebd8ce9795d0920a97da --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision f2184f65cf8300b422f8bbf67d6b8aaafd0647e6) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 00a81cf63e2bee520315ebd8ce9795d0920a97da) @@ -35,6 +35,7 @@ using Ringtoets.HydraRing.Calculation.Parsers; using Ringtoets.HydraRing.IO; using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.HeightStructures.Service { @@ -189,9 +190,19 @@ else { validationResult.AddRange(DistributionValidationService.ValidateDistribution(inputParameters.StormDuration, "stormduur")); - //DeviationWaveDirection + + if (IsInvalidNumber(inputParameters.DeviationWaveDirection)) + { + validationResult.Add(string.Format("De waarde voor '{0}' moet een geldig getal zijn.", "afwijking golfrichting")); + } + validationResult.AddRange(DistributionValidationService.ValidateDistribution(inputParameters.ModelFactorSuperCriticalFlow, "modelfactor overloopdebiet volkomen overlaat")); - //Orientatie + + if (IsInvalidNumber(inputParameters.StructureNormalOrientation)) + { + validationResult.Add(RingtoetsCommonDataResources.Orientation_Value_needs_to_be_between_0_and_360); + } + validationResult.AddRange(DistributionValidationService.ValidateDistribution(inputParameters.FlowWidthAtBottomProtection, "stroomvoerende breedte bodembescherming")); validationResult.AddRange(DistributionValidationService.ValidateDistribution(inputParameters.WidthFlowApertures, "breedte van doorstroomopening")); validationResult.AddRange(DistributionValidationService.ValidateDistribution(inputParameters.StorageStructureArea, "kombergend oppervlak")); @@ -204,7 +215,7 @@ return validationResult.ToArray(); } - private static bool IsValidNumber(RoundedDouble value) + private static bool IsInvalidNumber(RoundedDouble value) { return double.IsNaN(value) || double.IsInfinity(value); } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs =================================================================== diff -u -r12adc4f02f30f7e1d65953624958ed5af436f24f -r00a81cf63e2bee520315ebd8ce9795d0920a97da --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs (.../HeightStructuresCalculationActivityIntegrationTest.cs) (revision 12adc4f02f30f7e1d65953624958ed5af436f24f) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs (.../HeightStructuresCalculationActivityIntegrationTest.cs) (revision 00a81cf63e2bee520315ebd8ce9795d0920a97da) @@ -142,7 +142,7 @@ new Point2D(1, 1) })); - var calculation = new HeightStructuresCalculation + var calculation = new TestHeightStructuresCalculation() { InputParameters = { @@ -192,7 +192,7 @@ new Point2D(1, 1) })); - var calculation = new HeightStructuresCalculation + var calculation = new TestHeightStructuresCalculation() { InputParameters = { Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs =================================================================== diff -u -r25a8a43066f92ee22f310ba729deafbec7201b91 -r00a81cf63e2bee520315ebd8ce9795d0920a97da --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision 25a8a43066f92ee22f310ba729deafbec7201b91) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision 00a81cf63e2bee520315ebd8ce9795d0920a97da) @@ -139,7 +139,7 @@ const string name = ""; - HeightStructuresCalculation calculation = new HeightStructuresCalculation + HeightStructuresCalculation calculation = new TestHeightStructuresCalculation() { Name = name, InputParameters = @@ -167,6 +167,96 @@ } [Test] + [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] + public void Validate_DeviationWaveDirectionInvalid_ReturnsFalse(double value) + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(new HeightStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + const string name = ""; + const string parameterName = "afwijking golfrichting"; + string expectedValidationMessage = string.Format("Validatie mislukt: De waarde voor '{0}' moet een geldig getal zijn.", parameterName); + + var calculation = new TestHeightStructuresCalculation() + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + Structure = new TestHeightStructure() + } + }; + + calculation.InputParameters.DeviationWaveDirection = (RoundedDouble) value; + + // Call + bool isValid = false; + Action call = () => isValid = new HeightStructuresCalculationService().Validate(calculation, assessmentSectionStub); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(expectedValidationMessage, msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] + public void Validate_StructureNormalOrientationInvalid_ReturnsFalse() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(new HeightStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + const string name = ""; + string expectedValidationMessage = "Validatie mislukt: De waarde voor de oriëntatie moet in het bereik [0, 360] liggen."; + + var calculation = new TestHeightStructuresCalculation() + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + Structure = new TestHeightStructure() + } + }; + + calculation.InputParameters.StructureNormalOrientation = (RoundedDouble) double.NaN; + + // Call + bool isValid = false; + Action call = () => isValid = new HeightStructuresCalculationService().Validate(calculation, assessmentSectionStub); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(expectedValidationMessage, msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] [TestCaseSource("NormalDistributionsWithInvalidMean")] public void Validate_NormalDistributionMeanInvalid_ReturnsFalse(double meanOne, double meanTwo, double meanThree, string parameterName) { @@ -369,7 +459,7 @@ const string name = ""; - HeightStructuresCalculation calculation = new HeightStructuresCalculation + HeightStructuresCalculation calculation = new TestHeightStructuresCalculation() { Name = name, InputParameters = @@ -640,8 +730,7 @@ } } - private static - IAssessmentSection CreateAssessmentSectionStub(IFailureMechanism failureMechanism, MockRepository mockRepository) + private static IAssessmentSection CreateAssessmentSectionStub(IFailureMechanism failureMechanism, MockRepository mockRepository) { var assessmentSectionStub = mockRepository.Stub(); assessmentSectionStub.Stub(a => a.Id).Return("21"); @@ -722,8 +811,8 @@ { get { - yield return new TestCaseData(double.NaN, 1, 2, 3, 4, "stormduur"); - yield return new TestCaseData(double.PositiveInfinity, 1, 2, 3, 4, "stormduur"); + yield return new TestCaseData(double.NaN, 1, 2, 3, "stormduur"); + yield return new TestCaseData(double.PositiveInfinity, 1, 2, 3, "stormduur"); yield return new TestCaseData(1, double.NaN, 2, 3, "kombergend oppervlak"); yield return new TestCaseData(1, double.PositiveInfinity, 2, 3, "kombergend oppervlak");