Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfiguration.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresConfigurationSchemaIdentifiers.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ConfigurationClosingStructureInflowModelType.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ConfigurationClosingStructureInflowModelTypeConverter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfiguration.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfiguration.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfiguration.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,94 @@ +// 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; +using Ringtoets.Common.IO.Configurations; + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Configuration of a closing structure calculation. + /// + public class ClosingStructuresCalculationConfiguration : StructuresCalculationConfiguration + { + /// + /// Creates a new instance of . + /// + /// The name of the . + /// Thrown when is null. + public ClosingStructuresCalculationConfiguration(string name) : base(name) {} + + /// + /// Gets or sets the stochast configuration for the inside water level for the structure. + /// + public MeanStandardDeviationStochastConfiguration InsideWaterLevel { get; set; } + + /// + /// Gets or sets the stochast configuration for the drain coefficient for the structure. + /// + public MeanStandardDeviationStochastConfiguration DrainCoefficient { get; set; } + + /// + /// Gets or sets the stochast configuration for the threshold height open weir for the structure. + /// + public MeanStandardDeviationStochastConfiguration ThresholdHeightOpenWeir { get; set; } + + /// + /// Gets or sets the stochast configuration for the area flow of apertures for the structure. + /// + public MeanStandardDeviationStochastConfiguration AreaFlowApertures { get; set; } + + /// + /// Gets or sets the stochast configuration for the level crest of structure not closing. + /// + public MeanStandardDeviationStochastConfiguration LevelCrestStructureNotClosing { get; set; } + + /// + /// Gets or sets the number of identical apertures. + /// + public int? IdenticalApertures { get; set; } + + /// + /// Gets or sets the factor of storm duration for an open structure. + /// + public double? FactorStormDurationOpenStructure { get; set; } + + /// + /// Gets or sets the failure probability of an open structure. + /// + public double? FailureProbabilityOpenStructure { get; set; } + + /// + /// Gets or sets the failure probability of reparation. + /// + public double? FailureProbabilityReparation { get; set; } + + /// + /// Gets or sets the probability or frequency for an open structure before flooding. + /// + public double? ProbabilityOrFrequencyOpenStructureBeforeFlooding { get; set; } + + /// + /// Gets or sets the inflow model type. + /// + public ConfigurationClosingStructureInflowModelType? InflowModelType { get; set; } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,110 @@ +// 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; +using System.Collections.Generic; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.IO.Configurations.Helpers; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; +using Ringtoets.Common.IO.Exporters; + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Exports a closing structures calculation configuration and stores it as an XML file. + /// + public class ClosingStructuresCalculationConfigurationExporter : SchemaCalculationConfigurationExporter< + ClosingStructuresCalculationConfigurationWriter, + StructuresCalculation, + ClosingStructuresCalculationConfiguration> + { + /// + /// Creates a new instance of . + /// + /// The calculation configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public ClosingStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} + + protected override ClosingStructuresCalculationConfiguration ToConfiguration(StructuresCalculation calculation) + { + ClosingStructuresInput input = calculation.InputParameters; + var calculationConfiguration = new ClosingStructuresCalculationConfiguration(calculation.Name) + { + HydraulicBoundaryLocationName = input.HydraulicBoundaryLocation?.Name + }; + + + if (input.Structure != null) + { + calculationConfiguration.StructureName = input.Structure.Name; + calculationConfiguration.StructureNormalOrientation = input.StructureNormalOrientation; + + calculationConfiguration.InflowModelType = (ConfigurationClosingStructureInflowModelType?) new ConfigurationClosingStructureInflowModelTypeConverter().ConvertFrom(input.InflowModelType); + calculationConfiguration.IdenticalApertures = input.IdenticalApertures; + calculationConfiguration.FailureProbabilityOpenStructure = input.FailureProbabilityOpenStructure; + calculationConfiguration.FailureProbabilityReparation = input.FailureProbabilityReparation; + calculationConfiguration.ProbabilityOrFrequencyOpenStructureBeforeFlooding = input.ProbabilityOrFrequencyOpenStructureBeforeFlooding; + + calculationConfiguration.FlowWidthAtBottomProtection = input.FlowWidthAtBottomProtection.ToStochastConfiguration(); + calculationConfiguration.WidthFlowApertures = input.WidthFlowApertures.ToStochastConfiguration(); + calculationConfiguration.StorageStructureArea = input.StorageStructureArea.ToStochastConfiguration(); + calculationConfiguration.AllowedLevelIncreaseStorage = input.AllowedLevelIncreaseStorage.ToStochastConfiguration(); + calculationConfiguration.CriticalOvertoppingDischarge = input.CriticalOvertoppingDischarge.ToStochastConfiguration(); + + calculationConfiguration.AreaFlowApertures = input.AreaFlowApertures.ToStochastConfiguration(); + calculationConfiguration.InsideWaterLevel = input.InsideWaterLevel.ToStochastConfiguration(); + calculationConfiguration.LevelCrestStructureNotClosing = input.LevelCrestStructureNotClosing.ToStochastConfiguration(); + calculationConfiguration.ThresholdHeightOpenWeir = input.ThresholdHeightOpenWeir.ToStochastConfiguration(); + } + + if (input.ForeshoreProfile != null) + { + calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; + calculationConfiguration.WaveReduction = new WaveReductionConfiguration + { + UseForeshoreProfile = input.UseForeshore, + UseBreakWater = input.UseBreakWater, + BreakWaterType = (ConfigurationBreakWaterType?) new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type), + BreakWaterHeight = input.BreakWater.Height + }; + } + + calculationConfiguration.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; + calculationConfiguration.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure; + + calculationConfiguration.StormDuration = input.StormDuration.ToStochastConfigurationWithMean(); + calculationConfiguration.DrainCoefficient = input.DrainCoefficient.ToStochastConfigurationWithMean(); + calculationConfiguration.ModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow.ToStochastConfigurationWithMean(); + + return calculationConfiguration; + } + + protected override ClosingStructuresCalculationConfigurationWriter CreateWriter(string filePath) + { + return new ClosingStructuresCalculationConfigurationWriter(filePath); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationReader.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationReader.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationReader.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,174 @@ +// 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; +using System.Collections.Generic; +using System.Xml.Linq; +using Core.Common.Base.IO; +using Ringtoets.ClosingStructures.IO.Configurations.Helpers; +using Ringtoets.ClosingStructures.IO.Properties; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; +using Ringtoets.Common.IO.Readers; +using Ringtoets.Common.IO.Schema; +using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Reader for reading a closing structure calculation configuration from XML and creating a collection + /// of corresponding . + /// + public class ClosingStructuresCalculationConfigurationReader : CalculationConfigurationReader + { + private const string hrLocatieSchemaName = "HrLocatieSchema.xsd"; + private const string orientatieSchemaName = "OrientatieSchema.xsd"; + private const string golfReductieSchemaName = "GolfReductieSchema.xsd"; + private const string voorlandProfielSchemaName = "VoorlandProfielSchema.xsd"; + private const string stochastSchemaName = "StochastSchema.xsd"; + private const string stochastStandaardafwijkingSchemaName = "StochastStandaardafwijkingSchema.xsd"; + private const string stochastVariatiecoefficientSchemaName = "StochastVariatiecoefficientSchema.xsd"; + private const string structureBaseSchemaName = "KunstwerkenBasisSchema.xsd"; + + /// + /// Creates a new instance of . + /// + /// The file path to the XML file. + /// Thrown when is invalid. + /// Thrown when: + /// + /// points to a file that does not exist. + /// points to a file that does not contain valid XML. + /// points to a file that does not pass the schema validation. + /// points to a file that does not contain configuration elements. + /// + /// + public ClosingStructuresCalculationConfigurationReader(string filePath) + : base(filePath, + Resources.KunstwerkenBetrouwbaarheidSluitenSchema, + new Dictionary + { + { + hrLocatieSchemaName, RingtoetsCommonIOResources.HrLocatieSchema + }, + { + orientatieSchemaName, RingtoetsCommonIOResources.OrientatieSchema + }, + { + voorlandProfielSchemaName, RingtoetsCommonIOResources.VoorlandProfielSchema + }, + { + golfReductieSchemaName, RingtoetsCommonIOResources.GolfReductieSchema + }, + { + stochastSchemaName, RingtoetsCommonIOResources.StochastSchema + }, + { + stochastStandaardafwijkingSchemaName, RingtoetsCommonIOResources.StochastStandaardafwijkingSchema + }, + { + stochastVariatiecoefficientSchemaName, RingtoetsCommonIOResources.StochastVariatiecoefficientSchema + }, + { + structureBaseSchemaName, RingtoetsCommonIOResources.KunstwerkenBasisSchema + } + }) {} + + protected override ClosingStructuresCalculationConfiguration ParseCalculationElement(XElement calculationElement) + { + var configuration = new ClosingStructuresCalculationConfiguration(calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute).Value) + { + FailureProbabilityStructureWithErosion = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement), + StructureNormalOrientation = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.Orientation), + InflowModelType = (ConfigurationClosingStructureInflowModelType?) + calculationElement.GetConvertedValueFromDescendantStringElement( + ClosingStructuresConfigurationSchemaIdentifiers.InflowModelType), + FactorStormDurationOpenStructure = calculationElement.GetDoubleValueFromDescendantElement(ClosingStructuresConfigurationSchemaIdentifiers.FactorStormDurationOpenStructure), + FailureProbabilityOpenStructure = calculationElement.GetDoubleValueFromDescendantElement(ClosingStructuresConfigurationSchemaIdentifiers.FailureProbabilityOpenStructure), + FailureProbabilityReparation = calculationElement.GetDoubleValueFromDescendantElement(ClosingStructuresConfigurationSchemaIdentifiers.FailureProbabilityReparation), + ProbabilityOrFrequencyOpenStructureBeforeFlooding = calculationElement.GetDoubleValueFromDescendantElement(ClosingStructuresConfigurationSchemaIdentifiers.ProbabilityOrFrequencyOpenStructureBeforeFlooding), + IdenticalApertures = calculationElement.GetIntegerValueFromDescendantElement(ClosingStructuresConfigurationSchemaIdentifiers.IdenticalApertures), + ForeshoreProfileName = calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement), + HydraulicBoundaryLocationName = calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement), + StructureName = calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.StructureElement), + WaveReduction = GetWaveReductionParameters(calculationElement), + AreaFlowApertures = GetStandardDeviationStochastParameters(calculationElement, ClosingStructuresConfigurationSchemaIdentifiers.AreaFlowAperturesStochastName), + DrainCoefficient = GetStandardDeviationStochastParameters(calculationElement, ClosingStructuresConfigurationSchemaIdentifiers.DrainCoefficientStochastName), + InsideWaterLevel = GetStandardDeviationStochastParameters(calculationElement, ClosingStructuresConfigurationSchemaIdentifiers.InsideWaterLevelStochastName), + LevelCrestStructureNotClosing = GetStandardDeviationStochastParameters(calculationElement, ClosingStructuresConfigurationSchemaIdentifiers.LevelCrestStructureNotClosingStochastName), + ThresholdHeightOpenWeir = GetStandardDeviationStochastParameters(calculationElement, ClosingStructuresConfigurationSchemaIdentifiers.ThresholdHeightOpenWeirStochastName), + AllowedLevelIncreaseStorage = GetStandardDeviationStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName), + FlowWidthAtBottomProtection = GetStandardDeviationStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName), + ModelFactorSuperCriticalFlow = GetStandardDeviationStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName), + WidthFlowApertures = GetStandardDeviationStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName), + CriticalOvertoppingDischarge = GetVariationCoefficientStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName), + StorageStructureArea = GetVariationCoefficientStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName), + StormDuration = GetVariationCoefficientStochastParameters(calculationElement, ConfigurationSchemaIdentifiers.StormDurationStochastName) + }; + + return configuration; + } + + private static WaveReductionConfiguration GetWaveReductionParameters(XElement calculationElement) + { + XElement waveReduction = calculationElement.GetDescendantElement(ConfigurationSchemaIdentifiers.WaveReduction); + if (waveReduction != null) + { + return new WaveReductionConfiguration + { + BreakWaterType = (ConfigurationBreakWaterType?) calculationElement.GetConvertedValueFromDescendantStringElement(ConfigurationSchemaIdentifiers.BreakWaterType), + BreakWaterHeight = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.BreakWaterHeight), + UseBreakWater = calculationElement.GetBoolValueFromDescendantElement(ConfigurationSchemaIdentifiers.UseBreakWater), + UseForeshoreProfile = calculationElement.GetBoolValueFromDescendantElement(ConfigurationSchemaIdentifiers.UseForeshore) + }; + } + return null; + } + + private static MeanVariationCoefficientStochastConfiguration GetVariationCoefficientStochastParameters(XElement calculationElement, string stochastName) + { + XElement element = calculationElement.GetStochastElement(stochastName); + if (element != null) + { + return new MeanVariationCoefficientStochastConfiguration + { + Mean = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.MeanElement), + VariationCoefficient = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.VariationCoefficientElement) + }; + } + return null; + } + + private static MeanStandardDeviationStochastConfiguration GetStandardDeviationStochastParameters(XElement calculationElement, string stochastName) + { + XElement element = calculationElement.GetStochastElement(stochastName); + if (element != null) + { + return new MeanStandardDeviationStochastConfiguration + { + Mean = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.MeanElement), + StandardDeviation = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.StandardDeviationElement) + }; + } + return null; + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationWriter.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,94 @@ +// 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; +using System.Xml; +using Ringtoets.ClosingStructures.IO.Configurations.Helpers; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Writer for writing in XML format to file. + /// + public class ClosingStructuresCalculationConfigurationWriter : StructureCalculationConfigurationWriter + { + /// + /// Creates a new instance of . + /// + /// The path of the file to write to. + /// Thrown when is invalid. + /// A valid path: + /// + /// is not empty or null, + /// does not consist out of only whitespace characters, + /// does not contain an invalid character, + /// does not end with a directory or path separator (empty file name). + /// + public ClosingStructuresCalculationConfigurationWriter(string filePath) + : base(filePath) {} + + protected override void WriteSpecificStructureParameters(ClosingStructuresCalculationConfiguration configuration, XmlWriter writer) + { + if (configuration.InflowModelType != null) + { + writer.WriteElementString( + ClosingStructuresConfigurationSchemaIdentifiers.InflowModelType, + new ConfigurationClosingStructureInflowModelTypeConverter().ConvertToInvariantString(configuration.InflowModelType)); + } + + WriteElementWhenContentAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.FactorStormDurationOpenStructure, + configuration.FactorStormDurationOpenStructure); + WriteElementWhenContentAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.IdenticalApertures, + configuration.IdenticalApertures); + WriteElementWhenContentAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.ProbabilityOrFrequencyOpenStructureBeforeFlooding, + configuration.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + WriteElementWhenContentAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.FailureProbabilityOpenStructure, + configuration.FailureProbabilityOpenStructure); + WriteElementWhenContentAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.FailureProbabilityReparation, + configuration.FailureProbabilityReparation); + } + + protected override void WriteSpecificStochasts(ClosingStructuresCalculationConfiguration configuration, XmlWriter writer) + { + WriteDistributionWhenAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.DrainCoefficientStochastName, + configuration.DrainCoefficient); + WriteDistributionWhenAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.InsideWaterLevelStochastName, + configuration.InsideWaterLevel); + WriteDistributionWhenAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.AreaFlowAperturesStochastName, + configuration.AreaFlowApertures); + WriteDistributionWhenAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.ThresholdHeightOpenWeirStochastName, + configuration.ThresholdHeightOpenWeir); + WriteDistributionWhenAvailable(writer, + ClosingStructuresConfigurationSchemaIdentifiers.LevelCrestStructureNotClosingStochastName, + configuration.LevelCrestStructureNotClosing); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresConfigurationSchemaIdentifiers.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresConfigurationSchemaIdentifiers.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresConfigurationSchemaIdentifiers.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,111 @@ +// 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. + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Container of identifiers related to closing structure calculation configuration schema definitions. + /// + public static class ClosingStructuresConfigurationSchemaIdentifiers + { + #region parameters + + /// + /// The identifier for the identical apertures element. + /// + public const string IdenticalApertures = "nrdoorstroomopeningen"; + + /// + /// The identifier for the factor storm duration open structure element. + /// + public const string FactorStormDurationOpenStructure = "factorstormduur"; + + /// + /// The identifier for the failure probability open structure element. + /// + public const string FailureProbabilityOpenStructure = "kansmislukkensluiting"; + + /// + /// The identifier for the failure probability reparation element. + /// + public const string FailureProbabilityReparation = "faalkansherstel"; + + /// + /// The identifier for the probability or frequency open structure before flooding element. + /// + public const string ProbabilityOrFrequencyOpenStructureBeforeFlooding = "kansopopenstaan"; + + /// + /// The identifier for the inflow model type element. + /// + public const string InflowModelType = "instroommodel"; + + #endregion + + #region stochasts + + /// + /// The identifier for the level crest structure not closing stochast name. + /// + public const string LevelCrestStructureNotClosingStochastName = "kruinhoogte"; + + /// + /// The identifier for the inside water level stochast name. + /// + public const string InsideWaterLevelStochastName = "binnenwaterstand"; + + /// + /// The identifier for the drain coefficient stochast name. + /// + public const string DrainCoefficientStochastName = "afvoercoefficient"; + + /// + /// The identifier for the threshold height open weir stochast name. + /// + public const string ThresholdHeightOpenWeirStochastName = "drempelhoogte"; + + /// + /// The identifier for the area flow apertures stochast name. + /// + public const string AreaFlowAperturesStochastName = "doorstroomoppervlak"; + + #endregion + + #region inflow model type + + /// + /// The identifier for the flooded culvert inflow model type. + /// + public const string FloodedCulvert = "verdronkenkoker"; + + /// + /// The identifier for the low will inflow model type. + /// + public const string LowSill = "lagedrempel"; + + /// + /// The identifier for the vertical wall inflow model type. + /// + public const string VerticalWall = "verticalewand"; + + #endregion + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ConfigurationClosingStructureInflowModelType.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ConfigurationClosingStructureInflowModelType.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ConfigurationClosingStructureInflowModelType.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,44 @@ +// 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. + +namespace Ringtoets.ClosingStructures.IO.Configurations +{ + /// + /// Defines the types of the various inflow models. + /// + public enum ConfigurationClosingStructureInflowModelType + { + /// + /// A vertical wall. + /// + VerticalWall = 1, + + /// + /// A low sill structure. + /// + LowSill = 2, + + /// + /// A flooded culvert structure. + /// + FloodedCulvert = 3 + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverter.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverter.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverter.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,123 @@ +// 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; +using System.ComponentModel; +using System.Globalization; +using Ringtoets.ClosingStructures.Data; + +namespace Ringtoets.ClosingStructures.IO.Configurations.Helpers +{ + /// + /// Converts to + /// or and back. + /// + public class ConfigurationClosingStructureInflowModelTypeConverter : TypeConverter + { + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + if (destinationType == typeof(ClosingStructureInflowModelType)) + { + return true; + } + return base.CanConvertTo(context, destinationType); + } + + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string)) + { + var type = (ConfigurationClosingStructureInflowModelType)value; + switch (type) + { + case ConfigurationClosingStructureInflowModelType.FloodedCulvert: + return ClosingStructuresConfigurationSchemaIdentifiers.FloodedCulvert; + case ConfigurationClosingStructureInflowModelType.LowSill: + return ClosingStructuresConfigurationSchemaIdentifiers.LowSill; + case ConfigurationClosingStructureInflowModelType.VerticalWall: + return ClosingStructuresConfigurationSchemaIdentifiers.VerticalWall; + default: + throw new NotSupportedException(); + } + } + if (destinationType == typeof(ClosingStructureInflowModelType)) + { + var type = (ConfigurationClosingStructureInflowModelType)value; + switch (type) + { + case ConfigurationClosingStructureInflowModelType.FloodedCulvert: + return ClosingStructureInflowModelType.FloodedCulvert; + case ConfigurationClosingStructureInflowModelType.LowSill: + return ClosingStructureInflowModelType.LowSill; + case ConfigurationClosingStructureInflowModelType.VerticalWall: + return ClosingStructureInflowModelType.VerticalWall; + default: + throw new NotSupportedException(); + } + } + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + if (sourceType == typeof(string)) + { + return true; + } + if (sourceType == typeof(ClosingStructureInflowModelType)) + { + return true; + } + return base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + var text = value as string; + if (text != null) + { + switch (text) + { + case ClosingStructuresConfigurationSchemaIdentifiers.FloodedCulvert: + return ConfigurationClosingStructureInflowModelType.FloodedCulvert; + case ClosingStructuresConfigurationSchemaIdentifiers.LowSill: + return ConfigurationClosingStructureInflowModelType.LowSill; + case ClosingStructuresConfigurationSchemaIdentifiers.VerticalWall: + return ConfigurationClosingStructureInflowModelType.VerticalWall; + } + } + var breakWaterType = value as ClosingStructureInflowModelType?; + if (breakWaterType != null) + { + switch (breakWaterType) + { + case ClosingStructureInflowModelType.FloodedCulvert: + return ConfigurationClosingStructureInflowModelType.FloodedCulvert; + case ClosingStructureInflowModelType.LowSill: + return ConfigurationClosingStructureInflowModelType.LowSill; + case ClosingStructureInflowModelType.VerticalWall: + return ConfigurationClosingStructureInflowModelType.VerticalWall; + } + } + return base.ConvertFrom(context, culture, value); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj =================================================================== diff -u -r04a0742040ae09f8839510470014d2b273e67a78 -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj (.../Ringtoets.ClosingStructures.IO.csproj) (revision 04a0742040ae09f8839510470014d2b273e67a78) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Ringtoets.ClosingStructures.IO.csproj (.../Ringtoets.ClosingStructures.IO.csproj) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -45,14 +45,14 @@ Properties\GlobalAssembly.cs - + - - - - - - + + + + + + True Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -rf690272ef922b7cefaac34021bceca21947004c0 -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision f690272ef922b7cefaac34021bceca21947004c0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -35,6 +35,7 @@ using Ringtoets.ClosingStructures.Forms.PropertyClasses; using Ringtoets.ClosingStructures.Forms.Views; using Ringtoets.ClosingStructures.IO; +using Ringtoets.ClosingStructures.IO.Configurations; using Ringtoets.ClosingStructures.Service; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ClosingStructuresCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 16c94d05c67237dec9fcab0f3f03c6b48d3c335b refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/ConfigurationClosingStructureInflowModelTypeConverterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationExporterTest.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,263 @@ +// 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.IO; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.ClosingStructures.IO.Configurations; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.TestUtil; + +namespace Ringtoets.ClosingStructures.IO.Test.Configurations +{ + [TestFixture] + public class ClosingStructuresCalculationConfigurationExporterTest + : CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture< + ClosingStructuresCalculationConfigurationExporter, + ClosingStructuresCalculationConfigurationWriter, + StructuresCalculation, + ClosingStructuresCalculationConfiguration> + { + private static IEnumerable Calculations + { + get + { + yield return new TestCaseData("completeConfiguration", new[] + { + CreateFullCalculation() + }) + .SetName("Calculation configuration with all parameters set"); + yield return new TestCaseData("sparseConfiguration", new[] + { + CreateSparseCalculation() + }) + .SetName("Calculation configuration with none of its parameters set"); + yield return new TestCaseData("configurationWithStructure", new[] + { + CreateCalculationWithStructure() + }) + .SetName("Calculation configuration with a structure set"); + yield return new TestCaseData("configurationWithForeshoreProfile", new[] + { + CreateCalculationWithForeshoreProfile() + }) + .SetName("Calculation configuration with foreshore profile"); + yield return new TestCaseData("configurationWithUseBreakWater", new[] + { + CreateCalculationWithUseBreakWater() + }) + .SetName("Calculation configuration with use breakwater true"); + yield return new TestCaseData("folderWithSubfolderAndCalculation", new[] + { + new CalculationGroup("Testmap", false) + { + Children = + { + CreateFullCalculation(), + new CalculationGroup("Nested", false) + { + Children = + { + CreateSparseCalculation() + } + } + } + } + }) + .SetName("Calculation configuration with hierarchy"); + } + } + + [Test] + [TestCaseSource(nameof(Calculations))] + public void Export_ValidData_ReturnTrueAndWritesFile(string fileName, ICalculationBase[] calculations) + { + // Setup + string testDirectory = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.ClosingStructures.IO, + nameof(ClosingStructuresCalculationConfigurationExporter)); + + string expectedXmlFilePath = Path.Combine(testDirectory, $"{fileName}.xml"); + + // Call and Assert + WriteAndValidate(calculations, expectedXmlFilePath); + } + + private static ICalculation CreateSparseCalculation() + { + return new StructuresCalculation + { + Name = "sparse config" + }; + } + + private static StructuresCalculation CreateFullCalculation() + { + return new TestClosingStructuresCalculation + { + Name = "full config", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"), + Structure = new TestClosingStructure("kunstwerk1"), + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + FailureProbabilityStructureWithErosion = 1e-4, + StructureNormalOrientation = (RoundedDouble) 67.1, + FactorStormDurationOpenStructure = (RoundedDouble) 1.0, + IdenticalApertures = 1, + ProbabilityOrFrequencyOpenStructureBeforeFlooding = 1e-2, + FailureProbabilityOpenStructure = 1e-3, + FailureProbabilityReparation = 1e-2, + InflowModelType = ClosingStructureInflowModelType.LowSill, + UseBreakWater = true, + UseForeshore = true, + BreakWater = + { + Type = BreakWaterType.Dam, + Height = (RoundedDouble) 1.234 + }, + StormDuration = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 6.0, + CoefficientOfVariation = (RoundedDouble) 0.22 + }, + ModelFactorSuperCriticalFlow = new NormalDistribution + { + Mean = (RoundedDouble) 1.10, + StandardDeviation = (RoundedDouble) 0.14 + }, + FlowWidthAtBottomProtection = new LogNormalDistribution + { + Mean = (RoundedDouble) 15.2, + StandardDeviation = (RoundedDouble) 0.1 + }, + WidthFlowApertures = new NormalDistribution + { + Mean = (RoundedDouble) 13.2, + StandardDeviation = (RoundedDouble) 0.3 + }, + StorageStructureArea = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 15000, + CoefficientOfVariation = (RoundedDouble) 0.01 + }, + AllowedLevelIncreaseStorage = new LogNormalDistribution + { + Mean = (RoundedDouble) 0.2, + StandardDeviation = (RoundedDouble) 0.01 + }, + CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 2, + CoefficientOfVariation = (RoundedDouble) 0.1 + }, + DrainCoefficient = new NormalDistribution + { + Mean = (RoundedDouble) 1.1, + StandardDeviation = (RoundedDouble) 0.02 + }, + InsideWaterLevel = new NormalDistribution + { + Mean = (RoundedDouble) 0.5, + StandardDeviation = (RoundedDouble) 0.1 + }, + AreaFlowApertures = new LogNormalDistribution + { + Mean = (RoundedDouble) 80.5, + StandardDeviation = (RoundedDouble) 1 + }, + ThresholdHeightOpenWeir = new NormalDistribution + { + Mean = (RoundedDouble) 1.2, + StandardDeviation = (RoundedDouble) 0.1 + }, + LevelCrestStructureNotClosing = new NormalDistribution + { + Mean = (RoundedDouble) 4.3, + StandardDeviation = (RoundedDouble) 0.2 + } + } + }; + } + + private static StructuresCalculation CreateCalculationWithForeshoreProfile() + { + return new StructuresCalculation + { + Name = "with foreshore profile", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + UseForeshore = true + } + }; + } + + private static StructuresCalculation CreateCalculationWithUseBreakWater() + { + return new StructuresCalculation + { + Name = "with use breakwater", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + BreakWater = + { + Type = BreakWaterType.Caisson, + Height = (RoundedDouble) 1.23 + }, + UseBreakWater = true, + UseForeshore = false + } + }; + } + + private static StructuresCalculation CreateCalculationWithStructure() + { + return new StructuresCalculation + { + Name = "with structure", + InputParameters = + { + Structure = new TestClosingStructure("kunstwerk1"), + } + }; + } + + protected override StructuresCalculation CreateCalculation() + { + return new TestClosingStructuresCalculation(); + } + + protected override ClosingStructuresCalculationConfigurationExporter CallConfigurationFilePathConstructor(IEnumerable calculations, string filePath) + { + return new ClosingStructuresCalculationConfigurationExporter(calculations, filePath); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationReaderTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationReaderTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationReaderTest.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,634 @@ +// 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.IO; +using System.Linq; +using System.Xml.Schema; +using Core.Common.Base.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.IO.Configurations; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Readers; + +namespace Ringtoets.ClosingStructures.IO.Test.Configurations +{ + [TestFixture] + public class ClosingStructuresCalculationConfigurationReaderTest + { + private readonly string testDirectoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.ClosingStructures.IO, + nameof(ClosingStructuresCalculationConfigurationReader)); + + private static IEnumerable InvalidConfigurations + { + get + { + yield return new TestCaseData("invalidCalculationFailureProbabilityStructureWithErosionEmpty.xml", + "The 'faalkansgegevenerosiebodem' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityStructureWithErosionEmpty"); + yield return new TestCaseData("invalidCalculationFailureProbabilityStructureWithErosionNoDouble.xml", + "The 'faalkansgegevenerosiebodem' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityStructureWithErosionNoDouble"); + yield return new TestCaseData("invalidCalculationFailureProbabilityStructureWithErosionWrongCulture.xml", + "The 'faalkansgegevenerosiebodem' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityStructureWithErosionWrongCulture"); + + yield return new TestCaseData("invalidCalculationForeshoreProfileEmpty.xml", + "The 'voorlandprofiel' element is invalid - The value '' is invalid according to its datatype 'String'") + .SetName("invalidCalculationForeshoreProfileEmpty"); + + yield return new TestCaseData("invalidCalculationHydraulicBoundaryLocationEmpty.xml", + "The 'hrlocatie' element is invalid - The value '' is invalid according to its datatype 'String'") + .SetName("invalidCalculationHydraulicBoundaryLocationEmpty"); + + yield return new TestCaseData("invalidCalculationMultipleFailureProbabilityStructureWithErosion.xml", + "Element 'faalkansgegevenerosiebodem' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleFailureProbabilityStructureWithErosion"); + yield return new TestCaseData("invalidCalculationMultipleForeshoreProfile.xml", + "Element 'voorlandprofiel' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleForeshoreProfile"); + yield return new TestCaseData("invalidCalculationMultipleHydraulicBoundaryLocation.xml", + "Element 'hrlocatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleHydraulicBoundaryLocation"); + yield return new TestCaseData("invalidCalculationMultipleOrientation.xml", + "Element 'orientatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleOrientation"); + yield return new TestCaseData("invalidCalculationMultipleStructure.xml", + "Element 'kunstwerk' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleStructure"); + + yield return new TestCaseData("invalidCalculationMultipleFactorStormDurationOpenStructure.xml", + "Element 'factorstormduur' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleFactorStormDurationOpenStructure"); + yield return new TestCaseData("invalidCalculationMultipleFailureProbabilityOpenStructure.xml", + "Element 'kansmislukkensluiting' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleFailureProbabilityOpenStructure"); + yield return new TestCaseData("invalidCalculationMultipleFailureProbabilityReparation.xml", + "Element 'faalkansherstel' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleFailureProbabilityReparation"); + yield return new TestCaseData("invalidCalculationMultipleIdenticalApertures.xml", + "Element 'nrdoorstroomopeningen' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleIdenticalApertures"); + yield return new TestCaseData("invalidCalculationMultipleInflowModelTypes.xml", + "Element 'instroommodel' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleInflowModelTypes"); + yield return new TestCaseData("invalidCalculationMultipleProbabilityOrFrequencyOpenStructureBeforeFlooding.xml", + "Element 'kansopopenstaan' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleProbabilityOrFrequencyOpenStructureBeforeFlooding"); + + yield return new TestCaseData("invalidCalculationOrientationEmpty.xml", + "The 'orientatie' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationOrientationEmpty"); + yield return new TestCaseData("invalidCalculationOrientationNoDouble.xml", + "The 'orientatie' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationOrientationNoDouble"); + yield return new TestCaseData("invalidCalculationOrientationWrongCulture.xml", + "The 'orientatie' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationOrientationWrongCulture"); + + yield return new TestCaseData("invalidCalculationStructureEmpty.xml", + "The 'kunstwerk' element is invalid - The value '' is invalid according to its datatype 'String'") + .SetName("invalidCalculationStructureEmpty"); + + yield return new TestCaseData("invalidCalculationFactorStormDurationOpenStructureEmpty.xml", + "The 'factorstormduur' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFactorStormDurationOpenStructureEmpty"); + yield return new TestCaseData("invalidCalculationFactorStormDurationOpenStructureNoDouble.xml", + "The 'factorstormduur' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFactorStormDurationOpenStructureNoDouble"); + yield return new TestCaseData("invalidCalculationFactorStormDurationOpenStructureWrongCulture.xml", + "The 'factorstormduur' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFactorStormDurationOpenStructureWrongCulture"); + + yield return new TestCaseData("invalidCalculationFailureProbabilityOpenStructureEmpty.xml", + "The 'kansmislukkensluiting' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityOpenStructureEmpty"); + yield return new TestCaseData("invalidCalculationFailureProbabilityOpenStructureNoDouble.xml", + "The 'kansmislukkensluiting' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityOpenStructureNoDouble"); + yield return new TestCaseData("invalidCalculationFailureProbabilityOpenStructureWrongCulture.xml", + "The 'kansmislukkensluiting' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityOpenStructureWrongCulture"); + + yield return new TestCaseData("invalidCalculationFailureProbabilityReparationEmpty.xml", + "The 'faalkansherstel' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityReparationEmpty"); + yield return new TestCaseData("invalidCalculationFailureProbabilityReparationNoDouble.xml", + "The 'faalkansherstel' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityReparationNoDouble"); + yield return new TestCaseData("invalidCalculationFailureProbabilityReparationWrongCulture.xml", + "The 'faalkansherstel' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationFailureProbabilityReparationWrongCulture"); + + yield return new TestCaseData("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingEmpty.xml", + "The 'kansopopenstaan' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingEmpty"); + yield return new TestCaseData("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingNoDouble.xml", + "The 'kansopopenstaan' element is invalid - The value 'nul' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingNoDouble"); + yield return new TestCaseData("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingWrongCulture.xml", + "The 'kansopopenstaan' element is invalid - The value '0,5' is invalid according to its datatype 'Double'") + .SetName("invalidCalculationProbabilityOrFrequencyOpenStructureBeforeFloodingWrongCulture"); + + yield return new TestCaseData("invalidCalculationIdenticalAperturesEmpty.xml", + "The 'nrdoorstroomopeningen' element is invalid - The value '' is invalid according to its datatype 'Integer'") + .SetName("invalidCalculationIdenticalAperturesEmpty"); + yield return new TestCaseData("invalidCalculationIdenticalAperturesNoInt.xml", + "The 'nrdoorstroomopeningen' element is invalid - The value 'nul' is invalid according to its datatype 'Integer'") + .SetName("invalidCalculationIdenticalAperturesNoInt"); + + yield return new TestCaseData("invalidCalculationInflowModelTypeEmpty.xml", + "The 'instroommodel' element is invalid - The value '' is invalid according to its datatype 'String' - The Enumeration constraint failed.") + .SetName("invalidCalculationInflowModelTypeEmpty"); + yield return new TestCaseData("invalidCalculationInflowModelTypeUnsupportedString.xml", + "The 'instroommodel' element is invalid - The value 'invalid' is invalid according to its datatype 'String' - The Enumeration constraint failed.") + .SetName("invalidCalculationInflowModelTypeUnsupportedString"); + + yield return new TestCaseData("invalidStochastNoName.xml", + "The required attribute 'naam' is missing.") + .SetName("invalidStochastNoName"); + yield return new TestCaseData("invalidStochastUnknownName.xml", + "The 'naam' attribute is invalid - The value 'Test' is invalid according to its datatype 'nameType' - The Enumeration constraint failed.") + .SetName("invalidStochastUnknownName"); + yield return new TestCaseData("invalidStochastMultipleMean.xml", + "Element 'verwachtingswaarde' cannot appear more than once if content model type is \"all\".") + .SetName("invalidStochastMultipleMean"); + yield return new TestCaseData("invalidStochastMultipleStandardDeviation.xml", + "Element 'standaardafwijking' cannot appear more than once if content model type is \"all\".") + .SetName("invalidStochastMultipleStandardDeviation"); + yield return new TestCaseData("invalidStochastMultipleVariationCoefficient.xml", + "Element 'variatiecoefficient' cannot appear more than once if content model type is \"all\".") + .SetName("invalidStochastMultipleVariationCoefficient"); + yield return new TestCaseData("invalidStochastMeanEmpty.xml", + "The 'verwachtingswaarde' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidStochastMeanEmpty"); + yield return new TestCaseData("invalidStochastMeanNoDouble.xml", + "The 'verwachtingswaarde' element is invalid - The value 'string' is invalid according to its datatype 'Double'") + .SetName("invalidStochastMeanNoDouble"); + yield return new TestCaseData("invalidStochastMeanWrongCulture.xml", + "The 'verwachtingswaarde' element is invalid - The value '1,2' is invalid according to its datatype 'Double'") + .SetName("invalidStochastMeanWrongCulture"); + yield return new TestCaseData("invalidStochastStandardDeviationEmpty.xml", + "The 'standaardafwijking' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidStochastStandardDeviationEmpty"); + yield return new TestCaseData("invalidStochastStandardDeviationNoDouble.xml", + "The 'standaardafwijking' element is invalid - The value 'string' is invalid according to its datatype 'Double'") + .SetName("invalidStochastStandardDeviationNoDouble"); + yield return new TestCaseData("invalidStochastStandardDeviationWrongCulture.xml", + "The 'standaardafwijking' element is invalid - The value '1,2' is invalid according to its datatype 'Double'") + .SetName("invalidStochastStandardDeviationWrongCulture"); + yield return new TestCaseData("invalidStochastVariationCoefficientEmpty.xml", + "The 'variatiecoefficient' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidStochastVariationCoefficientEmpty"); + yield return new TestCaseData("invalidStochastVariationCoefficientNoDouble.xml", + "The 'variatiecoefficient' element is invalid - The value 'string' is invalid according to its datatype 'Double'") + .SetName("invalidStochastVariationCoefficientNoDouble"); + yield return new TestCaseData("invalidStochastVariationCoefficientWrongCulture.xml", + "The 'variatiecoefficient' element is invalid - The value '1,2' is invalid according to its datatype 'Double'") + .SetName("invalidStochastVariationCoefficientWrongCulture"); + + yield return new TestCaseData("invalidMultipleAllowedLevelIncreaseStochast.xml", + "There is a duplicate key sequence 'peilverhogingkomberging' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleAllowedLevelIncreaseStochast"); + yield return new TestCaseData("invalidMultipleCriticalOvertoppingDischargeStochast.xml", + "There is a duplicate key sequence 'kritiekinstromenddebiet' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleCriticalOvertoppingDischargeStochast"); + yield return new TestCaseData("invalidMultipleFlowWidthAtBottomProtectionStochast.xml", + "There is a duplicate key sequence 'breedtebodembescherming' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleFlowWidthAtBottomProtectionStochast"); + yield return new TestCaseData("invalidMultipleModelFactorSuperCriticalFlowStochast.xml", + "There is a duplicate key sequence 'modelfactoroverloopdebiet' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleModelFactorSuperCriticalFlowStochast"); + yield return new TestCaseData("invalidMultipleStorageStructureAreaStochast.xml", + "There is a duplicate key sequence 'kombergendoppervlak' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleStorageStructureAreaStochast"); + yield return new TestCaseData("invalidMultipleStormDurationStochast.xml", + "There is a duplicate key sequence 'stormduur' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleStormDurationStochast"); + yield return new TestCaseData("invalidMultipleWidthFlowAperturesStochast.xml", + "There is a duplicate key sequence 'breedtedoorstroomopening' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleWidthFlowAperturesStochast"); + + yield return new TestCaseData("invalidMultipleAreaFlowAperturesStochast.xml", + "There is a duplicate key sequence 'doorstroomoppervlak' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleAreaFlowAperturesStochast"); + yield return new TestCaseData("invalidMultipleDrainCoefficientStochast.xml", + "There is a duplicate key sequence 'afvoercoefficient' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleDrainCoefficientStochast"); + yield return new TestCaseData("invalidMultipleInsideWaterLevelStochast.xml", + "There is a duplicate key sequence 'binnenwaterstand' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleInsideWaterLevelStochast"); + yield return new TestCaseData("invalidMultipleLevelCrestStructureNotClosingStochast.xml", + "There is a duplicate key sequence 'kruinhoogte' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleLevelCrestStructureNotClosingStochast"); + yield return new TestCaseData("invalidMultipleThresholdHeightOpenWeirStochast.xml", + "There is a duplicate key sequence 'drempelhoogte' for the 'uniqueStochastNameConstraint' key or unique identity constraint.") + .SetName("invalidMultipleThresholdHeightOpenWeirStochast"); + + yield return new TestCaseData("invalidUseBreakWaterEmpty.xml", + "The 'damgebruiken' element is invalid - The value '' is invalid according to its datatype 'Boolean'") + .SetName("invalidUseBreakWaterEmpty"); + yield return new TestCaseData("invalidUseBreakWaterNoBoolean.xml", + "The 'damgebruiken' element is invalid - The value 'string' is invalid according to its datatype 'Boolean'") + .SetName("invalidUseBreakWaterNoBoolean"); + yield return new TestCaseData("invalidMultipleUseBreakWaters.xml", + "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", + "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.") + .SetName("invalidBreakWaterTypeUnsupportedString"); + + yield return new TestCaseData("invalidBreakWaterHeightEmpty.xml", + "The 'damhoogte' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidBreakWaterHeightEmpty"); + yield return new TestCaseData("invalidBreakWaterHeightNoDouble.xml", + "The 'damhoogte' element is invalid - The value 'string' is invalid according to its datatype 'Double'") + .SetName("invalidBreakWaterHeightNoDouble"); + yield return new TestCaseData("invalidBreakWaterHeightWrongCulture.xml", + "The 'damhoogte' element is invalid - The value '1,2' is invalid according to its datatype 'Double'") + .SetName("invalidBreakWaterHeightWrongCulture"); + yield return new TestCaseData("invalidMultipleBreakWaterHeights.xml", + "Element 'damhoogte' cannot appear more than once if content model type is \"all\".") + .SetName("invalidMultipleBreakWaterHeights"); + + yield return new TestCaseData("invalidUseForeshoreEmpty.xml", + "The 'voorlandgebruiken' element is invalid - The value '' is invalid according to its datatype 'Boolean'") + .SetName("invalidUseForeshoreEmpty"); + yield return new TestCaseData("invalidUseForeshoreNoBoolean.xml", + "The 'voorlandgebruiken' element is invalid - The value 'string' is invalid according to its datatype 'Boolean'") + .SetName("invalidUseForeshoreNoBoolean"); + yield return new TestCaseData("invalidMultipleUseForeshore.xml", + "Element 'voorlandgebruiken' cannot appear more than once if content model type is \"all\".") + .SetName("invalidMultipleUseForeshores"); + } + } + + [Test] + public void Constructor_WithFilePath_ReturnsNewInstance() + { + // Setup + var existingPath = Path.Combine(testDirectoryPath, "validConfigurationEmptyCalculation.xml"); + + // Call + var reader = new ClosingStructuresCalculationConfigurationReader(existingPath); + + // Assert + Assert.IsInstanceOf>(reader); + } + + [Test] + [TestCaseSource(nameof(InvalidConfigurations))] + public void Constructor_FileInvalidBasedOnSchemaDefinition_ThrowCriticalFileReadException(string fileName, string expectedParsingMessage) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, fileName); + + // Call + TestDelegate call = () => new ClosingStructuresCalculationConfigurationReader(filePath); + + // Assert + var exception = Assert.Throws(call); + 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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) 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.LevelCrestStructureNotClosing); + 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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) 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(0.002, calculation.FactorStormDurationOpenStructure); + Assert.AreEqual(0.03, calculation.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + Assert.AreEqual(0.22, calculation.FailureProbabilityOpenStructure); + Assert.AreEqual(0.0006, calculation.FailureProbabilityReparation); + Assert.AreEqual(0.001, calculation.FailureProbabilityStructureWithErosion); + Assert.AreEqual(4, calculation.IdenticalApertures); + Assert.AreEqual(ConfigurationClosingStructureInflowModelType.VerticalWall, calculation.InflowModelType); + + Assert.AreEqual(1.1, calculation.DrainCoefficient.Mean); + Assert.AreEqual(0.1, calculation.DrainCoefficient.StandardDeviation); + Assert.AreEqual(0.5, calculation.InsideWaterLevel.Mean); + Assert.AreEqual(0.1, calculation.InsideWaterLevel.StandardDeviation); + Assert.AreEqual(80.5, calculation.AreaFlowApertures.Mean); + Assert.AreEqual(1, calculation.AreaFlowApertures.StandardDeviation); + Assert.AreEqual(1.2, calculation.ThresholdHeightOpenWeir.Mean); + Assert.AreEqual(0.1, calculation.ThresholdHeightOpenWeir.StandardDeviation); + Assert.AreEqual(4.3, calculation.LevelCrestStructureNotClosing.Mean); + Assert.AreEqual(0.2, calculation.LevelCrestStructureNotClosing.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.AreEqual(0.12, calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.AreEqual(15000, calculation.StorageStructureArea.Mean); + Assert.AreEqual(0.01, calculation.StorageStructureArea.VariationCoefficient); + Assert.AreEqual(6.0, calculation.StormDuration.Mean); + Assert.AreEqual(0.12, calculation.StormDuration.VariationCoefficient); + Assert.AreEqual(15.2, calculation.WidthFlowApertures.Mean); + Assert.AreEqual(0.1, calculation.WidthFlowApertures.StandardDeviation); + + Assert.AreEqual(ConfigurationBreakWaterType.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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsTrue(double.IsNegativeInfinity(calculation.StructureNormalOrientation.Value)); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsTrue(double.IsPositiveInfinity(calculation.FactorStormDurationOpenStructure.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.ProbabilityOrFrequencyOpenStructureBeforeFlooding.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.FailureProbabilityOpenStructure.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.FailureProbabilityReparation.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.FailureProbabilityStructureWithErosion.Value)); + + Assert.IsTrue(double.IsNegativeInfinity(calculation.DrainCoefficient.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.DrainCoefficient.StandardDeviation.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.InsideWaterLevel.Mean.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.InsideWaterLevel.StandardDeviation.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.AreaFlowApertures.Mean.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.AreaFlowApertures.StandardDeviation.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.ThresholdHeightOpenWeir.Mean.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.ThresholdHeightOpenWeir.StandardDeviation.Value)); + Assert.IsTrue(double.IsPositiveInfinity(calculation.LevelCrestStructureNotClosing.Mean.Value)); + Assert.IsTrue(double.IsNegativeInfinity(calculation.LevelCrestStructureNotClosing.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.IsTrue(double.IsNegativeInfinity(calculation.ModelFactorSuperCriticalFlow.StandardDeviation.Value)); + 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.IsTrue(double.IsPositiveInfinity(calculation.StormDuration.VariationCoefficient.Value)); + 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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNaN(calculation.StructureNormalOrientation); + Assert.IsNull(calculation.StructureName); + Assert.IsNull(calculation.HydraulicBoundaryLocationName); + Assert.IsNull(calculation.ForeshoreProfileName); + Assert.IsNaN(calculation.FactorStormDurationOpenStructure); + Assert.IsNaN(calculation.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + Assert.IsNaN(calculation.FailureProbabilityOpenStructure); + Assert.IsNaN(calculation.FailureProbabilityReparation); + Assert.IsNaN(calculation.FailureProbabilityStructureWithErosion); + + Assert.IsNaN(calculation.DrainCoefficient.Mean); + Assert.IsNaN(calculation.DrainCoefficient.StandardDeviation); + Assert.IsNaN(calculation.InsideWaterLevel.Mean); + Assert.IsNaN(calculation.InsideWaterLevel.StandardDeviation); + Assert.IsNaN(calculation.AreaFlowApertures.Mean); + Assert.IsNaN(calculation.AreaFlowApertures.StandardDeviation); + Assert.IsNaN(calculation.ThresholdHeightOpenWeir.Mean); + Assert.IsNaN(calculation.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNaN(calculation.LevelCrestStructureNotClosing.Mean); + Assert.IsNaN(calculation.LevelCrestStructureNotClosing.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.IsNaN(calculation.ModelFactorSuperCriticalFlow.StandardDeviation); + Assert.IsNaN(calculation.StorageStructureArea.Mean); + Assert.IsNaN(calculation.StorageStructureArea.VariationCoefficient); + Assert.IsNaN(calculation.StormDuration.Mean); + Assert.IsNaN(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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) 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.FailureProbabilityOpenStructure); + Assert.IsNull(calculation.FailureProbabilityReparation); + Assert.IsNull(calculation.IdenticalApertures); + Assert.IsNull(calculation.InflowModelType); + Assert.IsNull(calculation.FactorStormDurationOpenStructure); + Assert.IsNull(calculation.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + + Assert.IsNull(calculation.AreaFlowApertures); + Assert.IsNull(calculation.DrainCoefficient); + Assert.IsNull(calculation.InsideWaterLevel); + Assert.IsNull(calculation.ThresholdHeightOpenWeir); + Assert.IsNull(calculation.LevelCrestStructureNotClosing); + + 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 ClosingStructuresCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (ClosingStructuresCalculationConfiguration) 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.FailureProbabilityOpenStructure); + Assert.IsNull(calculation.FailureProbabilityReparation); + Assert.IsNull(calculation.IdenticalApertures); + Assert.IsNull(calculation.InflowModelType); + Assert.IsNull(calculation.FactorStormDurationOpenStructure); + Assert.IsNull(calculation.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + + Assert.IsNull(calculation.AreaFlowApertures.Mean); + Assert.IsNull(calculation.AreaFlowApertures.StandardDeviation); + Assert.IsNull(calculation.DrainCoefficient.Mean); + Assert.IsNull(calculation.DrainCoefficient.StandardDeviation); + Assert.IsNull(calculation.InsideWaterLevel.Mean); + Assert.IsNull(calculation.InsideWaterLevel.StandardDeviation); + Assert.IsNull(calculation.ThresholdHeightOpenWeir.Mean); + Assert.IsNull(calculation.ThresholdHeightOpenWeir.StandardDeviation); + Assert.IsNull(calculation.LevelCrestStructureNotClosing.Mean); + Assert.IsNull(calculation.LevelCrestStructureNotClosing.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 Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationTest.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,112 @@ +// 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; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.IO.Configurations; +using Ringtoets.Common.IO.Configurations; + +namespace Ringtoets.ClosingStructures.IO.Test.Configurations +{ + [TestFixture] + public class ClosingStructuresCalculationConfigurationTest + { + [Test] + public void Constructor_NameNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new ClosingStructuresCalculationConfiguration(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("value", paramName); + } + + [Test] + public void Constructor_WithName_ExpectedValues() + { + // Call + var configuration = new ClosingStructuresCalculationConfiguration("some name"); + + // Assert + Assert.IsInstanceOf(configuration); + Assert.AreEqual("some name", configuration.Name); + Assert.IsNull(configuration.InflowModelType); + Assert.IsNull(configuration.InsideWaterLevel); + Assert.IsNull(configuration.DrainCoefficient); + Assert.IsNull(configuration.ThresholdHeightOpenWeir); + Assert.IsNull(configuration.AreaFlowApertures); + Assert.IsNull(configuration.LevelCrestStructureNotClosing); + Assert.IsNull(configuration.IdenticalApertures); + Assert.IsNull(configuration.FactorStormDurationOpenStructure); + Assert.IsNull(configuration.FailureProbabilityOpenStructure); + Assert.IsNull(configuration.FailureProbabilityReparation); + Assert.IsNull(configuration.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + } + + [Test] + public void SimpleProperties_SetNewValues_NewValuesSet() + { + // Setup + var random = new Random(21); + var inflowModelType = random.NextEnumValue(); + var insideWaterLevel = new MeanStandardDeviationStochastConfiguration(); + var drainCoefficient = new MeanStandardDeviationStochastConfiguration(); + var thresholdHeightOpenWeir = new MeanStandardDeviationStochastConfiguration(); + var areaFlowApertures = new MeanStandardDeviationStochastConfiguration(); + var levelCrestStructureNotClosing = new MeanStandardDeviationStochastConfiguration(); + var identicalApertures = random.Next(1, 5); + var factorStormDurationOpenStructure = random.NextDouble(); + var failureProbabilityOpenStructure = random.NextDouble(); + var failureProbabilityReparation = random.NextDouble(); + var probabilityOrFrequencyOpenStructureBeforeFlooding = random.NextDouble(); + + var configuration = new ClosingStructuresCalculationConfiguration("some name"); + + // Call + configuration.InflowModelType = inflowModelType; + configuration.InsideWaterLevel = insideWaterLevel; + configuration.DrainCoefficient = drainCoefficient; + configuration.ThresholdHeightOpenWeir = thresholdHeightOpenWeir; + configuration.AreaFlowApertures = areaFlowApertures; + configuration.LevelCrestStructureNotClosing = levelCrestStructureNotClosing; + configuration.IdenticalApertures = identicalApertures; + configuration.FactorStormDurationOpenStructure = factorStormDurationOpenStructure; + configuration.FailureProbabilityOpenStructure = failureProbabilityOpenStructure; + configuration.FailureProbabilityReparation = failureProbabilityReparation; + configuration.ProbabilityOrFrequencyOpenStructureBeforeFlooding = probabilityOrFrequencyOpenStructureBeforeFlooding; + + // Assert + Assert.AreEqual(inflowModelType, configuration.InflowModelType); + Assert.AreSame(insideWaterLevel, configuration.InsideWaterLevel); + Assert.AreSame(drainCoefficient, configuration.DrainCoefficient); + Assert.AreSame(thresholdHeightOpenWeir, configuration.ThresholdHeightOpenWeir); + Assert.AreSame(areaFlowApertures, configuration.AreaFlowApertures); + Assert.AreSame(levelCrestStructureNotClosing, configuration.LevelCrestStructureNotClosing); + Assert.AreEqual(identicalApertures, configuration.IdenticalApertures); + Assert.AreEqual(factorStormDurationOpenStructure, configuration.FactorStormDurationOpenStructure); + Assert.AreEqual(failureProbabilityOpenStructure, configuration.FailureProbabilityOpenStructure); + Assert.AreEqual(failureProbabilityReparation, configuration.FailureProbabilityReparation); + Assert.AreEqual(probabilityOrFrequencyOpenStructureBeforeFlooding, configuration.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/ClosingStructuresCalculationConfigurationWriterTest.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,196 @@ +// 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.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.ClosingStructures.IO.Configurations; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.TestUtil; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.ClosingStructures.IO.Test.Configurations +{ + [TestFixture] + public class ClosingStructuresCalculationConfigurationWriterTest + : CustomSchemaCalculationConfigurationWriterDesignGuidelinesTestFixture< + ClosingStructuresCalculationConfigurationWriter, + ClosingStructuresCalculationConfiguration> + { + private readonly string testDataPath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.ClosingStructures.IO, + nameof(ClosingStructuresCalculationConfigurationWriter)); + + private static IEnumerable Calculations + { + get + { + yield return new TestCaseData("completeConfiguration", new[] + { + CreateFullCalculation() + }) + .SetName("Calculation configuration with all parameters set"); + yield return new TestCaseData("sparseConfiguration", new[] + { + new ClosingStructuresCalculationConfiguration("sparse config") + }) + .SetName("Calculation configuration with none of its parameters set"); + yield return new TestCaseData("folderWithSubfolderAndCalculation", new IConfigurationItem[] + { + new CalculationGroupConfiguration("Testmap", new IConfigurationItem[] + { + CreateFullCalculation(), + new CalculationGroupConfiguration("Nested", new IConfigurationItem[] + { + new ClosingStructuresCalculationConfiguration("Berekening 2") + }) + }) + }) + .SetName("Calculation configurations in a hierarchy"); + } + } + + protected override void AssertDefaultConstructedInstance(ClosingStructuresCalculationConfigurationWriter writer) + { + Assert.IsInstanceOf>(writer); + } + + [Test] + [TestCaseSource(nameof(Calculations))] + public void Write_ValidCalculation_ValidFile(string expectedFileName, IConfigurationItem[] configuration) + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(ClosingStructuresCalculationConfigurationWriterTest)}.{nameof(Write_ValidCalculation_ValidFile)}.{expectedFileName}.xml"); + + try + { + var writer = new ClosingStructuresCalculationConfigurationWriter(filePath); + + // Call + writer.Write(configuration); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXmlFilePath = Path.Combine(testDataPath, $"{expectedFileName}.xml"); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + private static ClosingStructuresCalculationConfiguration CreateFullCalculation() + { + return new ClosingStructuresCalculationConfiguration("Berekening 1") + { + HydraulicBoundaryLocationName = "Locatie1", + StructureName = "kunstwerk1", + ForeshoreProfileName = "profiel1", + FailureProbabilityStructureWithErosion = 1e-4, + StructureNormalOrientation = 67.1, + FactorStormDurationOpenStructure = 1.0, + IdenticalApertures = 1, + ProbabilityOrFrequencyOpenStructureBeforeFlooding = 1e-2, + FailureProbabilityOpenStructure = 1e-3, + FailureProbabilityReparation = 1e-2, + InflowModelType = ConfigurationClosingStructureInflowModelType.LowSill, + WaveReduction = new WaveReductionConfiguration + { + UseBreakWater = true, + BreakWaterType = ConfigurationBreakWaterType.Dam, + BreakWaterHeight = 1.23, + UseForeshoreProfile = true + }, + FlowWidthAtBottomProtection = new MeanStandardDeviationStochastConfiguration + { + Mean = 15.2, + StandardDeviation = 0.1 + }, + WidthFlowApertures = new MeanStandardDeviationStochastConfiguration + { + Mean = 13.2, + StandardDeviation = 0.3 + }, + StorageStructureArea = new MeanVariationCoefficientStochastConfiguration + { + Mean = 15000, + VariationCoefficient = 0.01 + }, + CriticalOvertoppingDischarge = new MeanVariationCoefficientStochastConfiguration + { + Mean = 2, + VariationCoefficient = 0.1 + }, + ModelFactorSuperCriticalFlow = new MeanStandardDeviationStochastConfiguration + { + Mean = 1.1, + StandardDeviation = 0.14 + }, + AllowedLevelIncreaseStorage = new MeanStandardDeviationStochastConfiguration + { + Mean = 0.2, + StandardDeviation = 0.01 + }, + StormDuration = new MeanVariationCoefficientStochastConfiguration + { + Mean = 6.0, + VariationCoefficient = 0.22 + }, + DrainCoefficient = new MeanStandardDeviationStochastConfiguration + { + Mean = 1.1, + StandardDeviation = 0.02 + }, + InsideWaterLevel = new MeanStandardDeviationStochastConfiguration + { + Mean = 0.5, + StandardDeviation = 0.1 + }, + AreaFlowApertures = new MeanStandardDeviationStochastConfiguration + { + Mean = 80.5, + StandardDeviation = 1 + }, + ThresholdHeightOpenWeir = new MeanStandardDeviationStochastConfiguration + { + Mean = 1.2, + StandardDeviation = 0.1 + }, + LevelCrestStructureNotClosing = new MeanStandardDeviationStochastConfiguration + { + Mean = 4.3, + StandardDeviation = 0.2 + } + }; + } + + protected override ClosingStructuresCalculationConfigurationWriter CreateWriterInstance(string filePath) + { + return new ClosingStructuresCalculationConfigurationWriter(filePath); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverterTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverterTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Configurations/Helpers/ConfigurationClosingStructureInflowModelTypeConverterTest.cs (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -0,0 +1,230 @@ +// 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; +using System.ComponentModel; +using NUnit.Framework; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.IO.Configurations; +using Ringtoets.ClosingStructures.IO.Configurations.Helpers; + +namespace Ringtoets.ClosingStructures.IO.Test.Configurations.Helpers +{ + [TestFixture] + public class ConfigurationClosingStructureInflowModelTypeConverterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertTo_String_ReturnTrue() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(string)); + + // Assert + Assert.IsTrue(canConvertToString); + } + + [Test] + public void CanConvertTo_ClosingStructureInflowModelType_ReturnTrue() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(ClosingStructureInflowModelType)); + + // Assert + Assert.IsTrue(canConvertToString); + } + + [Test] + public void CanConvertTo_OtherThanStringOrClosingStructureInflowModelType_ReturnFalse() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertToString = converter.CanConvertTo(typeof(object)); + + // Assert + Assert.IsFalse(canConvertToString); + } + + [Test] + [TestCase(ConfigurationClosingStructureInflowModelType.FloodedCulvert, ClosingStructuresConfigurationSchemaIdentifiers.FloodedCulvert)] + [TestCase(ConfigurationClosingStructureInflowModelType.LowSill, ClosingStructuresConfigurationSchemaIdentifiers.LowSill)] + [TestCase(ConfigurationClosingStructureInflowModelType.VerticalWall, ClosingStructuresConfigurationSchemaIdentifiers.VerticalWall)] + public void ConvertTo_VariousCases_ReturnExpectedText(ConfigurationClosingStructureInflowModelType value, + string expectedResult) + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + object result = converter.ConvertTo(value, typeof(string)); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void ConvertTo_InvalidClosingStructureInflowModelType_ThrowNotSupportedException() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + var invalidValue = (ConfigurationClosingStructureInflowModelType)99999999; + + // Call + TestDelegate call = () => converter.ConvertTo(invalidValue, typeof(string)); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(ConfigurationClosingStructureInflowModelType.FloodedCulvert, ClosingStructureInflowModelType.FloodedCulvert)] + [TestCase(ConfigurationClosingStructureInflowModelType.LowSill, ClosingStructureInflowModelType.LowSill)] + [TestCase(ConfigurationClosingStructureInflowModelType.VerticalWall, ClosingStructureInflowModelType.VerticalWall)] + public void ConvertTo_VariousCases_ReturnExpectedText(ConfigurationClosingStructureInflowModelType value, + ClosingStructureInflowModelType expectedResult) + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + object result = converter.ConvertTo(value, typeof(ClosingStructureInflowModelType)); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CanConvertFrom_String_ReturnTrue() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(string)); + + // Assert + Assert.IsTrue(canConvertFromString); + } + + [Test] + public void CanConvertFrom_ClosingStructureInflowModelType_ReturnTrue() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(ClosingStructureInflowModelType)); + + // Assert + Assert.IsTrue(canConvertFromString); + } + + [Test] + public void CanConvertFrom_OtherThanStringOrClosingStructureInflowModelType_ReturnFalse() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + bool canConvertFromString = converter.CanConvertFrom(typeof(object)); + + // Assert + Assert.IsFalse(canConvertFromString); + } + + [Test] + [TestCase(ClosingStructuresConfigurationSchemaIdentifiers.FloodedCulvert,ConfigurationClosingStructureInflowModelType.FloodedCulvert)] + [TestCase(ClosingStructuresConfigurationSchemaIdentifiers.LowSill, ConfigurationClosingStructureInflowModelType.LowSill)] + [TestCase(ClosingStructuresConfigurationSchemaIdentifiers.VerticalWall, ConfigurationClosingStructureInflowModelType.VerticalWall)] + public void ConvertFrom_Text_ReturnExpectedClosingStructureInflowModelType(string value, + ConfigurationClosingStructureInflowModelType expectedResult) + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + object result = converter.ConvertFrom(value); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void ConvertFrom_InvalidText_ThrowNotSupportedException() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + TestDelegate call = () => converter.ConvertFrom("A"); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(ClosingStructureInflowModelType.FloodedCulvert, ConfigurationClosingStructureInflowModelType.FloodedCulvert)] + [TestCase(ClosingStructureInflowModelType.LowSill, ConfigurationClosingStructureInflowModelType.LowSill)] + [TestCase(ClosingStructureInflowModelType.VerticalWall, ConfigurationClosingStructureInflowModelType.VerticalWall)] + public void ConvertFrom_ClosingStructureInflowModelType_ReturnExpectedClosingStructureInflowModelType(ClosingStructureInflowModelType value, + ConfigurationClosingStructureInflowModelType expectedResult) + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + object result = converter.ConvertFrom(value); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void ConvertFrom_InvalidClosingStructureInflowModelType_ThrowNotSupportedException() + { + // Setup + var converter = new ConfigurationClosingStructureInflowModelTypeConverter(); + + // Call + TestDelegate call = () => converter.ConvertFrom((ClosingStructureInflowModelType)(-1)); + + // Assert + Assert.Throws(call); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj =================================================================== diff -u -r04a0742040ae09f8839510470014d2b273e67a78 -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj (.../Ringtoets.ClosingStructures.IO.Test.csproj) (revision 04a0742040ae09f8839510470014d2b273e67a78) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.IO.Test/Ringtoets.ClosingStructures.IO.Test.csproj (.../Ringtoets.ClosingStructures.IO.Test.csproj) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -50,12 +50,12 @@ Properties\GlobalAssembly.cs - + - - - - + + + + Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationContextExportInfoTest.cs =================================================================== diff -u -rf690272ef922b7cefaac34021bceca21947004c0 -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationContextExportInfoTest.cs (.../ClosingStructuresCalculationContextExportInfoTest.cs) (revision f690272ef922b7cefaac34021bceca21947004c0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationContextExportInfoTest.cs (.../ClosingStructuresCalculationContextExportInfoTest.cs) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -31,6 +31,7 @@ using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.ClosingStructures.Forms.PresentationObjects; using Ringtoets.ClosingStructures.IO; +using Ringtoets.ClosingStructures.IO.Configurations; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; namespace Ringtoets.ClosingStructures.Plugin.Test.ExportInfos Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -rf690272ef922b7cefaac34021bceca21947004c0 -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationGroupContextExportInfoTest.cs (.../ClosingStructuresCalculationGroupContextExportInfoTest.cs) (revision f690272ef922b7cefaac34021bceca21947004c0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ExportInfos/ClosingStructuresCalculationGroupContextExportInfoTest.cs (.../ClosingStructuresCalculationGroupContextExportInfoTest.cs) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) @@ -32,6 +32,7 @@ using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.ClosingStructures.Forms.PresentationObjects; using Ringtoets.ClosingStructures.IO; +using Ringtoets.ClosingStructures.IO.Configurations; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; namespace Ringtoets.ClosingStructures.Plugin.Test.ExportInfos