Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationReaderTest.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r928b72eb0fe0476d085e49e21ffd325b749a7db9 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationReaderTest.cs (.../HeightStructuresCalculationConfigurationReaderTest.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationReaderTest.cs (.../HeightStructuresCalculationConfigurationReaderTest.cs) (revision 928b72eb0fe0476d085e49e21ffd325b749a7db9) @@ -24,8 +24,11 @@ using NUnit.Framework; using Ringtoets.Common.IO.Readers; using System.IO; +using System.Linq; using System.Xml.Schema; using Core.Common.Base.IO; +using Ringtoets.Common.IO; +using Ringtoets.Common.IO.Configurations; namespace Ringtoets.HeightStructures.IO.Test { @@ -162,14 +165,14 @@ "The 'damgebruiken' element is invalid - The value 'string' is invalid according to its datatype 'Boolean'") .SetName("invalidUseBreakWaterNoBoolean"); yield return new TestCaseData("invalidMultipleUseBreakWaters.xml", - "The element 'golfreductie' has invalid child element 'damgebruiken'.") + "Element 'damgebruiken' cannot appear more than once if content model type is \"all\".") .SetName("invalidMultipleUseBreakWaters"); yield return new TestCaseData("invalidBreakWaterTypeEmpty.xml", "The 'damtype' element is invalid - The value '' is invalid according to its datatype 'String' - The Enumeration constraint failed.") .SetName("invalidBreakWaterTypeEmpty"); yield return new TestCaseData("invalidMultipleBreakWaterTypes.xml", - "The element 'golfreductie' has invalid child element 'damtype'.") + "Element 'damtype' cannot appear more than once if content model type is \"all\".") .SetName("invalidMultipleBreakWaterTypes"); yield return new TestCaseData("invalidBreakWaterTypeUnsupportedString.xml", "The 'damtype' element is invalid - The value 'invalid' is invalid according to its datatype 'String' - The Enumeration constraint failed.") @@ -185,7 +188,7 @@ "The 'damhoogte' element is invalid - The value '1,2' is invalid according to its datatype 'Double'") .SetName("invalidBreakWaterHeightWrongCulture"); yield return new TestCaseData("invalidMultipleBreakWaterHeights.xml", - "The element 'golfreductie' has invalid child element 'damhoogte'.") + "Element 'damhoogte' cannot appear more than once if content model type is \"all\".") .SetName("invalidMultipleBreakWaterHeights"); yield return new TestCaseData("invalidUseForeshoreEmpty.xml", @@ -195,7 +198,7 @@ "The 'voorlandgebruiken' element is invalid - The value 'string' is invalid according to its datatype 'Boolean'") .SetName("invalidUseForeshoreNoBoolean"); yield return new TestCaseData("invalidMultipleUseForeshore.xml", - "The element 'golfreductie' has invalid child element 'voorlandgebruiken'.") + "Element 'voorlandgebruiken' cannot appear more than once if content model type is \"all\".") .SetName("invalidMultipleUseForeshores"); } } @@ -228,5 +231,254 @@ Assert.IsInstanceOf(exception.InnerException); StringAssert.Contains(expectedParsingMessage, exception.InnerException?.Message); } + + [Test] + [TestCase("validConfigurationEmptyStochasts")] + [TestCase("validConfigurationEmptyCalculation")] + public void Read_ValidConfigurationWithEmptyCalculationOrWithEmptyStochasts_NoValuesSet(string fileName) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, $"{fileName}.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNull(calculation.StructureNormalOrientation); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsNull(calculation.FailureProbabilityStructureWithErosion); + + Assert.IsNull(calculation.LevelCrestStructure); + Assert.IsNull(calculation.AllowedLevelIncreaseStorage); + Assert.IsNull(calculation.CriticalOvertoppingDischarge); + Assert.IsNull(calculation.FlowWidthAtBottomProtection); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow); + Assert.IsNull(calculation.StorageStructureArea); + Assert.IsNull(calculation.StormDuration); + Assert.IsNull(calculation.WidthFlowApertures); + + Assert.IsNull(calculation.WaveReduction); + } + + [Test] + [TestCase("validFullConfiguration")] + [TestCase("validFullConfiguration_differentOrder")] + public void Read_ValidFullConfigurations_ExpectedValues(string fileName) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, $"{fileName}.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.AreEqual(67.1, calculation.StructureNormalOrientation); + Assert.AreEqual("kunstwerk1", calculation.StructureName); + Assert.AreEqual("Locatie1", calculation.HydraulicBoundaryLocationName); + Assert.AreEqual("profiel1", calculation.ForeshoreProfileName); + Assert.AreEqual(1e-6, calculation.FailureProbabilityStructureWithErosion); + + Assert.AreEqual(4.3, calculation.LevelCrestStructure.Mean); + Assert.AreEqual(0.1, calculation.LevelCrestStructure.StandardDeviation); + + Assert.AreEqual(0.2, calculation.AllowedLevelIncreaseStorage.Mean); + Assert.AreEqual(0.01, calculation.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.AreEqual(2, calculation.CriticalOvertoppingDischarge.Mean); + Assert.AreEqual(0.1, calculation.CriticalOvertoppingDischarge.VariationCoefficient); + Assert.AreEqual(15.2, calculation.FlowWidthAtBottomProtection.Mean); + Assert.AreEqual(0.1, calculation.FlowWidthAtBottomProtection.StandardDeviation); + Assert.AreEqual(1.10, calculation.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.AreEqual(15000, calculation.StorageStructureArea.Mean); + Assert.AreEqual(0.01, calculation.StorageStructureArea.VariationCoefficient); + Assert.AreEqual(6.0, calculation.StormDuration.Mean); + Assert.IsNull(calculation.StormDuration.VariationCoefficient); + Assert.AreEqual(15.2, calculation.WidthFlowApertures.Mean); + Assert.AreEqual(0.1, calculation.WidthFlowApertures.StandardDeviation); + + Assert.AreEqual(ReadBreakWaterType.Dam, calculation.WaveReduction.BreakWaterType); + Assert.AreEqual(1.234, calculation.WaveReduction.BreakWaterHeight); + Assert.IsTrue(calculation.WaveReduction.UseBreakWater); + Assert.IsTrue(calculation.WaveReduction.UseForeshoreProfile); + } + + [Test] + public void Read_ValidFullConfigurationsContainingInfinity_ExpectedValues() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validFullConfigurationContainingInfinity.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsTrue(double.IsNegativeInfinity(calculation.StructureNormalOrientation.Value)); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsTrue(double.IsNegativeInfinity(calculation.FailureProbabilityStructureWithErosion.Value)); + + Assert.IsTrue(double.IsNegativeInfinity(calculation.LevelCrestStructure.Mean.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.LevelCrestStructure.StandardDeviation.Value)); + + Assert.IsTrue(double.IsPositiveInfinity(calculation.AllowedLevelIncreaseStorage.Mean.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.AllowedLevelIncreaseStorage.StandardDeviation.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.CriticalOvertoppingDischarge.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.CriticalOvertoppingDischarge.VariationCoefficient.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.FlowWidthAtBottomProtection.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.FlowWidthAtBottomProtection.StandardDeviation.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.ModelFactorSuperCriticalFlow.Mean.Value)); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.IsTrue(double.IsPositiveInfinity(calculation.StorageStructureArea.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.StorageStructureArea.VariationCoefficient.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.StormDuration.Mean.Value)); + Assert.IsNull(calculation.StormDuration.VariationCoefficient); + Assert.IsTrue(double.IsPositiveInfinity(calculation.WidthFlowApertures.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.WidthFlowApertures.StandardDeviation.Value)); + + Assert.IsNull(calculation.WaveReduction.BreakWaterType); + Assert.IsTrue(double.IsNegativeInfinity(calculation.WaveReduction.BreakWaterHeight.Value)); + Assert.IsNull(calculation.WaveReduction.UseBreakWater); + Assert.IsNull(calculation.WaveReduction.UseForeshoreProfile); + } + + [Test] + public void Read_ValidFullConfigurationsContainingNaN_ExpectedValues() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validFullConfigurationContainingNaN.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNaN(calculation.StructureNormalOrientation); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsNaN(calculation.FailureProbabilityStructureWithErosion); + + Assert.IsNaN(calculation.LevelCrestStructure.Mean); + Assert.IsNaN(calculation.LevelCrestStructure.StandardDeviation); + + Assert.IsNaN(calculation.AllowedLevelIncreaseStorage.Mean); + Assert.IsNaN(calculation.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNaN(calculation.CriticalOvertoppingDischarge.Mean); + Assert.IsNaN(calculation.CriticalOvertoppingDischarge.VariationCoefficient); + Assert.IsNaN(calculation.FlowWidthAtBottomProtection.Mean); + Assert.IsNaN(calculation.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNaN(calculation.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.IsNaN(calculation.StorageStructureArea.Mean); + Assert.IsNaN(calculation.StorageStructureArea.VariationCoefficient); + Assert.IsNaN(calculation.StormDuration.Mean); + Assert.IsNull(calculation.StormDuration.VariationCoefficient); + Assert.IsNaN(calculation.WidthFlowApertures.Mean); + Assert.IsNaN(calculation.WidthFlowApertures.StandardDeviation); + + Assert.IsNull(calculation.WaveReduction.BreakWaterType); + Assert.IsNaN(calculation.WaveReduction.BreakWaterHeight); + Assert.IsNull(calculation.WaveReduction.UseBreakWater); + Assert.IsNull(calculation.WaveReduction.UseForeshoreProfile); + } + + [Test] + public void Read_ValidPartialConfigurations_ExpectedValues() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validPartialConfiguration.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNull(calculation.StructureNormalOrientation); + Assert.IsNull(calculation.StructureName); + Assert.AreEqual("Locatie1", calculation.HydraulicBoundaryLocationName); + Assert.AreEqual("profiel1", calculation.ForeshoreProfileName); + Assert.IsNull(calculation.FailureProbabilityStructureWithErosion); + + Assert.IsNull(calculation.LevelCrestStructure); + + Assert.IsNull(calculation.AllowedLevelIncreaseStorage); + Assert.AreEqual(2, calculation.CriticalOvertoppingDischarge.Mean); + Assert.AreEqual(0.1, calculation.CriticalOvertoppingDischarge.VariationCoefficient); + Assert.IsNull(calculation.FlowWidthAtBottomProtection); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow); + Assert.AreEqual(15000, calculation.StorageStructureArea.Mean); + Assert.IsNull(calculation.StorageStructureArea.VariationCoefficient); + Assert.AreEqual(6.0, calculation.StormDuration.Mean); + Assert.IsNull(calculation.StormDuration.VariationCoefficient); + Assert.IsNull(calculation.WidthFlowApertures.Mean); + Assert.AreEqual(0.1, calculation.WidthFlowApertures.StandardDeviation); + + Assert.IsNull(calculation.WaveReduction.BreakWaterType); + Assert.IsNull(calculation.WaveReduction.BreakWaterHeight); + Assert.IsTrue(calculation.WaveReduction.UseBreakWater); + Assert.IsTrue(calculation.WaveReduction.UseForeshoreProfile); + } + + [Test] + public void Read_ValidConfigurationsEmptyStochastElements_ExpectedValues() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfigurationEmptyStochastElements.xml"); + var reader = new HeightStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (HeightStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNull(calculation.StructureNormalOrientation); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsNull(calculation.FailureProbabilityStructureWithErosion); + + Assert.IsNull(calculation.LevelCrestStructure.Mean); + Assert.IsNull(calculation.LevelCrestStructure.StandardDeviation); + + Assert.IsNull(calculation.AllowedLevelIncreaseStorage.Mean); + Assert.IsNull(calculation.AllowedLevelIncreaseStorage.StandardDeviation); + Assert.IsNull(calculation.CriticalOvertoppingDischarge.Mean); + Assert.IsNull(calculation.CriticalOvertoppingDischarge.VariationCoefficient); + Assert.IsNull(calculation.FlowWidthAtBottomProtection.Mean); + Assert.IsNull(calculation.FlowWidthAtBottomProtection.StandardDeviation); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow.Mean); + Assert.IsNull(calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.IsNull(calculation.StorageStructureArea.Mean); + Assert.IsNull(calculation.StorageStructureArea.VariationCoefficient); + Assert.IsNull(calculation.StormDuration.Mean); + Assert.IsNull(calculation.StormDuration.VariationCoefficient); + Assert.IsNull(calculation.WidthFlowApertures.Mean); + Assert.IsNull(calculation.WidthFlowApertures.StandardDeviation); + + Assert.IsNull(calculation.WaveReduction); + } } } \ No newline at end of file