Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfiguration.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfiguration.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfiguration.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,202 @@
+// Copyright (C) Stichting Deltares 2017. 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.GrassCoverErosionInwards.IO.Configurations
+{
+ ///
+ /// Class that represents a grass cover erosion inwards calculation that is read via
+ /// .
+ ///
+ public class ReadGrassCoverErosionInwardsCalculation : IConfigurationItem
+ {
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The container of the properties for the
+ /// .
+ /// Thrown when
+ /// is null.
+ public ReadGrassCoverErosionInwardsCalculation(ConstructionProperties constructionProperties)
+ {
+ if (constructionProperties == null)
+ {
+ throw new ArgumentNullException(nameof(constructionProperties));
+ }
+
+ Name = constructionProperties.Name;
+ HydraulicBoundaryLocation = constructionProperties.HydraulicBoundaryLocation;
+ DikeProfileId = constructionProperties.DikeProfileId;
+ Orientation = constructionProperties.Orientation;
+ DikeHeight = constructionProperties.DikeHeight;
+ DikeHeightCalculationType = constructionProperties.DikeHeightCalculationType;
+ OvertoppingRateCalculationType = constructionProperties.OvertoppingRateCalculationType;
+ UseBreakWater = constructionProperties.UseBreakWater;
+ BreakWaterType = constructionProperties.BreakWaterType;
+ BreakWaterHeight = constructionProperties.BreakWaterHeight;
+ UseForeshore = constructionProperties.UseForeshore;
+ CriticalFlowRateMean = constructionProperties.CriticalFlowRateMean;
+ CriticalFlowRateStandardDeviation = constructionProperties.CriticalFlowRateStandardDeviation;
+ }
+
+ ///
+ /// Gets the name of the hydraulic boundary location of the read grass cover erosion
+ /// inwards calculation.
+ ///
+ public string HydraulicBoundaryLocation { get; }
+
+ ///
+ /// Gets the Id of the dike profile of the read grass cover erosion inwards calculation.
+ ///
+ public string DikeProfileId { get; }
+
+ ///
+ /// Gets the orientation of the grass cover erosion inwards calculation.
+ ///
+ public double? Orientation { get; }
+
+ ///
+ /// Gets the dike height of the grass cover erosion inwards calculation.
+ ///
+ public double? DikeHeight { get; }
+
+ ///
+ /// Gets the value for how the dike height should be calculated for the grass cover
+ /// erosion inwards calculation.
+ ///
+ public ReadHydraulicLoadsCalculationType? DikeHeightCalculationType { get; }
+
+ ///
+ /// Gets the value for how the overtopping rate should be calculated for the grass cover
+ /// erosion inwards calculation.
+ ///
+ public ReadHydraulicLoadsCalculationType? OvertoppingRateCalculationType { get; }
+
+ ///
+ /// Gets the value indicating if the break water for the grass cover erosion inwards
+ /// calculation should be used.
+ ///
+ public bool? UseBreakWater { get; }
+
+ ///
+ /// Gets the type of break water for the grass cover erosion inwards calculation.
+ ///
+ public ConfigurationBreakWaterType? BreakWaterType { get; }
+
+ ///
+ /// Gets the height of the break water for the grass cover erosion inwards calculation.
+ ///
+ public double? BreakWaterHeight { get; }
+
+ ///
+ /// Gets the value indicating if the foreshore for the grass cover erosion inwards
+ /// calculation should be used.
+ ///
+ public bool? UseForeshore { get; }
+
+ ///
+ /// Gets the mean of the critical flow distribution for the grass cover erosion
+ /// inwards calculation.
+ ///
+ public double? CriticalFlowRateMean { get; }
+
+ ///
+ /// Gets the standard deviation of the critical flow distribution for the grass
+ /// cover erosion inwards calculation.
+ ///
+ public double? CriticalFlowRateStandardDeviation { get; }
+
+ public string Name { get; }
+
+ ///
+ /// Class holding the various construction parameters for .
+ ///
+ public class ConstructionProperties
+ {
+ ///
+ /// Gets or sets the value for .
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public string HydraulicBoundaryLocation { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public string DikeProfileId { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public double? Orientation { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public double? DikeHeight { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public ReadHydraulicLoadsCalculationType? DikeHeightCalculationType { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public ReadHydraulicLoadsCalculationType? OvertoppingRateCalculationType { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public bool? UseBreakWater { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public ConfigurationBreakWaterType? BreakWaterType { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public double? BreakWaterHeight { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public bool? UseForeshore { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public double? CriticalFlowRateMean { get; set; }
+
+ ///
+ /// Gets or sets the value for .
+ ///
+ public double? CriticalFlowRateStandardDeviation { get; set; }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporter.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporter.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporter.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,46 @@
+// Copyright (C) Stichting Deltares 2017. 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.Common.Data.Calculation;
+using Ringtoets.Common.IO.Configurations.Export;
+using Ringtoets.GrassCoverErosionInwards.Data;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Configurations
+{
+ ///
+ /// Exports a grass cover erosion inwards calculation configuration and stores it as an XML file.
+ ///
+ public class GrassCoverErosionInwardsCalculationConfigurationExporter
+ : CalculationConfigurationExporter
+ {
+ ///
+ /// 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 GrassCoverErosionInwardsCalculationConfigurationExporter(IEnumerable configuration, string filePath)
+ : base(configuration, filePath) {}
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporter.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporter.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporter.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,332 @@
+// Copyright (C) Stichting Deltares 2017. 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.Linq;
+using Core.Common.Base.Data;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.DikeProfiles;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.IO.Configurations.Helpers;
+using Ringtoets.Common.IO.Configurations.Import;
+using Ringtoets.GrassCoverErosionInwards.Data;
+using Ringtoets.GrassCoverErosionInwards.IO.Properties;
+using Ringtoets.GrassCoverErosionInwards.Utils;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Configurations
+{
+ public class GrassCoverErosionInwardsCalculationConfigurationImporter
+ : CalculationConfigurationImporter
+ {
+ private readonly IEnumerable availableHydraulicBoundaryLocations;
+ private readonly IEnumerable availableDikeProfiles;
+ private readonly GrassCoverErosionInwardsFailureMechanism failureMechanism;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The path to the XML file to import from.
+ /// The calculation group to update.
+ /// The hydraulic boundary locations
+ /// used to check if the imported objects contain the right location.
+ /// The dike profiles used to check if
+ /// the imported objects contain the right profile.
+ /// The failure mechanism used to propagate changes.
+ /// Thrown when any parameter is
+ /// null.
+ public GrassCoverErosionInwardsCalculationConfigurationImporter(
+ string xmlFilePath,
+ CalculationGroup importTarget,
+ IEnumerable hydraulicBoundaryLocations,
+ IEnumerable dikeProfiles,
+ GrassCoverErosionInwardsFailureMechanism failureMechanism)
+ : base(xmlFilePath, importTarget)
+ {
+ if (hydraulicBoundaryLocations == null)
+ {
+ throw new ArgumentNullException(nameof(hydraulicBoundaryLocations));
+ }
+ if (dikeProfiles == null)
+ {
+ throw new ArgumentNullException(nameof(dikeProfiles));
+ }
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+ availableHydraulicBoundaryLocations = hydraulicBoundaryLocations;
+ availableDikeProfiles = dikeProfiles;
+ this.failureMechanism = failureMechanism;
+ }
+
+ protected override void DoPostImportUpdates()
+ {
+ GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments(
+ failureMechanism.SectionResults,
+ failureMechanism.Calculations.Cast());
+
+ base.DoPostImportUpdates();
+ }
+
+ protected override GrassCoverErosionInwardsCalculationConfigurationReader CreateCalculationConfigurationReader(string xmlFilePath)
+ {
+ return new GrassCoverErosionInwardsCalculationConfigurationReader(xmlFilePath);
+ }
+
+ protected override ICalculation ParseReadCalculation(ReadGrassCoverErosionInwardsCalculation readCalculation)
+ {
+ var calculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = readCalculation.Name
+ };
+ ReadDikeHeightCalculationType(readCalculation, calculation);
+ ReadOvertoppingRateCalculationType(readCalculation, calculation);
+
+ if (TryReadCriticalWaveReduction(readCalculation, calculation)
+ && TryReadHydraulicBoundaryLocation(readCalculation.HydraulicBoundaryLocation, calculation)
+ && TryReadDikeProfile(readCalculation.DikeProfileId, calculation)
+ && TryReadOrientation(readCalculation, calculation)
+ && TryReadWaveReduction(readCalculation, calculation)
+ && TryReadDikeHeight(readCalculation, calculation))
+ {
+ return calculation;
+ }
+ return null;
+ }
+
+ private bool TryReadHydraulicBoundaryLocation(string locationName, GrassCoverErosionInwardsCalculation calculation)
+ {
+ HydraulicBoundaryLocation location;
+
+ if (TryReadHydraulicBoundaryLocation(locationName, calculation.Name, availableHydraulicBoundaryLocations, out location))
+ {
+ calculation.InputParameters.HydraulicBoundaryLocation = location;
+ return true;
+ }
+
+ return false;
+ }
+
+ private bool TryReadDikeProfile(string dikeProfileId, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (dikeProfileId != null)
+ {
+ DikeProfile dikeProfile = availableDikeProfiles.FirstOrDefault(fp => fp.Id == dikeProfileId);
+
+ if (dikeProfile == null)
+ {
+ Log.LogCalculationConversionError(string.Format(
+ Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ReadDikeProfile_DikeProfile_0_does_not_exist,
+ dikeProfileId),
+ calculation.Name);
+
+ return false;
+ }
+
+ calculation.InputParameters.DikeProfile = dikeProfile;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Reads the orientation.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ /// false when the orientation is invalid or when there is an orientation but
+ /// no dike profile defined, true otherwise.
+ private bool TryReadOrientation(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (readCalculation.Orientation.HasValue)
+ {
+ if (calculation.InputParameters.DikeProfile == null)
+ {
+ Log.LogCalculationConversionError(Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ValidateWaveReduction_No_DikeProfile_provided_for_Orientation,
+ calculation.Name);
+
+ return false;
+ }
+
+ double orientation = readCalculation.Orientation.Value;
+
+ try
+ {
+ calculation.InputParameters.Orientation = (RoundedDouble) orientation;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ Log.LogOutOfRangeException(string.Format(Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ReadOrientation_Orientation_0_invalid, orientation),
+ calculation.Name,
+ e);
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ ///
+ /// Reads the wave reduction parameters.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ /// false when there is an invalid wave reduction parameter defined, true otherwise.
+ private bool TryReadWaveReduction(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (!ValidateWaveReduction(readCalculation, calculation))
+ {
+ return false;
+ }
+
+ if (readCalculation.UseForeshore.HasValue)
+ {
+ calculation.InputParameters.UseForeshore = readCalculation.UseForeshore.Value;
+ }
+
+ if (readCalculation.UseBreakWater.HasValue)
+ {
+ calculation.InputParameters.UseBreakWater = readCalculation.UseBreakWater.Value;
+ }
+
+ if (readCalculation.BreakWaterType.HasValue)
+ {
+ calculation.InputParameters.BreakWater.Type = (BreakWaterType) readCalculation.BreakWaterType.Value;
+ }
+
+ if (readCalculation.BreakWaterHeight.HasValue)
+ {
+ calculation.InputParameters.BreakWater.Height = (RoundedDouble) readCalculation.BreakWaterHeight;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Reads the dike height.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ /// false when there is a dike height but no dike profile defined, true otherwise.
+ private bool TryReadDikeHeight(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (readCalculation.DikeHeight.HasValue)
+ {
+ if (calculation.InputParameters.DikeProfile == null)
+ {
+ Log.LogCalculationConversionError(Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ValidateWaveReduction_No_DikeProfile_provided_for_DikeHeight,
+ calculation.Name);
+
+ return false;
+ }
+ calculation.InputParameters.DikeHeight = (RoundedDouble) readCalculation.DikeHeight.Value;
+ }
+ return true;
+ }
+
+ ///
+ /// Reads the dike height calculation type.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ private static void ReadDikeHeightCalculationType(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (readCalculation.DikeHeightCalculationType.HasValue)
+ {
+ calculation.InputParameters.DikeHeightCalculationType = (DikeHeightCalculationType) readCalculation.DikeHeightCalculationType.Value;
+ }
+ }
+
+ ///
+ /// Reads the overtopping rate calculation type.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ private static void ReadOvertoppingRateCalculationType(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (readCalculation.OvertoppingRateCalculationType.HasValue)
+ {
+ calculation.InputParameters.OvertoppingRateCalculationType = (OvertoppingRateCalculationType) readCalculation.OvertoppingRateCalculationType.Value;
+ }
+ }
+
+ ///
+ /// Reads the critical wave reduction.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ /// true if reading all required wave reduction parameters was successful,
+ /// false otherwise.
+ private static bool TryReadCriticalWaveReduction(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ var distribution = (LogNormalDistribution) calculation.InputParameters.CriticalFlowRate.Clone();
+
+ if (!distribution.TrySetDistributionProperties(readCalculation.CriticalFlowRateMean,
+ readCalculation.CriticalFlowRateStandardDeviation,
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.CriticalFlowRateStochastName,
+ calculation.Name))
+ {
+ return false;
+ }
+
+ calculation.InputParameters.CriticalFlowRate = distribution;
+ return true;
+ }
+
+ ///
+ /// Validation to check if the defined wave reduction parameters are valid.
+ ///
+ /// The calculation read from the imported file.
+ /// The calculation to configure.
+ /// false when there is an invalid wave reduction parameter defined, true otherwise.
+ private bool ValidateWaveReduction(ReadGrassCoverErosionInwardsCalculation readCalculation, GrassCoverErosionInwardsCalculation calculation)
+ {
+ if (calculation.InputParameters.DikeProfile == null)
+ {
+ if (readCalculation.UseBreakWater.HasValue
+ || readCalculation.UseForeshore.HasValue
+ || readCalculation.BreakWaterHeight != null
+ || readCalculation.BreakWaterType != null)
+ {
+ Log.LogCalculationConversionError(Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ValidateWaveReduction_No_DikeProfile_provided_for_BreakWater_parameters,
+ calculation.Name);
+
+ return false;
+ }
+ }
+ else if (!calculation.InputParameters.ForeshoreGeometry.Any())
+ {
+ if (readCalculation.UseForeshore.HasValue && readCalculation.UseForeshore.Value)
+ {
+ Log.LogCalculationConversionError(string.Format(
+ Resources.GrassCoverErosionInwardsCalculationConfigurationImporter_ValidateWaveReduction_DikeProfile_0_has_no_geometry_and_cannot_be_used,
+ readCalculation.DikeProfileId),
+ calculation.Name);
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationReader.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationReader.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationReader.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,111 @@
+// Copyright (C) Stichting Deltares 2017. 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.Common.IO.Configurations;
+using Ringtoets.Common.IO.Configurations.Helpers;
+using Ringtoets.Common.IO.Configurations.Import;
+using Ringtoets.GrassCoverErosionInwards.IO.Properties;
+using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Configurations
+{
+ ///
+ /// This class reads a grass cover erosion inwards configuration from XML and creates
+ /// a collection of corresponding , typically
+ /// containing one or more .
+ ///
+ public class GrassCoverErosionInwardsCalculationConfigurationReader : CalculationConfigurationReader
+ {
+ private const string hrLocatieSchemaName = "HrLocatieSchema.xsd";
+ private const string orientatieSchemaName = "OrientatieSchema.xsd";
+ private const string golfReductieSchemaName = "GolfReductieSchema.xsd";
+ private const string stochastSchemaName = "StochastSchema.xsd";
+ private const string stochastStandaardafwijkingSchemaName = "StochastStandaardafwijkingSchema.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 GrassCoverErosionInwardsCalculationConfigurationReader(string xmlFilePath)
+ : base(xmlFilePath,
+ Resources.GEKBConfiguratieSchema,
+ new Dictionary
+ {
+ {
+ hrLocatieSchemaName, RingtoetsCommonIOResources.HrLocatieSchema
+ },
+ {
+ orientatieSchemaName, RingtoetsCommonIOResources.OrientatieSchema
+ },
+ {
+ golfReductieSchemaName, RingtoetsCommonIOResources.GolfReductieSchema
+ },
+ {
+ stochastSchemaName, RingtoetsCommonIOResources.StochastSchema
+ },
+ {
+ stochastStandaardafwijkingSchemaName, RingtoetsCommonIOResources.StochastStandaardafwijkingSchema
+ }
+ }) {}
+
+ protected override ReadGrassCoverErosionInwardsCalculation ParseCalculationElement(XElement calculationElement)
+ {
+ var constructionProperties = new ReadGrassCoverErosionInwardsCalculation.ConstructionProperties
+ {
+ Name = calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute).Value,
+ HydraulicBoundaryLocation = calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement),
+ DikeProfileId = calculationElement.GetStringValueFromDescendantElement(GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeProfileElement),
+ Orientation = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.Orientation),
+ DikeHeight = calculationElement.GetDoubleValueFromDescendantElement(GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightElement),
+ DikeHeightCalculationType = (ReadHydraulicLoadsCalculationType?) calculationElement.GetConvertedValueFromDescendantStringElement(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightCalculationTypeElement),
+ OvertoppingRateCalculationType = (ReadHydraulicLoadsCalculationType?) calculationElement.GetConvertedValueFromDescendantStringElement(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.OvertoppingRateCalculationTypeElement),
+ UseBreakWater = calculationElement.GetBoolValueFromDescendantElement(ConfigurationSchemaIdentifiers.UseBreakWater),
+ BreakWaterType = (ConfigurationBreakWaterType?) calculationElement.GetConvertedValueFromDescendantStringElement(ConfigurationSchemaIdentifiers.BreakWaterType),
+ BreakWaterHeight = calculationElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.BreakWaterHeight),
+ UseForeshore = calculationElement.GetBoolValueFromDescendantElement(ConfigurationSchemaIdentifiers.UseForeshore)
+ };
+
+ XElement criticalFlowRateElement = calculationElement.GetStochastElement(GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.CriticalFlowRateStochastName);
+ if (criticalFlowRateElement != null)
+ {
+ constructionProperties.CriticalFlowRateMean = criticalFlowRateElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.MeanElement);
+ constructionProperties.CriticalFlowRateStandardDeviation = criticalFlowRateElement.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.StandardDeviationElement);
+ }
+
+ return new ReadGrassCoverErosionInwardsCalculation(constructionProperties);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,54 @@
+// Copyright (C) Stichting Deltares 2017. 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.GrassCoverErosionInwards.IO.Configurations
+{
+ ///
+ /// Container of identifiers related to the grass cover erosion inwards calculation configuration schema definition.
+ ///
+ internal static class GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers
+ {
+ ///
+ /// The tag of elements containing the name of the dike profile.
+ ///
+ public const string DikeProfileElement = "dijkprofiel";
+
+ ///
+ /// The name for the critical flow rate stochast.
+ ///
+ public const string CriticalFlowRateStochastName = "overslagdebiet";
+
+ ///
+ /// The identifier for the dike height elements.
+ ///
+ internal const string DikeHeightElement = "dijkhoogte";
+
+ ///
+ /// The identifier for the dike height calculation type elements.
+ ///
+ internal const string DikeHeightCalculationTypeElement = "hbnberekenen";
+
+ ///
+ /// The identifier for the overtopping rate calculation type elements.
+ ///
+ internal const string OvertoppingRateCalculationTypeElement = "overslagdebietberekenen";
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriter.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,152 @@
+// Copyright (C) Stichting Deltares 2017. 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.Xml;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.IO.Configurations;
+using Ringtoets.Common.IO.Configurations.Export;
+using Ringtoets.GrassCoverErosionInwards.Data;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Configurations
+{
+ ///
+ /// Writer for writing a grass cover erosion inwards calculation configuration to XML.
+ ///
+ public class GrassCoverErosionInwardsCalculationConfigurationWriter : CalculationConfigurationWriter
+ {
+ protected override void WriteCalculation(GrassCoverErosionInwardsCalculation calculation, XmlWriter writer)
+ {
+ writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement);
+ writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculation.Name);
+
+ GrassCoverErosionInwardsInput input = calculation.InputParameters;
+
+ WriteHydraulicBoundaryLocation(input, writer);
+
+ WriteDikeProfileId(input, writer);
+
+ WriteOrientation(input, writer);
+
+ WriteDikeHeight(input, writer);
+
+ writer.WriteElementString(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightCalculationTypeElement,
+ HydraulicLoadsCalculationTypeAsXmlString((ReadHydraulicLoadsCalculationType) input.DikeHeightCalculationType));
+
+ writer.WriteElementString(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.OvertoppingRateCalculationTypeElement,
+ HydraulicLoadsCalculationTypeAsXmlString((ReadHydraulicLoadsCalculationType) input.OvertoppingRateCalculationType));
+
+ WriteWaveReduction(input, writer);
+
+ WriteDistributions(CreateInputDistributions(input), writer);
+
+ writer.WriteEndElement();
+ }
+
+ private static void WriteHydraulicBoundaryLocation(GrassCoverErosionInwardsInput input, XmlWriter writer)
+ {
+ if (input.HydraulicBoundaryLocation == null)
+ {
+ return;
+ }
+
+ writer.WriteElementString(
+ ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement,
+ input.HydraulicBoundaryLocation.Name);
+ }
+
+ private static void WriteDikeProfileId(GrassCoverErosionInwardsInput input, XmlWriter writer)
+ {
+ if (input.DikeProfile == null)
+ {
+ return;
+ }
+
+ writer.WriteElementString(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeProfileElement,
+ input.DikeProfile.Id);
+ }
+
+ private static void WriteOrientation(GrassCoverErosionInwardsInput input, XmlWriter writer)
+ {
+ if (input.DikeProfile == null)
+ {
+ return;
+ }
+
+ writer.WriteElementString(
+ ConfigurationSchemaIdentifiers.Orientation,
+ XmlConvert.ToString(input.Orientation));
+ }
+
+ private static void WriteDikeHeight(GrassCoverErosionInwardsInput input, XmlWriter writer)
+ {
+ if (input.DikeProfile == null)
+ {
+ return;
+ }
+
+ writer.WriteElementString(
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightElement,
+ XmlConvert.ToString(input.DikeHeight));
+ }
+
+ private static string HydraulicLoadsCalculationTypeAsXmlString(ReadHydraulicLoadsCalculationType type)
+ {
+ return new ReadHydraulicLoadsCalculationTypeConverter().ConvertToInvariantString(type);
+ }
+
+ private static void WriteWaveReduction(GrassCoverErosionInwardsInput input, XmlWriter writer)
+ {
+ if (input.DikeProfile == null)
+ {
+ return;
+ }
+
+ writer.WriteStartElement(ConfigurationSchemaIdentifiers.WaveReduction);
+
+ writer.WriteElementString(
+ ConfigurationSchemaIdentifiers.UseBreakWater,
+ XmlConvert.ToString(input.UseBreakWater));
+
+ WriteBreakWaterProperties(input.BreakWater, writer);
+
+ writer.WriteElementString(
+ ConfigurationSchemaIdentifiers.UseForeshore,
+ XmlConvert.ToString(input.UseForeshore));
+
+ writer.WriteEndElement();
+ }
+
+ private static IDictionary CreateInputDistributions(GrassCoverErosionInwardsInput calculationInputParameters)
+ {
+ return new Dictionary
+ {
+ {
+ GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.CriticalFlowRateStochastName,
+ calculationInputParameters.CriticalFlowRate
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Importers/GrassCoverErosionInwardsCalculationConfigurationImporter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Readers/GrassCoverErosionInwardsCalculationConfigurationReader.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Readers/ReadGrassCoverErosionInwardsCalculation.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj
===================================================================
diff -u -r26f49ad2e6873ad9dace912e6d40b32fd8e89e6d -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 26f49ad2e6873ad9dace912e6d40b32fd8e89e6d)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -46,19 +46,19 @@
Properties\GlobalAssembly.cs
-
-
-
+
+
+
-
+ TrueTrueResources.resx
-
-
+
+
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Writers/GrassCoverErosionInwardsCalculationConfigurationWriter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs
===================================================================
diff -u -re402805257d7185512020535bd0df9cd01a7734e -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision e402805257d7185512020535bd0df9cd01a7734e)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -50,8 +50,7 @@
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses;
using Ringtoets.GrassCoverErosionInwards.Forms.Views;
-using Ringtoets.GrassCoverErosionInwards.IO.Exporters;
-using Ringtoets.GrassCoverErosionInwards.IO.Importers;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters;
using Ringtoets.GrassCoverErosionInwards.Plugin.Properties;
using Ringtoets.GrassCoverErosionInwards.Service;
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,85 @@
+// Copyright (C) Stichting Deltares 2017. 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.IO;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.IO.TestUtil;
+using Ringtoets.GrassCoverErosionInwards.Data;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationExporterTest
+ : CustomCalculationConfigurationExporterDesignGuidelinesTestFixture<
+ GrassCoverErosionInwardsCalculationConfigurationExporter,
+ GrassCoverErosionInwardsCalculationConfigurationWriter,
+ GrassCoverErosionInwardsCalculation>
+ {
+ [Test]
+ public void Export_ValidData_ReturnTrueAndWritesFile()
+ {
+ // Setup
+ var calculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1"
+ };
+ var calculation2 = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 2"
+ };
+
+ var calculationGroup2 = new CalculationGroup("Nested", false)
+ {
+ Children =
+ {
+ calculation2
+ }
+ };
+
+ var calculationGroup = new CalculationGroup("Testmap", false)
+ {
+ Children =
+ {
+ calculation,
+ calculationGroup2
+ }
+ };
+
+ string expectedXmlFilePath = TestHelper.GetTestDataPath(
+ TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationExporter), "folderWithSubfolderAndCalculation.xml"));
+
+ // Call and Assert
+ WriteAndValidate(new[]
+ {
+ calculationGroup
+ }, expectedXmlFilePath);
+ }
+
+ protected override GrassCoverErosionInwardsCalculation CreateCalculation()
+ {
+ return new GrassCoverErosionInwardsCalculation();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporterTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporterTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationImporterTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,631 @@
+// Copyright (C) Stichting Deltares 2017. 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.IO;
+using System.Linq;
+using Core.Common.Base.Data;
+using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.DikeProfiles;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.Common.IO.Configurations.Import;
+using Ringtoets.GrassCoverErosionInwards.Data;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationImporterTest
+ {
+ private readonly string path = TestHelper.GetTestDataPath(
+ TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ nameof(GrassCoverErosionInwardsCalculationConfigurationImporter));
+
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ "",
+ new CalculationGroup(),
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Assert
+ Assert.IsInstanceOf<
+ CalculationConfigurationImporter<
+ GrassCoverErosionInwardsCalculationConfigurationReader,
+ ReadGrassCoverErosionInwardsCalculation>>(importer);
+ }
+
+ [Test]
+ public void Constructor_HydraulicBoundaryLocationsNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ "",
+ new CalculationGroup(),
+ null,
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("hydraulicBoundaryLocations", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_DikeProfilesNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ "",
+ new CalculationGroup(),
+ Enumerable.Empty(),
+ null,
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("dikeProfiles", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_FailureMechanismNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ "",
+ new CalculationGroup(),
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void Import_ValidConfigurationInvalidOrientation_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationOrientationOutOfRange.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ new[]
+ {
+ new TestDikeProfile("Dijkprofiel", "Dijkprofiel ID")
+ },
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Een waarde van '380' als oriëntatie is ongeldig. De waarde voor de oriëntatie moet in het bereik [0,00, 360,00] liggen. " +
+ "Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void Import_ValidConfigurationInvalidCriticalWaveReductionMean_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationNegativeCriticalWaveReductionMean.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Een gemiddelde van '-1' is ongeldig voor stochast 'overslagdebiet'. " +
+ "Gemiddelde moet groter zijn dan 0. " +
+ "Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ public void Import_ValidConfigurationInvalidCriticalWaveReductionStandardDeviation_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationNegativeCriticalWaveReductionStandardDeviation.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Een standaardafwijking van '-2,1' is ongeldig voor stochast 'overslagdebiet'. " +
+ "Standaardafwijking (σ) moet groter zijn dan of gelijk zijn aan 0. " +
+ "Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_HydraulicBoundaryLocationUnknown_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationUnknownHydraulicBoundaryLocation.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "De locatie met hydraulische randvoorwaarden 'HRlocatie' bestaat niet. Berekening 'Calculation' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_DikeProfileUnknown_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationUnknownDikeProfile.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Het dijkprofiel met ID 'Dijkprofiel' bestaat niet. Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_WaveReductionWithoutDikeProfile_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationWaveReductionWithoutDikeProfile.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Er is geen dijkprofiel opgegeven om golfreductie parameters aan toe te voegen. Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_DikeHeightWithoutDikeProfile_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationDikeHeightWithoutDikeProfile.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Er is geen dijkprofiel opgegeven om de dijkhoogte aan toe te voegen. Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_OrientationWithoutDikeProfile_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationOrientationWithoutDikeProfile.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Er is geen dijkprofiel opgegeven om de oriëntatie aan toe te voegen. Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_UseForeshoreButProfileWithoutGeometry_LogMessageAndContinueImport()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationUseForeshoreWithoutGeometry.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var dikeProfile = new TestDikeProfile("Dijkprofiel", "Dijkprofiel ID");
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ new[]
+ {
+ dikeProfile
+ },
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ var successful = false;
+ Action call = () => successful = importer.Import();
+
+ // Assert
+ const string expectedMessage = "Het opgegeven dijkprofiel 'Dijkprofiel ID' heeft geen voorlandgeometrie en kan daarom niet gebruikt worden. Berekening 'Berekening 1' is overgeslagen.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsTrue(successful);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ }
+
+ [Test]
+ public void Import_ValidConfigurationWithoutForeshoreProfileNotUsed_DataAddedToModel()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCalculationNotUseForeshoreWithoutGeometry.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HRlocatie", 10, 20);
+ var dikeProfile = new TestDikeProfile("Dijkprofiel", "Dijkprofiel ID");
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ new[]
+ {
+ hydraulicBoundaryLocation
+ },
+ new[]
+ {
+ dikeProfile
+ },
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ bool successful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(successful);
+
+ var expectedCalculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1",
+ InputParameters =
+ {
+ DikeProfile = dikeProfile
+ }
+ };
+
+ Assert.AreEqual(1, calculationGroup.Children.Count);
+ AssertCalculation(expectedCalculation, (GrassCoverErosionInwardsCalculation) calculationGroup.Children[0]);
+ }
+
+ [Test]
+ public void Import_ValidConfigurationOnlyCriticalFlowRateMeanSet_DataAddedToModel()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCriticalFlowRateMeanOnly.xml");
+
+ var calculationGroup = new CalculationGroup();
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ bool successful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(successful);
+
+ var expectedCalculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1",
+ InputParameters =
+ {
+ CriticalFlowRate =
+ {
+ Mean = (RoundedDouble) 2.0
+ }
+ }
+ };
+
+ Assert.AreEqual(1, calculationGroup.Children.Count);
+ AssertCalculation(expectedCalculation, (GrassCoverErosionInwardsCalculation) calculationGroup.Children[0]);
+ }
+
+ [Test]
+ public void Import_ValidConfigurationOnlyCriticalFlowRateNoParametersSet_DataAddedToModel()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCriticalFlowRateNoParameters.xml");
+
+ var calculationGroup = new CalculationGroup();
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ bool successful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(successful);
+
+ var expectedCalculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1"
+ };
+
+ Assert.AreEqual(1, calculationGroup.Children.Count);
+ AssertCalculation(expectedCalculation, (GrassCoverErosionInwardsCalculation) calculationGroup.Children[0]);
+ }
+
+ [Test]
+ public void Import_ValidConfigurationOnlyCriticalFlowRateStandardDeviationSet_DataAddedToModel()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationCriticalFlowRateStandardDeviationOnly.xml");
+
+ var calculationGroup = new CalculationGroup();
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ bool successful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(successful);
+
+ var expectedCalculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1",
+ InputParameters =
+ {
+ CriticalFlowRate =
+ {
+ StandardDeviation = (RoundedDouble) 1.1
+ }
+ }
+ };
+
+ Assert.AreEqual(1, calculationGroup.Children.Count);
+ AssertCalculation(expectedCalculation, (GrassCoverErosionInwardsCalculation) calculationGroup.Children[0]);
+ }
+
+ [Test]
+ public void Import_ValidConfigurationWithValidData_DataAddedToModel()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationFullCalculation.xml");
+
+ var calculationGroup = new CalculationGroup();
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HRlocatie", 10, 20);
+ var dikeProfile = new DikeProfile(new Point2D(0, 0), new[]
+ {
+ new RoughnessPoint(new Point2D(0, 0), 2.1),
+ new RoughnessPoint(new Point2D(1, 1), 3.9),
+ new RoughnessPoint(new Point2D(2, 2), 5.2)
+ }, new[]
+ {
+ new Point2D(1, 0),
+ new Point2D(3, 4),
+ new Point2D(6, 5)
+ }, new BreakWater(BreakWaterType.Caisson, 0), new DikeProfile.ConstructionProperties
+ {
+ Id = "Dijkprofiel ID",
+ Name = "Dijkprofiel",
+ DikeHeight = 3.45
+ });
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ new[]
+ {
+ hydraulicBoundaryLocation
+ },
+ new[]
+ {
+ dikeProfile
+ },
+ new GrassCoverErosionInwardsFailureMechanism());
+
+ // Call
+ bool successful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(successful);
+
+ var expectedCalculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = hydraulicBoundaryLocation,
+ DikeProfile = dikeProfile,
+ DikeHeightCalculationType = DikeHeightCalculationType.CalculateByAssessmentSectionNorm,
+ OvertoppingRateCalculationType = OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability,
+ Orientation = (RoundedDouble) 5.5,
+ UseForeshore = true,
+ UseBreakWater = true,
+ BreakWater =
+ {
+ Height = (RoundedDouble) 6.6,
+ Type = BreakWaterType.Caisson
+ },
+ CriticalFlowRate =
+ {
+ Mean = (RoundedDouble) 2.0,
+ StandardDeviation = (RoundedDouble) 1.1
+ }
+ }
+ };
+
+ Assert.AreEqual(1, calculationGroup.Children.Count);
+ AssertCalculation(expectedCalculation, (GrassCoverErosionInwardsCalculation) calculationGroup.Children[0]);
+ }
+
+ [Test]
+ public void DoPostImport_CalculationWithDikeProfileInSection_AssignsCalculationToSectionResult()
+ {
+ // Setup
+ string filePath = Path.Combine(path, "validConfigurationFullCalculation.xml");
+ var calculationGroup = new CalculationGroup();
+
+ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
+
+ failureMechanism.AddSection(new FailureMechanismSection("name", new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(10, 10)
+ }));
+
+ var calculation = new GrassCoverErosionInwardsCalculation
+ {
+ InputParameters =
+ {
+ DikeProfile = new TestDikeProfile(new Point2D(5, 5))
+ }
+ };
+ failureMechanism.CalculationsGroup.Children.Add(
+ calculation);
+
+ var importer = new GrassCoverErosionInwardsCalculationConfigurationImporter(
+ filePath,
+ calculationGroup,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ failureMechanism);
+
+ // Preconditions
+ Assert.AreEqual(1, failureMechanism.SectionResults.Count());
+ Assert.IsNull(failureMechanism.SectionResults.ElementAt(0).Calculation);
+
+ // Call
+ importer.DoPostImport();
+
+ // Assert
+ Assert.AreSame(calculation, failureMechanism.SectionResults.ElementAt(0).Calculation);
+ }
+
+ private static void AssertCalculation(GrassCoverErosionInwardsCalculation expectedCalculation, GrassCoverErosionInwardsCalculation actualCalculation)
+ {
+ Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name);
+ Assert.AreSame(expectedCalculation.InputParameters.HydraulicBoundaryLocation, actualCalculation.InputParameters.HydraulicBoundaryLocation);
+ Assert.AreEqual(expectedCalculation.InputParameters.Orientation, actualCalculation.InputParameters.Orientation);
+ Assert.AreEqual(expectedCalculation.InputParameters.DikeProfile, actualCalculation.InputParameters.DikeProfile);
+ Assert.AreEqual(expectedCalculation.InputParameters.DikeHeightCalculationType, actualCalculation.InputParameters.DikeHeightCalculationType);
+ Assert.AreEqual(expectedCalculation.InputParameters.OvertoppingRateCalculationType, actualCalculation.InputParameters.OvertoppingRateCalculationType);
+ Assert.AreEqual(expectedCalculation.InputParameters.DikeHeight, actualCalculation.InputParameters.DikeHeight);
+ Assert.AreEqual(expectedCalculation.InputParameters.UseForeshore, actualCalculation.InputParameters.UseForeshore);
+ Assert.AreEqual(expectedCalculation.InputParameters.UseBreakWater, actualCalculation.InputParameters.UseBreakWater);
+ Assert.AreEqual(expectedCalculation.InputParameters.BreakWater.Height, actualCalculation.InputParameters.BreakWater.Height);
+ Assert.AreEqual(expectedCalculation.InputParameters.BreakWater.Type, actualCalculation.InputParameters.BreakWater.Type);
+ DistributionAssert.AreEqual(expectedCalculation.InputParameters.CriticalFlowRate, actualCalculation.InputParameters.CriticalFlowRate);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationReaderTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationReaderTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationReaderTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,425 @@
+// Copyright (C) Stichting Deltares 2017. 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.Common.IO.Configurations;
+using Ringtoets.Common.IO.Configurations.Import;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationReaderTest
+ {
+ private readonly string testDirectoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ nameof(GrassCoverErosionInwardsCalculationConfigurationReader));
+
+ private static IEnumerable InvalidConfigurations
+ {
+ get
+ {
+ yield return new TestCaseData("invalidHydraulicBoundaryLocationEmpty.xml",
+ "The 'hrlocatie' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.")
+ .SetName("invalidHydraulicBoundaryLocationEmpty");
+ yield return new TestCaseData("invalidMultipleHydraulicBoundaryLocations.xml",
+ "Element 'hrlocatie' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleHydraulicBoundaryLocations");
+
+ yield return new TestCaseData("invalidDikeProfileEmpty.xml",
+ "The 'dijkprofiel' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.")
+ .SetName("invalidDikeProfileEmpty");
+ yield return new TestCaseData("invalidMultipleDikeProfiles.xml",
+ "Element 'dijkprofiel' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleDikeProfiles");
+
+ yield return new TestCaseData("invalidOrientationEmpty.xml",
+ "The 'orientatie' element is invalid - The value '' is invalid according to its datatype 'Double'")
+ .SetName("invalidOrientationEmpty");
+ yield return new TestCaseData("invalidOrientationNoDouble.xml",
+ "The 'orientatie' element is invalid - The value 'string' is invalid according to its datatype 'Double'")
+ .SetName("invalidOrientationNoDouble");
+ yield return new TestCaseData("invalidMultipleOrientation.xml",
+ "Element 'orientatie' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleOrientation");
+
+ yield return new TestCaseData("invalidDikeHeightEmpty.xml",
+ "The 'dijkhoogte' element is invalid - The value '' is invalid according to its datatype 'Double'")
+ .SetName("invalidDikeHeightEmpty");
+ yield return new TestCaseData("invalidDikeHeightNoDouble.xml",
+ "The 'dijkhoogte' element is invalid - The value 'string' is invalid according to its datatype 'Double'")
+ .SetName("invalidDikeHeightNoDouble");
+ yield return new TestCaseData("invalidMultipleDikeHeight.xml",
+ "Element 'dijkhoogte' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleDikeHeight");
+
+ yield return new TestCaseData("invalidDikeHeightCalculationTypeEmpty.xml",
+ "The 'hbnberekenen' element is invalid - The value '' is invalid according to its datatype 'String' - The Enumeration constraint failed.")
+ .SetName("invalidDikeHeightCalculationTypeEmpty");
+ yield return new TestCaseData("invalidMultipleDikeHeightCalculationTypes.xml",
+ "Element 'hbnberekenen' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleDikeHeightCalculationTypes");
+ yield return new TestCaseData("invalidDikeHeightCalculationTypeUnsupportedString.xml",
+ "The 'hbnberekenen' element is invalid - The value 'invalid' is invalid according to its datatype 'String' - The Enumeration constraint failed.")
+ .SetName("invalidDikeHeightCalculationTypeUnsupportedString");
+
+ yield return new TestCaseData("invalidOvertoppingRateCalculationTypeEmpty.xml",
+ "The 'overslagdebietberekenen' element is invalid - The value '' is invalid according to its datatype 'String' - The Enumeration constraint failed.")
+ .SetName("invalidOvertoppingRateCalculationTypeEmpty");
+ yield return new TestCaseData("invalidMultipleOvertoppingRateCalculationTypes.xml",
+ "Element 'overslagdebietberekenen' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleOvertoppingRateCalculationTypes");
+ yield return new TestCaseData("invalidOvertoppingRateCalculationTypeUnsupportedString.xml",
+ "The 'overslagdebietberekenen' element is invalid - The value 'invalid' is invalid according to its datatype 'String' - The Enumeration constraint failed.")
+ .SetName("invalidOvertoppingRateCalculationTypeUnsupportedString");
+
+ 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("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");
+
+ yield return new TestCaseData("invalidMultipleCriticalFlowRateStochast.xml",
+ "There is a duplicate key sequence 'overslagdebiet' for the 'uniqueStochastNameConstraint' key or unique identity constraint.")
+ .SetName("invalidMultipleCriticalFlowRateStochast");
+
+ yield return new TestCaseData("invalidCriticalFlowRateMeanEmpty.xml",
+ "The 'verwachtingswaarde' element is invalid - The value '' is invalid according to its datatype 'Double'")
+ .SetName("invalidCriticalFlowRateMeanEmpty");
+ yield return new TestCaseData("invalidCriticalFlowRateMeanNoDouble.xml",
+ "The 'verwachtingswaarde' element is invalid - The value 'string' is invalid according to its datatype 'Double'")
+ .SetName("invalidCriticalFlowRateMeanNoDouble");
+ yield return new TestCaseData("invalidMultipleCriticalFlowRateMean.xml",
+ "Element 'verwachtingswaarde' cannot appear more than once if content model type is \"all\"")
+ .SetName("invalidMultipleCriticalFlowRateMean");
+
+ yield return new TestCaseData("invalidCriticalFlowRateStandardDeviationEmpty.xml",
+ "The 'standaardafwijking' element is invalid - The value '' is invalid according to its datatype 'Double'")
+ .SetName("invalidCriticalFlowRateStandardDeviationEmpty");
+ yield return new TestCaseData("invalidCriticalFlowRateStandardDeviationNoDouble.xml",
+ "The 'standaardafwijking' element is invalid - The value 'string' is invalid according to its datatype 'Double'")
+ .SetName("invalidCriticalFlowRateStandardDeviationNoDouble");
+ yield return new TestCaseData("invalidMultipleCriticalFlowRateStandardDeviation.xml",
+ "Element 'standaardafwijking' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleCriticalFlowRateStandardDeviation");
+
+ 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 'unsupported' is invalid according to its datatype 'nameType' - The Enumeration constraint failed.")
+ .SetName("invalidStochastUnknownName");
+ yield return new TestCaseData("invalidMultipleStochasts.xml",
+ "Element 'stochasten' cannot appear more than once if content model type is \"all\".")
+ .SetName("invalidMultipleStochasts");
+ }
+ }
+
+ [Test]
+ [TestCaseSource(nameof(InvalidConfigurations))]
+ public void Constructor_FileInvalidBasedOnSchemaDefinition_ThrowCriticalFileReadException(string fileName, string expectedParsingMessage)
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, fileName);
+
+ // Call
+ TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.IsInstanceOf(exception.InnerException);
+ StringAssert.Contains(expectedParsingMessage, exception.InnerException?.Message);
+ }
+
+ [Test]
+ public void Constructor_ValidConfiguration_ExpectedValues()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationEmptyCalculation.xml");
+
+ // Call
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Assert
+ Assert.IsInstanceOf>(reader);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithEmptyCalculation_ReturnExpectedReadCalculation()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationEmptyCalculation.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.AreEqual("Calculation", calculation.Name);
+ Assert.IsNull(calculation.HydraulicBoundaryLocation);
+ Assert.IsNull(calculation.DikeProfileId);
+ Assert.IsNull(calculation.Orientation);
+ Assert.IsNull(calculation.DikeHeight);
+ Assert.IsNull(calculation.DikeHeightCalculationType);
+ Assert.IsNull(calculation.OvertoppingRateCalculationType);
+ Assert.IsNull(calculation.UseBreakWater);
+ Assert.IsNull(calculation.BreakWaterType);
+ Assert.IsNull(calculation.BreakWaterHeight);
+ Assert.IsNull(calculation.UseForeshore);
+ Assert.IsNull(calculation.CriticalFlowRateMean);
+ Assert.IsNull(calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithCalculationContainingEmptyStochasts_ReturnExpectedReadCalculation()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationCalculationContainingEmptyStochasts.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.IsNull(calculation.CriticalFlowRateMean);
+ Assert.IsNull(calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithCalculationContainingNaNs_ReturnExpectedReadCalculation()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationCalculationContainingNaNs.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.IsNaN(calculation.Orientation);
+ Assert.IsNaN(calculation.DikeHeight);
+ Assert.IsNaN(calculation.BreakWaterHeight);
+ Assert.IsNaN(calculation.CriticalFlowRateMean);
+ Assert.IsNaN(calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithCalculationContainingInfinities_ReturnExpectedReadCalculation()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationCalculationContainingInfinities.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+
+ Assert.IsNotNull(calculation.Orientation);
+ Assert.IsNotNull(calculation.DikeHeight);
+ Assert.IsNotNull(calculation.BreakWaterHeight);
+ Assert.IsNotNull(calculation.CriticalFlowRateMean);
+ Assert.IsNotNull(calculation.CriticalFlowRateStandardDeviation);
+
+ Assert.IsTrue(double.IsPositiveInfinity(calculation.Orientation.Value));
+ Assert.IsTrue(double.IsNegativeInfinity(calculation.DikeHeight.Value));
+ Assert.IsTrue(double.IsNegativeInfinity(calculation.BreakWaterHeight.Value));
+ Assert.IsTrue(double.IsPositiveInfinity(calculation.CriticalFlowRateMean.Value));
+ Assert.IsTrue(double.IsPositiveInfinity(calculation.CriticalFlowRateStandardDeviation.Value));
+ }
+
+ [Test]
+ [TestCase("validConfigurationFullCalculation.xml",
+ TestName = "Read_ValidConfigurationWithFullCalculation_ReturnExpectedReadCalculation(FullCalculation)")]
+ [TestCase("validConfigurationFullCalculation_differentOrder.xml",
+ TestName = "Read_ValidConfigurationWithFullCalculation_ReturnExpectedReadCalculation(FullCalculation_differentOrder)")]
+ public void Read_ValidConfigurationWithFullCalculation_ReturnExpectedReadCalculation(string fileName)
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, fileName);
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.AreEqual("Berekening 1", calculation.Name);
+ Assert.AreEqual("Some_hydraulic_boundary_location", calculation.HydraulicBoundaryLocation);
+ Assert.AreEqual("some_dike_profile", calculation.DikeProfileId);
+ Assert.AreEqual(67.1, calculation.Orientation);
+ Assert.AreEqual(3.45, calculation.DikeHeight);
+ Assert.AreEqual(ReadHydraulicLoadsCalculationType.CalculateByAssessmentSectionNorm, calculation.DikeHeightCalculationType);
+ Assert.AreEqual(ReadHydraulicLoadsCalculationType.CalculateByProfileSpecificRequiredProbability, calculation.OvertoppingRateCalculationType);
+ Assert.AreEqual(true, calculation.UseBreakWater);
+ Assert.AreEqual(ConfigurationBreakWaterType.Dam, calculation.BreakWaterType);
+ Assert.AreEqual(1.234, calculation.BreakWaterHeight);
+ Assert.AreEqual(false, calculation.UseForeshore);
+ Assert.AreEqual(0.1, calculation.CriticalFlowRateMean);
+ Assert.AreEqual(0.2, calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithPartialCalculation_ReturnExpectedReadCalculation()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationPartialCalculation.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.AreEqual("Partial calculation 2", calculation.Name);
+ Assert.IsNull(calculation.HydraulicBoundaryLocation);
+ Assert.AreEqual("id_of_dikeprofile", calculation.DikeProfileId);
+ Assert.IsNull(calculation.Orientation);
+ Assert.AreEqual(-1.2, calculation.DikeHeight);
+ Assert.IsNull(calculation.DikeHeightCalculationType);
+ Assert.IsNull(calculation.OvertoppingRateCalculationType);
+ Assert.AreEqual(false, calculation.UseBreakWater);
+ Assert.IsNull(calculation.BreakWaterType);
+ Assert.AreEqual(3.4, calculation.BreakWaterHeight);
+ Assert.IsNull(calculation.UseForeshore);
+ Assert.IsNull(calculation.CriticalFlowRateMean);
+ Assert.IsNull(calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithMissingStochastMean_ExpectedValues()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationCriticalFlowRateMissingMean.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.IsNull(calculation.CriticalFlowRateMean);
+ Assert.AreEqual(2.2, calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithMissingStochastStandardDeviation_ExpectedValues()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationCriticalFlowRateMissingStandardDeviation.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.AreEqual(1.1, calculation.CriticalFlowRateMean);
+ Assert.IsNull(calculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Read_ValidConfigurationWithEmptyStochast_ExpectedValues()
+ {
+ // Setup
+ string filePath = Path.Combine(testDirectoryPath, "validConfigurationEmptyCriticalFlowRate.xml");
+ var reader = new GrassCoverErosionInwardsCalculationConfigurationReader(filePath);
+
+ // Call
+ IList readConfigurationItems = reader.Read().ToList();
+
+ // Assert
+ Assert.AreEqual(1, readConfigurationItems.Count);
+
+ var calculation = readConfigurationItems[0] as ReadGrassCoverErosionInwardsCalculation;
+ Assert.IsNotNull(calculation);
+ Assert.IsNull(calculation.CriticalFlowRateMean);
+ Assert.IsNull(calculation.CriticalFlowRateStandardDeviation);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiersTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiersTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiersTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,41 @@
+// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiersTest
+ {
+ [Test]
+ public void GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers_ExpectedValues()
+ {
+ // Call & Assert
+ Assert.AreEqual("dijkprofiel", GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeProfileElement);
+ Assert.AreEqual("overslagdebiet", GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.CriticalFlowRateStochastName);
+ Assert.AreEqual("dijkhoogte", GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightElement);
+ Assert.AreEqual("hbnberekenen", GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.DikeHeightCalculationTypeElement);
+ Assert.AreEqual("overslagdebietberekenen", GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.OvertoppingRateCalculationTypeElement);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,121 @@
+// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework;
+using Ringtoets.Common.IO.Configurations;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationTest
+ {
+ [Test]
+ public void Constructor_WithoutConstructionProperties_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new ReadGrassCoverErosionInwardsCalculation(null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("constructionProperties", paramName);
+ }
+
+ [Test]
+ public void Constructor_ConstructionPropertiesWithoutValues_PropertiesAreDefault()
+ {
+ // Call
+ var constructionProperties = new ReadGrassCoverErosionInwardsCalculation.ConstructionProperties();
+ var readCalculation = new ReadGrassCoverErosionInwardsCalculation(constructionProperties);
+
+ // Assert
+ Assert.IsInstanceOf(readCalculation);
+ Assert.IsNull(readCalculation.Name);
+ Assert.IsNull(readCalculation.HydraulicBoundaryLocation);
+ Assert.IsNull(readCalculation.DikeProfileId);
+ Assert.IsNull(readCalculation.Orientation);
+ Assert.IsNull(readCalculation.DikeHeight);
+ Assert.IsNull(readCalculation.DikeHeightCalculationType);
+ Assert.IsNull(readCalculation.OvertoppingRateCalculationType);
+ Assert.IsNull(readCalculation.UseBreakWater);
+ Assert.IsNull(readCalculation.BreakWaterType);
+ Assert.IsNull(readCalculation.BreakWaterHeight);
+ Assert.IsNull(readCalculation.UseForeshore);
+ Assert.IsNull(readCalculation.CriticalFlowRateMean);
+ Assert.IsNull(readCalculation.CriticalFlowRateStandardDeviation);
+ }
+
+ [Test]
+ public void Constructor_ConstructionPropertiesWithValuesSet_PropertiesAsExpected()
+ {
+ // Setup
+ const string calculationName = "Name of the calculation";
+ const string hydraulicBoundaryLocationName = "name of the hydraulic boundary location";
+ const string dikeProfileId = "id of the dike profile";
+ const double orientation = 1.1;
+ const double dikeHeight = 2.2;
+ const ReadHydraulicLoadsCalculationType dikeHeightCalculationType = ReadHydraulicLoadsCalculationType.CalculateByAssessmentSectionNorm;
+ const ReadHydraulicLoadsCalculationType overtoppingRateCalculationType = ReadHydraulicLoadsCalculationType.CalculateByProfileSpecificRequiredProbability;
+ const bool useBreakWater = true;
+ const ConfigurationBreakWaterType breakWaterType = ConfigurationBreakWaterType.Wall;
+ const double breakWaterHeight = 3.3;
+ const bool useForeshore = true;
+ const double criticalFlowMean = 4.4;
+ const double critifalFlowStandardDeviation = 5.5;
+
+ var constructionProperties = new ReadGrassCoverErosionInwardsCalculation.ConstructionProperties
+ {
+ Name = calculationName,
+ HydraulicBoundaryLocation = hydraulicBoundaryLocationName,
+ DikeProfileId = dikeProfileId,
+ Orientation = orientation,
+ DikeHeight = dikeHeight,
+ DikeHeightCalculationType = dikeHeightCalculationType,
+ OvertoppingRateCalculationType = overtoppingRateCalculationType,
+ UseBreakWater = useBreakWater,
+ BreakWaterType = breakWaterType,
+ BreakWaterHeight = breakWaterHeight,
+ UseForeshore = useForeshore,
+ CriticalFlowRateMean = criticalFlowMean,
+ CriticalFlowRateStandardDeviation = critifalFlowStandardDeviation
+ };
+
+ // Call
+ var readCalculation = new ReadGrassCoverErosionInwardsCalculation(constructionProperties);
+
+ // Assert
+ Assert.AreEqual(calculationName, readCalculation.Name);
+ Assert.AreEqual(hydraulicBoundaryLocationName, readCalculation.HydraulicBoundaryLocation);
+ Assert.AreEqual(dikeProfileId, constructionProperties.DikeProfileId);
+ Assert.AreEqual(orientation, readCalculation.Orientation);
+ Assert.AreEqual(dikeHeight, readCalculation.DikeHeight);
+ Assert.AreEqual(dikeHeightCalculationType, readCalculation.DikeHeightCalculationType);
+ Assert.AreEqual(overtoppingRateCalculationType, readCalculation.OvertoppingRateCalculationType);
+ Assert.AreEqual(useBreakWater, readCalculation.UseBreakWater);
+ Assert.AreEqual(breakWaterType, readCalculation.BreakWaterType);
+ Assert.AreEqual(breakWaterHeight, readCalculation.BreakWaterHeight);
+ Assert.AreEqual(useForeshore, readCalculation.UseForeshore);
+ Assert.AreEqual(criticalFlowMean, readCalculation.CriticalFlowRateMean);
+ Assert.AreEqual(critifalFlowStandardDeviation, readCalculation.CriticalFlowRateStandardDeviation);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs
===================================================================
diff -u
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 0)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Configurations/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -0,0 +1,193 @@
+// Copyright (C) Stichting Deltares 2017. 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.IO;
+using Core.Common.Base.Data;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.DikeProfiles;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.Common.IO.TestUtil;
+using Ringtoets.GrassCoverErosionInwards.Data;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
+
+namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Configurations
+{
+ [TestFixture]
+ public class GrassCoverErosionInwardsCalculationConfigurationWriterTest
+ : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture<
+ GrassCoverErosionInwardsCalculationConfigurationWriter,
+ GrassCoverErosionInwardsCalculation>
+ {
+ [Test]
+ public void WriteConfiguration_SparseCalculation_WritesSparseConfigurationToFile()
+ {
+ // Setup
+ string filePath = TestHelper.GetScratchPadPath(
+ $"{nameof(WriteConfiguration_SparseCalculation_WritesSparseConfigurationToFile)}.xml");
+
+ string expectedXmlFilePath = TestHelper.GetTestDataPath(
+ TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationWriter), "sparseConfiguration.xml"));
+
+ var calculation = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1"
+ };
+
+ try
+ {
+ var writer = new GrassCoverErosionInwardsCalculationConfigurationWriter();
+
+ // Call
+ writer.Write(new[]
+ {
+ calculation
+ }, filePath);
+
+ // Assert
+ string actualXml = File.ReadAllText(filePath);
+ string expectedXml = File.ReadAllText(expectedXmlFilePath);
+
+ Assert.AreEqual(expectedXml, actualXml);
+ }
+ finally
+ {
+ File.Delete(filePath);
+ }
+ }
+
+ [Test]
+ public void WriteConfiguration_CompleteCalculation_WritesCompleteConfigurationToFile()
+ {
+ // Setup
+ string filePath = TestHelper.GetScratchPadPath(
+ $"{nameof(WriteConfiguration_CompleteCalculation_WritesCompleteConfigurationToFile)}.xml");
+
+ string expectedXmlFilePath = TestHelper.GetTestDataPath(
+ TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationWriter), "completeConfiguration.xml"));
+
+ GrassCoverErosionInwardsCalculation calculation = CreateCompleteCalculation();
+
+ try
+ {
+ var writer = new GrassCoverErosionInwardsCalculationConfigurationWriter();
+
+ // Call
+ writer.Write(new[]
+ {
+ calculation
+ }, filePath);
+
+ // Assert
+ string actualXml = File.ReadAllText(filePath);
+ string expectedXml = File.ReadAllText(expectedXmlFilePath);
+
+ Assert.AreEqual(expectedXml, actualXml);
+ }
+ finally
+ {
+ File.Delete(filePath);
+ }
+ }
+
+ [Test]
+ public void Write_NestedConfiguration_ValidFile()
+ {
+ // Setup
+ string filePath = TestHelper.GetScratchPadPath("test.xml");
+
+ GrassCoverErosionInwardsCalculation calculation = CreateCompleteCalculation();
+ var calculation2 = new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 2"
+ };
+ var calculationGroup2 = new CalculationGroup("Nested", false)
+ {
+ Children =
+ {
+ calculation2
+ }
+ };
+
+ var calculationGroup = new CalculationGroup("Testmap", false)
+ {
+ Children =
+ {
+ calculation,
+ calculationGroup2
+ }
+ };
+
+ try
+ {
+ // Call
+ new GrassCoverErosionInwardsCalculationConfigurationWriter().Write(new[]
+ {
+ calculationGroup
+ }, filePath);
+
+ // Assert
+ Assert.IsTrue(File.Exists(filePath));
+
+ string actualXml = File.ReadAllText(filePath);
+ string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO,
+ Path.Combine("GrassCoverErosionInwardsCalculationConfigurationWriter",
+ "folderWithSubfolderAndCalculation.xml"));
+ string expectedXml = File.ReadAllText(expectedXmlFilePath);
+
+ Assert.AreEqual(expectedXml, actualXml);
+ }
+ finally
+ {
+ File.Delete(filePath);
+ }
+ }
+
+ private static GrassCoverErosionInwardsCalculation CreateCompleteCalculation()
+ {
+ return new GrassCoverErosionInwardsCalculation
+ {
+ Name = "Berekening 1",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"),
+ DikeProfile = new TestDikeProfile("dijkProfiel", "id"),
+ Orientation = (RoundedDouble) 67.1,
+ UseForeshore = true,
+ UseBreakWater = true,
+ BreakWater =
+ {
+ Height = (RoundedDouble) 1.23,
+ Type = BreakWaterType.Caisson
+ },
+ CriticalFlowRate =
+ {
+ Mean = (RoundedDouble) 0.1,
+ StandardDeviation = (RoundedDouble) 0.1
+ }
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiersTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Importers/GrassCoverErosionInwardsCalculationConfigurationImporterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Readers/GrassCoverErosionInwardsCalculationConfigurationReaderTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Readers/ReadGrassCoverErosionInwardsCalculationTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj
===================================================================
diff -u -r8aeff3f1153aaac2b2980ca207e298b6d764947b -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision 8aeff3f1153aaac2b2980ca207e298b6d764947b)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -50,14 +50,14 @@
Properties\GlobalAssembly.cs
-
-
-
-
+
+
+
+
-
-
+
+
Fisheye: Tag 237b9031d74382e26141395ff845d5e43f44981d refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs
===================================================================
diff -u -rc4e2a1db42a818567d116298b5c163b56b69ce0e -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextExportInfoTest.cs) (revision c4e2a1db42a818567d116298b5c163b56b69ce0e)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextExportInfoTest.cs) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -29,7 +29,7 @@
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
-using Ringtoets.GrassCoverErosionInwards.IO.Exporters;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources;
namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ExportInfos
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs
===================================================================
diff -u -rc4e2a1db42a818567d116298b5c163b56b69ce0e -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs) (revision c4e2a1db42a818567d116298b5c163b56b69ce0e)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -30,7 +30,7 @@
using Ringtoets.Common.Data.Calculation;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
-using Ringtoets.GrassCoverErosionInwards.IO.Exporters;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources;
namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ExportInfos
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ImportInfos/GrassCoverErosionInwardsCalculationGroupContextImportInfoTest.cs
===================================================================
diff -u -rc4e2a1db42a818567d116298b5c163b56b69ce0e -r237b9031d74382e26141395ff845d5e43f44981d
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ImportInfos/GrassCoverErosionInwardsCalculationGroupContextImportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextImportInfoTest.cs) (revision c4e2a1db42a818567d116298b5c163b56b69ce0e)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ImportInfos/GrassCoverErosionInwardsCalculationGroupContextImportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextImportInfoTest.cs) (revision 237b9031d74382e26141395ff845d5e43f44981d)
@@ -32,7 +32,7 @@
using Ringtoets.Common.Forms.Properties;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
-using Ringtoets.GrassCoverErosionInwards.IO.Importers;
+using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ImportInfos
{