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");