Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u -r602d5e06d2d39e5f5133842526246edb8bb97a16 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 602d5e06d2d39e5f5133842526246edb8bb97a16) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -308,6 +308,7 @@ { var validationRules = new List { + new UseBreakWaterRule(input), new VariationCoefficientLogNormalDistributionRule(input.StormDuration, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)), new NumericInputRule(input.DeviationWaveDirection, @@ -339,6 +340,7 @@ { var validationRules = new List { + new UseBreakWaterRule(input), new VariationCoefficientLogNormalDistributionRule(input.StormDuration, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)), new NormalDistributionRule(input.InsideWaterLevel, @@ -368,6 +370,7 @@ { var validationRules = new List { + new UseBreakWaterRule(input), new VariationCoefficientLogNormalDistributionRule(input.StormDuration, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)), new NormalDistributionRule(input.InsideWaterLevel, Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u -r56ec7114c4c96eeee4a1bb16d0ecac2bb10a49b8 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision 56ec7114c4c96eeee4a1bb16d0ecac2bb10a49b8) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -358,7 +358,7 @@ } [Test] - public void Validate_InvalidInFlowModelType_ThrowsNotSupportedException() + public void Validate_InvalidInFlowModelType_ThrowsInvalidEnumArgumentException() { // Setup var mockRepository = new MockRepository(); @@ -393,7 +393,7 @@ } [Test] - public void Calculate_InvalidInFlowModelType_ThrowsNotSupportedException() + public void Calculate_InvalidInFlowModelType_ThrowsInvalidEnumArgumentException() { // Setup var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); @@ -442,6 +442,52 @@ } [Test] + [Combinatorial] + public void Validate_UsesBreakWaterAndHasInvalidBreakWaterSettings_ReturnsFalse( + [Values(ClosingStructureInflowModelType.VerticalWall, ClosingStructureInflowModelType.LowSill, ClosingStructureInflowModelType.FloodedCulvert)] ClosingStructureInflowModelType inflowModelType, + [Values(double.NaN, double.NegativeInfinity, double.PositiveInfinity)] double breakWaterHeight) + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = AssessmentSectionHelper.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 = inflowModelType, + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + ForeshoreProfile = CreateForeshoreProfile(new BreakWater(BreakWaterType.Dam, breakWaterHeight)), + UseBreakWater = true + } + }; + + bool isValid = false; + + // Call + Action call = () => isValid = ClosingStructuresCalculationService.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("Validatie mislukt: Er is geen geldige damhoogte ingevoerd.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] [TestCase(true, false)] [TestCase(true, true)] [TestCase(false, false)] @@ -719,10 +765,10 @@ } [Test] - [TestCase(ClosingStructureInflowModelType.VerticalWall)] - [TestCase(ClosingStructureInflowModelType.LowSill)] - [TestCase(ClosingStructureInflowModelType.FloodedCulvert)] - public void Calculate_ValidCalculation_LogStartAndEndAndReturnOutput(ClosingStructureInflowModelType inflowModelType) + [Combinatorial] + public void Calculate_ValidCalculation_LogStartAndEndAndReturnOutput( + [Values(ClosingStructureInflowModelType.VerticalWall, ClosingStructureInflowModelType.LowSill, ClosingStructureInflowModelType.FloodedCulvert)] ClosingStructureInflowModelType inflowModelType, + [Values(CalculationType.NoForeshore, CalculationType.ForeshoreWithoutBreakWater, CalculationType.ForeshoreWithValidBreakWater)] CalculationType calculationType) { // Setup var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); @@ -743,27 +789,48 @@ InputParameters = { HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - InflowModelType = inflowModelType + InflowModelType = inflowModelType, + ForeshoreProfile = CreateForeshoreProfile(new BreakWater(BreakWaterType.Dam, 10)), + UseForeshore = true, + UseBreakWater = true } }; - // Call - Action call = () => new ClosingStructuresCalculationService().Calculate(calculation, - assessmentSectionStub, - closingStructuresFailureMechanism, - validDataFilepath); + switch (calculationType) + { + case CalculationType.NoForeshore: + calculation.InputParameters.ForeshoreProfile = null; + calculation.InputParameters.UseForeshore = false; + calculation.InputParameters.UseBreakWater = false; + break; + case CalculationType.ForeshoreWithoutBreakWater: + calculation.InputParameters.ForeshoreProfile = CreateForeshoreProfile(null); + calculation.InputParameters.UseBreakWater = false; + break; + case CalculationType.ForeshoreWithValidBreakWater: + break; + } - // Assert - TestHelper.AssertLogMessages(call, messages => + // Call + using (new HydraRingCalculatorFactoryConfig()) { - var msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekeningsverslag. Klik op details voor meer informatie.", msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); - }); - Assert.IsNotNull(calculation.Output); + Action call = () => new ClosingStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + closingStructuresFailureMechanism, + validDataFilepath); + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekeningsverslag. Klik op details voor meer informatie.", msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.IsNotNull(calculation.Output); + } + mockRepository.VerifyAll(); } @@ -935,6 +1002,25 @@ } } + public enum CalculationType + { + NoForeshore, + ForeshoreWithValidBreakWater, + ForeshoreWithoutBreakWater + } + + private static ForeshoreProfile CreateForeshoreProfile(BreakWater breakWater) + { + return new ForeshoreProfile(new Point2D(0, 0), + new[] + { + new Point2D(3.3, 4.4), + new Point2D(5.5, 6.6) + }, + breakWater, + new ForeshoreProfile.ConstructionProperties()); + } + #region Parameter name mappings private const string insideWaterLevel = "binnenwaterstand"; Fisheye: Tag dc80ceebd52da19d841b46b5300695fd5c83e4a6 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Service/DistributionValidation.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -48,10 +48,10 @@ Properties\GlobalAssembly.cs - + Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/UseBreakWaterRule.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/UseBreakWaterRule.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/UseBreakWaterRule.cs (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -0,0 +1,57 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using Ringtoets.Common.Data.DikeProfiles; +using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; + +namespace Ringtoets.Common.Service.ValidationRules +{ + /// + /// Validation rule to validate the properties. + /// + public class UseBreakWaterRule : ValidationRule + { + private readonly IUseBreakWater breakWater; + + /// + /// Instantiates a to validate the properties of calculation inputs that implement + /// . + /// + /// The that needs to be validated. + public UseBreakWaterRule(IUseBreakWater breakWater) + { + this.breakWater = breakWater; + } + + public override IEnumerable Validate() + { + var messages = new List(); + + if (breakWater.UseBreakWater && IsInValidNumber(breakWater.BreakWater.Height)) + { + messages.Add(RingtoetsCommonServiceResources.Validation_Invalid_BreakWaterHeight_value); + } + + return messages; + } + } +} \ No newline at end of file Fisheye: Tag dc80ceebd52da19d841b46b5300695fd5c83e4a6 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Service.Test/DistributionValidationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -62,13 +62,13 @@ - + Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs (.../LogNormalDistributionRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs (.../LogNormalDistributionRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -37,7 +37,7 @@ public void Validate_ValidNormalDistribution_NoErrorMessage() { // Setup - ValidationRule rule = new LogNormalDistributionRule(new LogNormalDistribution(2), paramName); + var rule = new LogNormalDistributionRule(new LogNormalDistribution(2), paramName); // Call IEnumerable message = rule.Validate(); @@ -58,7 +58,7 @@ Mean = (RoundedDouble) value }; - ValidationRule rule = new LogNormalDistributionRule(distribution, paramName); + var rule = new LogNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); @@ -82,7 +82,7 @@ StandardDeviation = (RoundedDouble) value }; - ValidationRule rule = new LogNormalDistributionRule(distribution, paramName); + var rule = new LogNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs (.../NormalDistributionRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs (.../NormalDistributionRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -37,7 +37,7 @@ public void Validate_ValidNormalDistribution_NoErrorMessage() { // Setup - ValidationRule rule = new NormalDistributionRule(new NormalDistribution(2), paramName); + var rule = new NormalDistributionRule(new NormalDistribution(2), paramName); // Call IEnumerable message = rule.Validate(); @@ -59,7 +59,7 @@ Mean = (RoundedDouble) value }; - ValidationRule rule = new NormalDistributionRule(distribution, paramName); + var rule = new NormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); @@ -83,7 +83,7 @@ StandardDeviation = (RoundedDouble) value }; - ValidationRule rule = new NormalDistributionRule(distribution, paramName); + var rule = new NormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs (.../NumericInputRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs (.../NumericInputRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -36,7 +36,7 @@ public void Validate_ValidOrientation_NoErrorMessage() { // Setup - ValidationRule rule = new NumericInputRule(new RoundedDouble(2), paramName); + var rule = new NumericInputRule(new RoundedDouble(2), paramName); // Call IEnumerable message = rule.Validate(); @@ -52,7 +52,7 @@ var expectedMessage = string.Format("Er is geen concreet getal ingevoerd voor '{0}'.", paramName); var orientation = new RoundedDouble(2, double.NaN); - ValidationRule rule = new NumericInputRule(orientation, paramName); + var rule = new NumericInputRule(orientation, paramName); // Call IEnumerable messages = rule.Validate(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/UseBreakWaterRuleTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/UseBreakWaterRuleTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/UseBreakWaterRuleTest.cs (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -0,0 +1,113 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Service.ValidationRules; + +namespace Ringtoets.Common.Service.Test.ValidationRules +{ + [TestFixture] + public class UseBreakWaterRuleTest + { + private MockRepository mockRepository; + + [SetUp] + public void SetUp() + { + mockRepository = new MockRepository(); + } + + [Test] + [TestCase(BreakWaterType.Wall)] + [TestCase(BreakWaterType.Caisson)] + [TestCase(BreakWaterType.Dam)] + public void Validate_ValidBreakWaterHeight_NoErrorMessage(BreakWaterType type) + { + // Setup + var breakWaterStub = mockRepository.Stub(); + breakWaterStub.UseBreakWater = true; + breakWaterStub.Stub(call => breakWaterStub.BreakWater).Return(new BreakWater(type, 5.0)); + mockRepository.ReplayAll(); + + var rule = new UseBreakWaterRule(breakWaterStub); + + // Call + IEnumerable message = rule.Validate(); + + // Assert + CollectionAssert.IsEmpty(message); + mockRepository.VerifyAll(); + } + + [Test] + [Combinatorial] + public void Validate_DoesNotUseBreakWaterWithInvalidBreakWaterHeight_NoErrorMessage( + [Values(BreakWaterType.Wall, BreakWaterType.Caisson, BreakWaterType.Dam)] BreakWaterType type, + [Values(double.NaN, double.NegativeInfinity, double.PositiveInfinity)] double height) + { + // Setup + var breakWaterStub = mockRepository.Stub(); + breakWaterStub.UseBreakWater = false; + breakWaterStub.Stub(call => breakWaterStub.BreakWater).Return(new BreakWater(type, height)); + mockRepository.ReplayAll(); + + var rule = new UseBreakWaterRule(breakWaterStub); + + // Call + IEnumerable message = rule.Validate(); + + // Assert + CollectionAssert.IsEmpty(message); + mockRepository.VerifyAll(); + } + + + [Test] + [Combinatorial] + public void Validate_UseBreakWaterWithInvalidBreakWaterHeight_ErrorMessage( + [Values(BreakWaterType.Wall, BreakWaterType.Caisson, BreakWaterType.Dam)] BreakWaterType type, + [Values(double.NaN, double.NegativeInfinity, double.PositiveInfinity)] double height) + { + // Setup + const string expectedMessage = "Er is geen geldige damhoogte ingevoerd."; + var breakWaterStub = mockRepository.Stub(); + breakWaterStub.UseBreakWater = true; + breakWaterStub.Stub(call => breakWaterStub.BreakWater).Return(new BreakWater(type, height)); + mockRepository.ReplayAll(); + + var rule = new UseBreakWaterRule(breakWaterStub); + + // Call + IEnumerable messages = rule.Validate(); + + string[] validationMessages = messages.ToArray(); + + // Assert + Assert.AreEqual(1, validationMessages.Length); + StringAssert.StartsWith(expectedMessage, validationMessages[0]); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs (.../ValidationRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs (.../ValidationRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; @@ -35,7 +34,7 @@ [TestCase(double.NaN)] [TestCase(double.NegativeInfinity)] [TestCase(double.PositiveInfinity)] - public void ValidationRule_ValidatesInvalidNumber_ReturnFalse(double value) + public void IsNumberInvalid_ValidatesInvalidNumber_ReturnTrue(double value) { // Call bool isNumberInvalid = TestRule.PublicIsNumberValid((RoundedDouble) value); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs (.../VariationCoefficientLogNormalDistributionRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs (.../VariationCoefficientLogNormalDistributionRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -37,8 +37,8 @@ public void Validate_ValidDistribution_NoErrorMessage() { // Setup - ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(new VariationCoefficientLogNormalDistribution(2), - paramName); + var rule = new VariationCoefficientLogNormalDistributionRule(new VariationCoefficientLogNormalDistribution(2), + paramName); // Call IEnumerable message = rule.Validate(); @@ -59,7 +59,7 @@ Mean = (RoundedDouble) value }; - ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName); + var rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); @@ -83,7 +83,7 @@ CoefficientOfVariation = (RoundedDouble) value }; - ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName); + var rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs =================================================================== diff -u -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs (.../VariationCoefficientNormalDistributionRuleTest.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs (.../VariationCoefficientNormalDistributionRuleTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -37,8 +37,8 @@ public void Validate_ValidDistribution_NoErrorMessage() { // Setup - ValidationRule rule = new VariationCoefficientNormalDistributionRule(new VariationCoefficientNormalDistribution(2), - paramName); + var rule = new VariationCoefficientNormalDistributionRule(new VariationCoefficientNormalDistribution(2), + paramName); // Call IEnumerable message = rule.Validate(); @@ -60,7 +60,7 @@ Mean = (RoundedDouble) value }; - ValidationRule rule = new VariationCoefficientNormalDistributionRule(distribution, paramName); + var rule = new VariationCoefficientNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); @@ -84,7 +84,7 @@ CoefficientOfVariation = (RoundedDouble) value }; - ValidationRule rule = new VariationCoefficientNormalDistributionRule(distribution, paramName); + var rule = new VariationCoefficientNormalDistributionRule(distribution, paramName); // Call IEnumerable messages = rule.Validate(); Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -r56ec7114c4c96eeee4a1bb16d0ecac2bb10a49b8 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 56ec7114c4c96eeee4a1bb16d0ecac2bb10a49b8) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -185,7 +185,6 @@ else { IEnumerable inputValidationRules = GetInputValidationRules(inputParameters); - foreach (var validationRule in inputValidationRules) { validationResults.AddRange(validationRule.Validate()); @@ -199,6 +198,7 @@ { var validationRules = new List { + new UseBreakWaterRule(input), new VariationCoefficientLogNormalDistributionRule(input.StormDuration, ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)), new NumericInputRule(input.DeviationWaveDirection, Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs =================================================================== diff -u -rd79d26d2ad423b4287d5cdaeb0ac267089a54bf9 -rdc80ceebd52da19d841b46b5300695fd5c83e4a6 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision d79d26d2ad423b4287d5cdaeb0ac267089a54bf9) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision dc80ceebd52da19d841b46b5300695fd5c83e4a6) @@ -446,6 +446,51 @@ } [Test] + [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] + public void Validate_UsesBreakWaterAndHasInvalidBreakWaterSettings_ReturnsFalse(double breakWaterHeight) + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(new HeightStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + const string name = ""; + + var calculation = new TestHeightStructuresCalculation() + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + Structure = new TestHeightStructure(), + ForeshoreProfile = CreateForeshoreProfile(new BreakWater(BreakWaterType.Dam, breakWaterHeight)), + UseBreakWater = true + } + }; + + // Call + bool isValid = false; + Action call = () => isValid = 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("Validatie mislukt: Er is geen geldige damhoogte ingevoerd.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] public void Validate_ValidCalculationInputAndHydraulicBoundaryDatabase_ReturnsTrue() { // Setup @@ -485,7 +530,10 @@ } [Test] - public void Calculate_ValidCalculation_LogStartAndEndAndReturnOutput() + [TestCase(CalculationType.NoForeshore)] + [TestCase(CalculationType.ForeshoreWithValidBreakWater)] + [TestCase(CalculationType.ForeshoreWithoutBreakWater)] + public void Calculate_ValidCalculationInputAndForeshoreWithValidBreakWater_LogStartAndEndAndReturnOutput(CalculationType calculationType) { // Setup var heightStructuresFailureMechanism = new HeightStructuresFailureMechanism(); @@ -505,29 +553,104 @@ InputParameters = { HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - Structure = new TestHeightStructure() + Structure = new TestHeightStructure(), + ForeshoreProfile = CreateForeshoreProfile(new BreakWater(BreakWaterType.Dam, 10)), + UseBreakWater = true, + UseForeshore = true } }; + switch (calculationType) + { + case CalculationType.NoForeshore: + calculation.InputParameters.ForeshoreProfile = null; + calculation.InputParameters.UseForeshore = false; + calculation.InputParameters.UseBreakWater = false; + break; + case CalculationType.ForeshoreWithoutBreakWater: + calculation.InputParameters.ForeshoreProfile = CreateForeshoreProfile(null); + calculation.InputParameters.UseBreakWater = false; + break; + case CalculationType.ForeshoreWithValidBreakWater: + break; + } + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); // Call - Action call = () => new HeightStructuresCalculationService().Calculate(calculation, - assessmentSectionStub, - heightStructuresFailureMechanism, - validFilePath); + using (new HydraRingCalculatorFactoryConfig()) + { + Action call = () => new HeightStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + heightStructuresFailureMechanism, + validFilePath); - // Assert - TestHelper.AssertLogMessages(call, messages => + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Hoogte kunstwerk berekeningsverslag. Klik op details voor meer informatie.", msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.IsNotNull(calculation.Output); + } + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] + public void Calculate_ValidCalculationInputAndForeshoreWithInvalidBreakWater_LogStartAndEndAndReturnOutput(double height) + { + // Setup + var heightStructuresFailureMechanism = new HeightStructuresFailureMechanism(); + + var mockRepository = new MockRepository(); + var assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(heightStructuresFailureMechanism, mockRepository); + mockRepository.ReplayAll(); + + heightStructuresFailureMechanism.AddSection(new FailureMechanismSection("test section", new[] { - var msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith("Hoogte kunstwerk berekeningsverslag. Klik op details voor meer informatie.", msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); - }); - Assert.IsNotNull(calculation.Output); + new Point2D(0, 0), + new Point2D(1, 1) + })); + var calculation = new TestHeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + Structure = new TestHeightStructure(), + ForeshoreProfile = CreateForeshoreProfile(new BreakWater(BreakWaterType.Dam, height)), + UseBreakWater = false, + UseForeshore = true + } + }; + + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + // Call + using (new HydraRingCalculatorFactoryConfig()) + { + Action call = () => new HeightStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + heightStructuresFailureMechanism, + validFilePath); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Hoogte kunstwerk berekeningsverslag. Klik op details voor meer informatie.", msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.IsNotNull(calculation.Output); + } mockRepository.VerifyAll(); } @@ -568,7 +691,7 @@ heightStructuresFailureMechanism, testDataPath); } - catch(HydraRingFileParserException) + catch (HydraRingFileParserException) { exception = true; } @@ -699,7 +822,7 @@ { InputParameters = { - HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), Structure = new TestHeightStructure() } }; @@ -722,6 +845,25 @@ } } + public enum CalculationType + { + NoForeshore, + ForeshoreWithValidBreakWater, + ForeshoreWithoutBreakWater + } + + private static ForeshoreProfile CreateForeshoreProfile(BreakWater breakWater) + { + return new ForeshoreProfile(new Point2D(0, 0), + new[] + { + new Point2D(3.3, 4.4), + new Point2D(5.5, 6.6) + }, + breakWater, + new ForeshoreProfile.ConstructionProperties()); + } + #region Testcases private static IEnumerable NormalDistributionsWithInvalidMean