Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfiguration.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfiguration.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfiguration.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,89 @@ +// 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.MacroStabilityInwards.IO.Configurations +{ + /// + /// Class that represents a macro stability inwards calculation configuration. + /// + public class MacroStabilityInwardsCalculationConfiguration : IConfigurationItem + { + private string name; + + /// + /// Creates a new instance of . + /// + /// The name of the . + /// Thrown when is null. + public MacroStabilityInwardsCalculationConfiguration(string name) + { + Name = name; + } + + /// + /// Gets the assessment level of the calculation. + /// + public double? AssessmentLevel { get; set; } + + /// + /// Gets the name of the hydraulic boundary location of the calculation. + /// + public string HydraulicBoundaryLocation { get; set; } + + /// + /// Gets the name of the surface line of the calculation. + /// + public string SurfaceLine { get; set; } + + /// + /// Gets the name of the stochastic soil model of the calculation. + /// + public string StochasticSoilModel { get; set; } + + /// + /// Gets the name of the stochastic soil profile of the calculation. + /// + public string StochasticSoilProfile { get; set; } + + /// + /// Gets or sets the name for the calculation. + /// + /// Thrown when is null. + public string Name + { + get + { + return name; + } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value), @"Name is required for a structure calculation configuration."); + } + name = value; + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationExporter.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,44 @@ +// 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.MacroStabilityInwards.Data; + +namespace Ringtoets.MacroStabilityInwards.IO.Configurations +{ + /// + /// Exports a macro stability inwards calculation configuration and stores it as an XML file. + /// + public class MacroStabilityInwardsCalculationConfigurationExporter : 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 MacroStabilityInwardsCalculationConfigurationExporter(IEnumerable configuration, string filePath) : base(configuration, filePath) {} + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationImporter.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationImporter.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationImporter.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,241 @@ +// 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.Hydraulics; +using Ringtoets.Common.IO.Configurations.Helpers; +using Ringtoets.Common.IO.Configurations.Import; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.IO.Properties; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.IO.Configurations +{ + /// + /// Imports a macro stability inwards calculation configuration from an XML file and stores it on a + /// . + /// + public class MacroStabilityInwardsCalculationConfigurationImporter : CalculationConfigurationImporter + { + private readonly IEnumerable availableHydraulicBoundaryLocations; + private readonly MacroStabilityInwardsFailureMechanism 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 failure mechanism used to check + /// if the imported objects contain the right data. + /// Thrown when any parameter is + /// null. + public MacroStabilityInwardsCalculationConfigurationImporter(string xmlFilePath, + CalculationGroup importTarget, + IEnumerable availableHydraulicBoundaryLocations, + MacroStabilityInwardsFailureMechanism failureMechanism) + : base(xmlFilePath, importTarget) + { + if (availableHydraulicBoundaryLocations == null) + { + throw new ArgumentNullException(nameof(availableHydraulicBoundaryLocations)); + } + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + this.availableHydraulicBoundaryLocations = availableHydraulicBoundaryLocations; + this.failureMechanism = failureMechanism; + } + + protected override MacroStabilityInwardsCalculationConfigurationReader CreateCalculationConfigurationReader(string xmlFilePath) + { + return new MacroStabilityInwardsCalculationConfigurationReader(xmlFilePath); + } + + protected override ICalculation ParseReadCalculation(MacroStabilityInwardsCalculationConfiguration calculationConfiguration) + { + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = calculationConfiguration.Name + }; + + if (TryReadHydraulicBoundaryData(calculationConfiguration, calculation) + && TryReadSurfaceLine(calculationConfiguration, calculation) + && TryReadStochasticSoilModel(calculationConfiguration, calculation) + && TryReadStochasticSoilProfile(calculationConfiguration, calculation)) + { + return calculation; + } + return null; + } + + /// + /// Reads the hydraulic boundary location or the assessment level that is manually set. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// false when the has a + /// set which is not available in , true otherwise. + private bool TryReadHydraulicBoundaryData(MacroStabilityInwardsCalculationConfiguration calculationConfiguration, MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation) + { + HydraulicBoundaryLocation location; + + bool locationRead = TryReadHydraulicBoundaryLocation(calculationConfiguration.HydraulicBoundaryLocation, calculationConfiguration.Name, availableHydraulicBoundaryLocations, out location); + + if (!locationRead) + { + return false; + } + + if (location != null) + { + macroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation = location; + } + else if (calculationConfiguration.AssessmentLevel.HasValue) + { + macroStabilityInwardsCalculation.InputParameters.UseAssessmentLevelManualInput = true; + macroStabilityInwardsCalculation.InputParameters.AssessmentLevel = (RoundedDouble) calculationConfiguration.AssessmentLevel.Value; + } + + return true; + } + + /// + /// Reads the surface line. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// false when the has a + /// set which is not available in , true otherwise. + private bool TryReadSurfaceLine(MacroStabilityInwardsCalculationConfiguration calculationConfiguration, MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation) + { + if (calculationConfiguration.SurfaceLine != null) + { + RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine = failureMechanism.SurfaceLines + .FirstOrDefault(sl => sl.Name == calculationConfiguration.SurfaceLine); + + if (surfaceLine == null) + { + Log.LogCalculationConversionError(string.Format( + Resources.MacroStabilityInwardsCalculationConfigurationImporter_ReadSurfaceLine_SurfaceLine_0_does_not_exist, + calculationConfiguration.SurfaceLine), + macroStabilityInwardsCalculation.Name); + return false; + } + + macroStabilityInwardsCalculation.InputParameters.SurfaceLine = surfaceLine; + } + return true; + } + + /// + /// Reads the stochastic soil model. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// false when + /// + /// the has a set + /// which is not available in the failure mechanism. + /// The does not intersect with the + /// when this is set. + /// + /// true otherwise. + private bool TryReadStochasticSoilModel(MacroStabilityInwardsCalculationConfiguration calculationConfiguration, MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation) + { + if (calculationConfiguration.StochasticSoilModel != null) + { + StochasticSoilModel soilModel = failureMechanism.StochasticSoilModels + .FirstOrDefault(ssm => ssm.Name == calculationConfiguration.StochasticSoilModel); + + if (soilModel == null) + { + Log.LogCalculationConversionError(string.Format( + Resources.MacroStabilityInwardsCalculationConfigurationImporter_ReadStochasticSoilModel_Stochastische_soil_model_0_does_not_exist, + calculationConfiguration.StochasticSoilModel), + macroStabilityInwardsCalculation.Name); + return false; + } + + if (macroStabilityInwardsCalculation.InputParameters.SurfaceLine != null + && !soilModel.IntersectsWithSurfaceLineGeometry(macroStabilityInwardsCalculation.InputParameters.SurfaceLine)) + { + Log.LogCalculationConversionError(string.Format( + Resources.MacroStabilityInwardsCalculationConfigurationImporter_ReadStochasticSoilModel_Stochastische_soil_model_0_does_not_intersect_with_surfaceLine_1, + calculationConfiguration.StochasticSoilModel, + calculationConfiguration.SurfaceLine), + macroStabilityInwardsCalculation.Name); + return false; + } + + macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel = soilModel; + } + return true; + } + + /// + /// Reads the stochastic soil profile. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// false when the has: + /// + /// a set but no is specified; + /// a set which is not available in the . + /// + /// true otherwise. + private bool TryReadStochasticSoilProfile(MacroStabilityInwardsCalculationConfiguration calculationConfiguration, MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation) + { + if (calculationConfiguration.StochasticSoilProfile != null) + { + if (macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel == null) + { + Log.LogCalculationConversionError(string.Format( + Resources.MacroStabilityInwardsCalculationConfigurationImporter_ReadStochasticSoilProfile_No_soil_model_provided_for_soil_profile_with_name_0, + calculationConfiguration.StochasticSoilProfile), + macroStabilityInwardsCalculation.Name); + return false; + } + + StochasticSoilProfile soilProfile = macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles + .FirstOrDefault(ssp => ssp.SoilProfile.Name == calculationConfiguration.StochasticSoilProfile); + + if (soilProfile == null) + { + Log.LogCalculationConversionError(string.Format( + Resources.MacroStabilityInwardsCalculationConfigurationImporter_ReadStochasticSoilProfile_Stochastic_soil_profile_0_does_not_exist_within_soil_model_1, + calculationConfiguration.StochasticSoilProfile, calculationConfiguration.StochasticSoilModel), + macroStabilityInwardsCalculation.Name); + return false; + } + + macroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile = soilProfile; + } + return true; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationReader.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationReader.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationReader.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,72 @@ +// 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.MacroStabilityInwards.IO.Properties; + +namespace Ringtoets.MacroStabilityInwards.IO.Configurations +{ + /// + /// This class reads a macro stability inwards calculation configuration from XML and creates a collection of corresponding + /// , typically containing one or more . + /// + public class MacroStabilityInwardsCalculationConfigurationReader : CalculationConfigurationReader + { + /// + /// 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. + /// + /// + internal MacroStabilityInwardsCalculationConfigurationReader(string xmlFilePath) + : base(xmlFilePath, + Resources.MacroStabiliteitBinnenwaartsConfiguratieSchema, + new Dictionary()) {} + + protected override MacroStabilityInwardsCalculationConfiguration ParseCalculationElement(XElement calculationElement) + { + var configuration = new MacroStabilityInwardsCalculationConfiguration( + calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute).Value) + { + AssessmentLevel = calculationElement.GetDoubleValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.AssessmentLevelElement), + HydraulicBoundaryLocation = calculationElement.GetStringValueFromDescendantElement(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement), + SurfaceLine = calculationElement.GetStringValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SurfaceLineElement), + StochasticSoilModel = calculationElement.GetStringValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilModelElement), + StochasticSoilProfile = calculationElement.GetStringValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilProfileElement) + }; + + return configuration; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,49 @@ +// 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.MacroStabilityInwards.IO.Configurations +{ + /// + /// Container of identifiers related to the macro stability inwards calculation configuration schema definition. + /// + internal static class MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers + { + /// + /// The identifier for assessment level elements. + /// + internal const string AssessmentLevelElement = "toetspeil"; + + /// + /// The identifier for surface line elements. + /// + internal const string SurfaceLineElement = "profielschematisatie"; + + /// + /// The identifier for stochastic soil model elements. + /// + internal const string StochasticSoilModelElement = "ondergrondmodel"; + + /// + /// The identifier for stochastic soil profile elements. + /// + internal const string StochasticSoilProfileElement = "ondergrondschematisatie"; + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Configurations/MacroStabilityInwardsCalculationConfigurationWriter.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,73 @@ +// 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.Xml; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Export; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Ringtoets.MacroStabilityInwards.IO.Configurations +{ + /// + /// Writer for writing a macro stability inwards calculation configuration to XML. + /// + public class MacroStabilityInwardsCalculationConfigurationWriter : CalculationConfigurationWriter + { + protected override void WriteCalculation(MacroStabilityInwardsCalculation calculation, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculation.Name); + + MacroStabilityInwardsInput calculationInputParameters = calculation.InputParameters; + + if (calculationInputParameters.UseAssessmentLevelManualInput) + { + writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.AssessmentLevelElement, + XmlConvert.ToString(calculationInputParameters.AssessmentLevel)); + } + else if (calculationInputParameters.HydraulicBoundaryLocation != null) + { + writer.WriteElementString(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + calculationInputParameters.HydraulicBoundaryLocation.Name); + } + + if (calculationInputParameters.SurfaceLine != null) + { + writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SurfaceLineElement, + calculationInputParameters.SurfaceLine.Name); + } + + if (calculationInputParameters.StochasticSoilModel != null) + { + writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilModelElement, + calculationInputParameters.StochasticSoilModel.Name); + + if (calculationInputParameters.StochasticSoilProfile?.SoilProfile != null) + { + writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilProfileElement, + calculationInputParameters.StochasticSoilProfile.SoilProfile.Name); + } + } + + writer.WriteEndElement(); + } + } +} \ No newline at end of file Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/MacroStabilityInwardsCalculationConfigurationImporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Readers/MacroStabilityInwardsCalculationConfigurationReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Readers/ReadMacroStabilityInwardsCalculation.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Ringtoets.MacroStabilityInwards.IO.csproj =================================================================== diff -u -r320aceee6e754aa37aa80a80b371a0150cbf2496 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Ringtoets.MacroStabilityInwards.IO.csproj (.../Ringtoets.MacroStabilityInwards.IO.csproj) (revision 320aceee6e754aa37aa80a80b371a0150cbf2496) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Ringtoets.MacroStabilityInwards.IO.csproj (.../Ringtoets.MacroStabilityInwards.IO.csproj) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -51,20 +51,20 @@ - - + + - + True True Resources.resx - - - + + + Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Schema/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -45,7 +45,7 @@ using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; using Ringtoets.MacroStabilityInwards.Forms.PropertyClasses; using Ringtoets.MacroStabilityInwards.Forms.Views; -using Ringtoets.MacroStabilityInwards.IO.Exporters; +using Ringtoets.MacroStabilityInwards.IO.Configurations; using Ringtoets.MacroStabilityInwards.IO.Importers; using Ringtoets.MacroStabilityInwards.Plugin.FileImporter; using Ringtoets.MacroStabilityInwards.Plugin.Properties; Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationExporterTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,94 @@ +// 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.Data.Hydraulics; +using Ringtoets.Common.IO.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Integration.TestUtils; +using Ringtoets.MacroStabilityInwards.IO.Configurations; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationExporterTest + : CustomCalculationConfigurationExporterDesignGuidelinesTestFixture< + MacroStabilityInwardsCalculationConfigurationExporter, + MacroStabilityInwardsCalculationConfigurationWriter, + MacroStabilityInwardsCalculation> + { + [Test] + public void Export_ValidData_ReturnTrueAndWritesFile() + { + // Setup + MacroStabilityInwardsCalculation calculation = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculation(); + + MacroStabilityInwardsCalculation calculation2 = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculation(); + calculation2.Name = "PK001_0002 W1-6_4_1D1"; + calculation2.InputParameters.HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "PUNT_SCH_17", 0, 0); + calculation2.InputParameters.SurfaceLine.Name = "PK001_0002"; + calculation2.InputParameters.StochasticSoilModel = new StochasticSoilModel(1, "PK001_0002_Macrostabiliteit", string.Empty); + calculation2.InputParameters.StochasticSoilProfile = new StochasticSoilProfile(0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new MacroStabilityInwardsSoilProfile("W1-6_4_1D1", 0, new[] + { + new MacroStabilityInwardsSoilLayer(0) + }, SoilProfileType.SoilProfile1D, 0) + }; + + var calculationGroup2 = new CalculationGroup("PK001_0002", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("PK001_0001", false) + { + Children = + { + calculation, + calculationGroup2 + } + }; + + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, + Path.Combine(nameof(MacroStabilityInwardsCalculationConfigurationExporter), + "folderWithSubfolderAndCalculation.xml")); + + // Call and Assert + WriteAndValidate(new[] + { + calculationGroup + }, expectedXmlFilePath); + } + + protected override MacroStabilityInwardsCalculation CreateCalculation() + { + return MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculation(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationImporterTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationImporterTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationImporterTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,377 @@ +// 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.Hydraulics; +using Ringtoets.Common.IO.Configurations.Import; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.IO.Configurations; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationImporterTest + { + private readonly string readerPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, nameof(MacroStabilityInwardsCalculationConfigurationReader)); + private readonly string importerPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, nameof(MacroStabilityInwardsCalculationConfigurationImporter)); + + [Test] + public void Constructor_ExpectedValues() + { + // Call + var importer = new MacroStabilityInwardsCalculationConfigurationImporter("", + new CalculationGroup(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism()); + + // Assert + Assert.IsInstanceOf>(importer); + } + + [Test] + public void Constructor_HydraulicBoundaryLocationsNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new MacroStabilityInwardsCalculationConfigurationImporter("", + new CalculationGroup(), + null, + new MacroStabilityInwardsFailureMechanism()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("availableHydraulicBoundaryLocations", exception.ParamName); + } + + [Test] + public void Constructor_FailureMechanismNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new MacroStabilityInwardsCalculationConfigurationImporter("", + new CalculationGroup(), + Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void Import_HydraulicBoundaryLocationUnknown_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingUnknownHydraulicBoundaryLocation.xml"); + + var calculationGroup = new CalculationGroup(); + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism()); + + // 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_SurfaceLineUnknown_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingUnknownSurfaceLine.xml"); + + var calculationGroup = new CalculationGroup(); + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new HydraulicBoundaryLocation[0], + new MacroStabilityInwardsFailureMechanism()); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "De profielschematisatie 'Profielschematisatie' bestaat niet. Berekening 'Calculation' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + public void Import_StochasticSoilModelUnknown_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingUnknownSoilModel.xml"); + + var calculationGroup = new CalculationGroup(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new HydraulicBoundaryLocation[0], + failureMechanism); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "Het stochastische ondergrondmodel 'Ondergrondmodel' bestaat niet. Berekening 'Calculation' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + public void Import_StochasticSoilModelNotIntersectingWithSurfaceLine_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingNonIntersectingSurfaceLineAndSoilModel.xml"); + + var calculationGroup = new CalculationGroup(); + var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + { + Name = "Profielschematisatie" + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 1.0, 0.0), + new Point3D(2.5, 1.0, 1.0), + new Point3D(5.0, 1.0, 0.0) + }); + var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "readerPath"); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }, "readerPath"); + + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new HydraulicBoundaryLocation[0], + failureMechanism); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "Het stochastische ondergrondmodel 'Ondergrondmodel'doorkruist de profielschematisatie 'Profielschematisatie' niet. Berekening 'Calculation' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + public void Import_StochasticSoilProfileUnknown_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingUnknownSoilProfile.xml"); + + var calculationGroup = new CalculationGroup(); + var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + { + Name = "Profielschematisatie" + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "readerPath"); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }, "readerPath"); + + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new HydraulicBoundaryLocation[0], + failureMechanism); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "De ondergrondschematisatie 'Ondergrondschematisatie' bestaat niet binnen het stochastische ondergrondmodel 'Ondergrondmodel'. Berekening 'Calculation' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + public void Import_StochasticSoilProfileSpecifiedWithoutSoilModel_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(importerPath, "validConfigurationCalculationContainingSoilProfileWithoutSoilModel.xml"); + + var calculationGroup = new CalculationGroup(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new HydraulicBoundaryLocation[0], + failureMechanism); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "Er is geen stochastisch ondergrondmodel opgegeven bij ondergrondschematisatie 'Ondergrondschematisatie'. Berekening 'Calculation' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + [TestCase(false, "validConfigurationFullCalculationContainingHydraulicBoundaryLocation.xml")] + [TestCase(true, "validConfigurationFullCalculationContainingAssessmentLevel.xml")] + public void Import_ValidConfigurationWithValidHydraulicBoundaryData_DataAddedToModel(bool manualAssessmentLevel, string file) + { + // Setup + string filePath = Path.Combine(readerPath, file); + + var calculationGroup = new CalculationGroup(); + var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + { + Name = "Profielschematisatie" + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + var stochasticSoilProfile = new StochasticSoilProfile(0, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new MacroStabilityInwardsSoilProfile("Ondergrondschematisatie", 0, new[] + { + new MacroStabilityInwardsSoilLayer(0) + }, SoilProfileType.SoilProfile1D, 0) + }; + + var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); + stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "readerPath"); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }, "readerPath"); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HRlocatie", 10, 20); + var importer = new MacroStabilityInwardsCalculationConfigurationImporter(filePath, + calculationGroup, + new[] + { + hydraulicBoundaryLocation + }, + failureMechanism); + + // Call + bool successful = importer.Import(); + + // Assert + Assert.IsTrue(successful); + + var expectedCalculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation", + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + UseAssessmentLevelManualInput = manualAssessmentLevel, + SurfaceLine = surfaceLine, + StochasticSoilModel = stochasticSoilModel, + StochasticSoilProfile = stochasticSoilProfile + } + }; + if (manualAssessmentLevel) + { + expectedCalculation.InputParameters.AssessmentLevel = (RoundedDouble) 1.1; + } + + Assert.AreEqual(1, calculationGroup.Children.Count); + AssertMacroStabilityInwardsCalculationScenario(expectedCalculation, (MacroStabilityInwardsCalculationScenario) calculationGroup.Children[0]); + } + + private static void AssertMacroStabilityInwardsCalculationScenario(MacroStabilityInwardsCalculationScenario expectedCalculation, MacroStabilityInwardsCalculationScenario actualCalculation) + { + Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); + Assert.AreEqual(expectedCalculation.InputParameters.UseAssessmentLevelManualInput, actualCalculation.InputParameters.UseAssessmentLevelManualInput); + if (expectedCalculation.InputParameters.UseAssessmentLevelManualInput) + { + Assert.AreEqual(expectedCalculation.InputParameters.AssessmentLevel.Value, actualCalculation.InputParameters.AssessmentLevel.Value); + } + else + { + Assert.AreSame(expectedCalculation.InputParameters.HydraulicBoundaryLocation, actualCalculation.InputParameters.HydraulicBoundaryLocation); + } + Assert.AreSame(expectedCalculation.InputParameters.SurfaceLine, actualCalculation.InputParameters.SurfaceLine); + Assert.AreSame(expectedCalculation.InputParameters.StochasticSoilModel, actualCalculation.InputParameters.StochasticSoilModel); + Assert.AreSame(expectedCalculation.InputParameters.StochasticSoilProfile, actualCalculation.InputParameters.StochasticSoilProfile); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationReaderTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationReaderTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationReaderTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,246 @@ +// 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.MacroStabilityInwards.IO.Configurations; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationReaderTest + { + private readonly string testDirectoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, + nameof(MacroStabilityInwardsCalculationConfigurationReader)); + + private static IEnumerable InvalidConfigurations + { + get + { + yield return new TestCaseData("invalidAssessmentLevelEmpty.xml", + "The 'toetspeil' element is invalid - The value '' is invalid according to its datatype 'Double'") + .SetName("invalidAssessmentLevelEmpty"); + yield return new TestCaseData("invalidAssessmentLevelNoDouble.xml", + "The 'toetspeil' element is invalid - The value 'string' is invalid according to its datatype 'Double'") + .SetName("invalidAssessmentLevelNoDouble"); + yield return new TestCaseData("invalidContainingBothAssessmentLevelAndHydraulicBoundaryLocation.xml", + "Element 'hrlocatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidContainingBothAssessmentLevelAndHydraulicBoundaryLocation"); + yield return new TestCaseData("invalidCalculationMultipleAssessmentLevel.xml", + "Element 'toetspeil' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleAssessmentLevel"); + yield return new TestCaseData("invalidCalculationMultipleHydraulicBoundaryLocation.xml", + "Element 'hrlocatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleHydraulicBoundaryLocation"); + yield return new TestCaseData("invalidCalculationMultipleSurfaceLine.xml", + "Element 'profielschematisatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleSurfaceLine"); + yield return new TestCaseData("invalidCalculationMultipleStochasticSoilModel.xml", + "Element 'ondergrondmodel' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleStochasticSoilModel"); + yield return new TestCaseData("invalidCalculationMultipleStochasticSoilProfile.xml", + "Element 'ondergrondschematisatie' cannot appear more than once if content model type is \"all\".") + .SetName("invalidCalculationMultipleStochasticSoilProfile"); + yield return new TestCaseData("invalidConfigurationCalculationContainingEmptyHydraulicBoundaryLocation.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("invalidConfigurationCalculationContainingEmptyHydraulicBoundaryLocation"); + yield return new TestCaseData("invalidConfigurationCalculationContainingEmptySurfaceLine.xml", + "The 'profielschematisatie' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.") + .SetName("invalidConfigurationCalculationContainingEmptySurfaceLine"); + yield return new TestCaseData("invalidConfigurationCalculationContainingEmptySoilModel.xml", + "The 'ondergrondmodel' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.") + .SetName("invalidConfigurationCalculationContainingEmptySoilModel"); + yield return new TestCaseData("invalidConfigurationCalculationContainingEmptySoilProfile.xml", + "The 'ondergrondschematisatie' element is invalid - The value '' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.") + .SetName("invalidConfigurationCalculationContainingEmptySoilProfile"); + } + } + + [Test] + [TestCaseSource(nameof(InvalidConfigurations))] + public void Constructor_FileInvalidBasedOnSchemaDefinition_ThrowCriticalFileReadException(string fileName, string expectedParsingMessage) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, fileName); + + // Call + TestDelegate call = () => new MacroStabilityInwardsCalculationConfigurationReader(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 MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Assert + Assert.IsInstanceOf>(reader); + } + + [Test] + public void Read_ValidConfigurationWithEmptyCalculation_ReturnExpectedReadMacroStabilityInwardsCalculation() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfigurationEmptyCalculation.xml"); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + Assert.AreEqual("Calculation", calculation.Name); + Assert.IsNull(calculation.AssessmentLevel); + Assert.IsNull(calculation.HydraulicBoundaryLocation); + Assert.IsNull(calculation.SurfaceLine); + Assert.IsNull(calculation.StochasticSoilModel); + Assert.IsNull(calculation.StochasticSoilProfile); + } + + [Test] + public void Read_ValidConfigurationWithCalculationContainingNaNs_ReturnExpectedReadMacroStabilityInwardsCalculation() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfigurationCalculationContainingNaNs.xml"); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + Assert.IsNaN(calculation.AssessmentLevel); + } + + [Test] + public void Read_ValidConfigurationWithCalculationContainingInfinities_ReturnExpectedReadMacroStabilityInwardsCalculation() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfigurationCalculationContainingInfinities.xml"); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + + Assert.IsNotNull(calculation.AssessmentLevel); + + Assert.IsTrue(double.IsNegativeInfinity(calculation.AssessmentLevel.Value)); + } + + [Test] + [TestCase("validConfigurationFullCalculationContainingHydraulicBoundaryLocation.xml", + TestName = "Read_ValidConfigurationWithFullCalculationContainingHydraulicBoundaryLocation_ReturnCalculation(HydraulicBoundaryLocation)")] + [TestCase("validConfigurationFullCalculationContainingHydraulicBoundaryLocation_differentOrder.xml", + TestName = "Read_ValidConfigurationWithFullCalculationContainingHydraulicBoundaryLocation_ReturnCalculation(HydraulicBoundaryLocation_differentOrder)")] + public void Read_ValidConfigurationWithFullCalculationContainingHydraulicBoundaryLocation_ReturnExpectedReadMacroStabilityInwardsCalculation(string fileName) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, fileName); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + Assert.AreEqual("Calculation", calculation.Name); + Assert.IsNull(calculation.AssessmentLevel); + Assert.AreEqual("HRlocatie", calculation.HydraulicBoundaryLocation); + Assert.AreEqual("Profielschematisatie", calculation.SurfaceLine); + Assert.AreEqual("Ondergrondmodel", calculation.StochasticSoilModel); + Assert.AreEqual("Ondergrondschematisatie", calculation.StochasticSoilProfile); + } + + [Test] + [TestCase("validConfigurationFullCalculationContainingAssessmentLevel.xml", + TestName = "Read_ValidConfigurationWithFullCalculationContainingAssessmentLevel_ReturnCalculation(AssessmentLevel)")] + [TestCase("validConfigurationFullCalculationContainingAssessmentLevel_differentOrder.xml", + TestName = "Read_ValidConfigurationWithFullCalculationContainingAssessmentLevel_ReturnCalculation(AssessmentLevel_differentOrder)")] + public void Read_ValidConfigurationWithFullCalculationContainingAssessmentLevel_ReturnExpectedReadMacroStabilityInwardsCalculation(string fileName) + { + // Setup + string filePath = Path.Combine(testDirectoryPath, fileName); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + Assert.AreEqual("Calculation", calculation.Name); + Assert.AreEqual(1.1, calculation.AssessmentLevel); + Assert.IsNull(calculation.HydraulicBoundaryLocation); + Assert.AreEqual("Profielschematisatie", calculation.SurfaceLine); + Assert.AreEqual("Ondergrondmodel", calculation.StochasticSoilModel); + Assert.AreEqual("Ondergrondschematisatie", calculation.StochasticSoilProfile); + } + + [Test] + public void Read_ValidConfigurationWithPartialCalculation_ReturnExpectedReadMacroStabilityInwardsCalculation() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfigurationPartialCalculation.xml"); + var reader = new MacroStabilityInwardsCalculationConfigurationReader(filePath); + + // Call + IList readConfigurationItems = reader.Read().ToList(); + + // Assert + Assert.AreEqual(1, readConfigurationItems.Count); + + var calculation = (MacroStabilityInwardsCalculationConfiguration) readConfigurationItems[0]; + Assert.AreEqual("Calculation", calculation.Name); + Assert.AreEqual(1.1, calculation.AssessmentLevel); + Assert.IsNull(calculation.HydraulicBoundaryLocation); + Assert.IsNull(calculation.SurfaceLine); + Assert.IsNull(calculation.StochasticSoilModel); + Assert.AreEqual("Ondergrondschematisatie", calculation.StochasticSoilProfile); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiersTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiersTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiersTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,39 @@ +// 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.MacroStabilityInwards.IO.Configurations; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationSchemaIdentifiersTest + { + [Test] + public void MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers_ExpectedValues() + { + Assert.AreEqual("toetspeil", MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.AssessmentLevelElement); + Assert.AreEqual("profielschematisatie", MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SurfaceLineElement); + Assert.AreEqual("ondergrondmodel", MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilModelElement); + Assert.AreEqual("ondergrondschematisatie", MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilProfileElement); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,91 @@ +// 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.MacroStabilityInwards.IO.Configurations; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationTest + { + [Test] + public void Constructor_WithoutConstructionProperties_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new MacroStabilityInwardsCalculationConfiguration(null); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Constructor_ConstructionPropertiesWithoutValues_PropertiesAreDefault() + { + // Setup + const string name = "some name"; + + // Call + var readCalculation = new MacroStabilityInwardsCalculationConfiguration(name); + + // Assert + Assert.IsInstanceOf(readCalculation); + Assert.AreEqual(name, readCalculation.Name); + Assert.IsNull(readCalculation.AssessmentLevel); + Assert.IsNull(readCalculation.HydraulicBoundaryLocation); + Assert.IsNull(readCalculation.SurfaceLine); + Assert.IsNull(readCalculation.StochasticSoilModel); + Assert.IsNull(readCalculation.StochasticSoilProfile); + } + + [Test] + public void Constructor_ConstructionPropertiesWithValuesSet_PropertiesAsExpected() + { + // Setup + const string calculationName = "Name of the calculation"; + const double assessmentLevel = 1.1; + const string hydraulicBoundaryLocation = "Name of the hydraulic boundary location"; + const string surfaceLine = "Name of the surface line"; + const string stochasticSoilModel = "Name of the stochastic soil model"; + const string stochasticSoilProfile = "Name of the stochastic soil profile"; + + // Call + var readCalculation = new MacroStabilityInwardsCalculationConfiguration(calculationName) + { + AssessmentLevel = assessmentLevel, + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + SurfaceLine = surfaceLine, + StochasticSoilModel = stochasticSoilModel, + StochasticSoilProfile = stochasticSoilProfile + }; + + // Assert + Assert.AreEqual(calculationName, readCalculation.Name); + Assert.AreEqual(assessmentLevel, readCalculation.AssessmentLevel); + Assert.AreEqual(hydraulicBoundaryLocation, readCalculation.HydraulicBoundaryLocation); + Assert.AreEqual(surfaceLine, readCalculation.SurfaceLine); + Assert.AreEqual(stochasticSoilModel, readCalculation.StochasticSoilModel); + Assert.AreEqual(stochasticSoilProfile, readCalculation.StochasticSoilProfile); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Configurations/MacroStabilityInwardsCalculationConfigurationWriterTest.cs (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -0,0 +1,165 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.IO.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Integration.TestUtils; +using Ringtoets.MacroStabilityInwards.IO.Configurations; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.IO.Test.Configurations +{ + [TestFixture] + public class MacroStabilityInwardsCalculationConfigurationWriterTest + : CustomCalculationConfigurationWriterDesignGuidelinesTestFixture< + MacroStabilityInwardsCalculationConfigurationWriter, + MacroStabilityInwardsCalculation> + { + private static IEnumerable Calculations + { + get + { + yield return new TestCaseData("calculationWithoutHydraulicLocation", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithoutHydraulicLocationAndAssessmentLevel()) + .SetName("calculationWithoutHydraulicLocation"); + yield return new TestCaseData("calculationWithAssessmentLevel", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithAssessmentLevel()) + .SetName("calculationWithAssessmentLevel"); + yield return new TestCaseData("calculationWithoutSurfaceLine", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithoutSurfaceLine()) + .SetName("calculationWithoutSurfaceLine"); + yield return new TestCaseData("calculationWithoutSoilModel", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithoutSoilModel()) + .SetName("calculationWithoutSoilModel"); + yield return new TestCaseData("calculationWithoutSoilProfile", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithoutSoilProfile()) + .SetName("calculationWithoutSoilProfile"); + yield return new TestCaseData("calculationWithNaNs", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithNaNs()) + .SetName("calculationWithNaNs"); + yield return new TestCaseData("calculationWithInfinities", + MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationWithInfinities()) + .SetName("calculationWithInfinities"); + } + } + + [Test] + public void Write_CalculationGroupsAndCalculation_ValidFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + MacroStabilityInwardsCalculation calculation = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculation(); + + MacroStabilityInwardsCalculation calculation2 = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculation(); + calculation2.Name = "PK001_0002 W1-6_4_1D1"; + calculation2.InputParameters.HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "PUNT_SCH_17", 0, 0); + calculation2.InputParameters.SurfaceLine.Name = "PK001_0002"; + calculation2.InputParameters.StochasticSoilModel = new StochasticSoilModel(1, "PK001_0002_Macrostabiliteit", string.Empty); + calculation2.InputParameters.StochasticSoilProfile = new StochasticSoilProfile(0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new MacroStabilityInwardsSoilProfile("W1-6_4_1D1", 0, new[] + { + new MacroStabilityInwardsSoilLayer(0) + }, SoilProfileType.SoilProfile1D, 0) + }; + + var calculationGroup2 = new CalculationGroup("PK001_0002", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("PK001_0001", false) + { + Children = + { + calculation, + calculationGroup2 + } + }; + + try + { + // Call + new MacroStabilityInwardsCalculationConfigurationWriter().Write(new[] + { + calculationGroup + }, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, + Path.Combine("MacroStabilityInwardsCalculationConfigurationWriter", + "folderWithSubfolderAndCalculation.xml")); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + [TestCaseSource(nameof(Calculations))] + public void Write_ValidCalculation_ValidFile(string expectedFileName, MacroStabilityInwardsCalculation calculation) + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + try + { + // Call + new MacroStabilityInwardsCalculationConfigurationWriter().Write(new[] + { + calculation + }, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.MacroStabilityInwards.IO, + Path.Combine("MacroStabilityInwardsCalculationConfigurationWriter", + $"{expectedFileName}.xml")); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/MacroStabilityInwardsCalculationConfigurationImporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Readers/MacroStabilityInwardsCalculationConfigurationReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Readers/ReadMacroStabilityInwardsCalculationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Ringtoets.MacroStabilityInwards.IO.Test.csproj =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Ringtoets.MacroStabilityInwards.IO.Test.csproj (.../Ringtoets.MacroStabilityInwards.IO.Test.csproj) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Ringtoets.MacroStabilityInwards.IO.Test.csproj (.../Ringtoets.MacroStabilityInwards.IO.Test.csproj) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -72,12 +72,12 @@ - - - - - - + + + + + + Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Schema/MacroStabilityInwardsCalculationConfigurationSchemaIdentifiersTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationContextExportInfoTest.cs =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationContextExportInfoTest.cs (.../MacroStabilityInwardsCalculationContextExportInfoTest.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationContextExportInfoTest.cs (.../MacroStabilityInwardsCalculationContextExportInfoTest.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -29,7 +29,7 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; -using Ringtoets.MacroStabilityInwards.IO.Exporters; +using Ringtoets.MacroStabilityInwards.IO.Configurations; using Ringtoets.MacroStabilityInwards.Primitives; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationGroupContextExportInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextExportInfoTest.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ExportInfos/MacroStabilityInwardsCalculationGroupContextExportInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextExportInfoTest.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -30,7 +30,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; -using Ringtoets.MacroStabilityInwards.IO.Exporters; +using Ringtoets.MacroStabilityInwards.IO.Configurations; using Ringtoets.MacroStabilityInwards.Primitives; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ImportInfos/MacroStabilityInwardsCalculationGroupContextImportInfoTest.cs =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ImportInfos/MacroStabilityInwardsCalculationGroupContextImportInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextImportInfoTest.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ImportInfos/MacroStabilityInwardsCalculationGroupContextImportInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextImportInfoTest.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -32,6 +32,7 @@ using Ringtoets.Common.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.IO.Configurations; using Ringtoets.MacroStabilityInwards.IO.Importers; using Ringtoets.MacroStabilityInwards.Primitives; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/Helpers/WaveConditionsInputExtensions.cs =================================================================== diff -u -r4fa75e2c07753d69a156377821eec5caaff7fc11 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/Helpers/WaveConditionsInputExtensions.cs (.../WaveConditionsInputExtensions.cs) (revision 4fa75e2c07753d69a156377821eec5caaff7fc11) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/Helpers/WaveConditionsInputExtensions.cs (.../WaveConditionsInputExtensions.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -20,6 +20,9 @@ // All rights reserved. using System; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Revetment.Data; namespace Ringtoets.Revetment.IO.Configurations.Helpers @@ -53,8 +56,47 @@ Orientation = input.Orientation, StepSize = (ConfigurationWaveConditionsInputStepSize?) new ConfigurationWaveConditionsInputStepSizeConverter().ConvertFrom(input.StepSize) }; - calculationConfiguration.SetConfigurationForeshoreProfileDependendProperties(input); + SetConfigurationForeshoreProfileDependendProperties(calculationConfiguration, input); return calculationConfiguration; } + + /// + /// Sets the using properties from , + /// when is set. + /// + /// The configuration to update. + /// The wave conditions input to update from. + /// Thrown when any of the input parameters is null. + private static void SetConfigurationForeshoreProfileDependendProperties(WaveConditionsCalculationConfiguration configuration, + WaveConditionsInput input) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + if (input.ForeshoreProfile == null) + { + return; + } + + configuration.ForeshoreProfile = input.ForeshoreProfile?.Id; + configuration.WaveReduction = new WaveReductionConfiguration + { + UseForeshoreProfile = input.UseForeshore, + UseBreakWater = input.UseBreakWater, + BreakWaterHeight = input.BreakWater.Height + }; + + if (Enum.IsDefined(typeof(BreakWaterType), input.BreakWater.Type)) + { + configuration.WaveReduction.BreakWaterType = (ConfigurationBreakWaterType?) + new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type); + } + } } } \ No newline at end of file Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/Helpers/WaveReductionConversionExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfiguration.cs =================================================================== diff -u -r4fa75e2c07753d69a156377821eec5caaff7fc11 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfiguration.cs (.../WaveConditionsCalculationConfiguration.cs) (revision 4fa75e2c07753d69a156377821eec5caaff7fc11) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Configurations/WaveConditionsCalculationConfiguration.cs (.../WaveConditionsCalculationConfiguration.cs) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -25,7 +25,7 @@ namespace Ringtoets.Revetment.IO.Configurations { /// - /// Class that represents a wave conditions calculation that is read via . + /// Class that represents a wave conditions calculation configuration. /// public class WaveConditionsCalculationConfiguration : IConfigurationItem { @@ -42,42 +42,42 @@ } /// - /// Gets the name of the hydraulic boundary location of the read calculation. + /// Gets the name of the hydraulic boundary location of the calculation. /// public string HydraulicBoundaryLocation { get; set; } /// - /// Gets the upper boundary of the revetment of the read calculation. + /// Gets the upper boundary of the revetment of the calculation. /// public double? UpperBoundaryRevetment { get; set; } /// - /// Gets the lower boundary of the revetment of the read calculation. + /// Gets the lower boundary of the revetment of the calculation. /// public double? LowerBoundaryRevetment { get; set; } /// - /// Gets the upper boundary of the water levels of the read calculation. + /// Gets the upper boundary of the water levels of the calculation. /// public double? UpperBoundaryWaterLevels { get; set; } /// - /// Gets the lower boundary of the water levels of the read calculation. + /// Gets the lower boundary of the water levels of the calculation. /// public double? LowerBoundaryWaterLevels { get; set; } /// - /// Gets the step size of the read calculation. + /// Gets the step size of the calculation. /// public ConfigurationWaveConditionsInputStepSize? StepSize { get; set; } /// - /// Gets the name of the foreshore profile of the read calculation. + /// Gets the name of the foreshore profile of the calculation. /// public string ForeshoreProfile { get; set; } /// - /// Gets the orientation of the read calculation. + /// Gets the orientation of the calculation. /// public double? Orientation { get; set; } @@ -105,76 +105,5 @@ name = value; } } - - /// - /// Class holding the various construction parameters for . - /// - public class ConstructionProperties - { - /// - /// Gets or sets the value for . - /// - public string Name { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public string HydraulicBoundaryLocation { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? UpperBoundaryRevetment { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? LowerBoundaryRevetment { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? UpperBoundaryWaterLevels { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? LowerBoundaryWaterLevels { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public ConfigurationWaveConditionsInputStepSize? StepSize { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public string ForeshoreProfile { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? Orientation { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public bool? UseBreakWater { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public ConfigurationBreakWaterType? BreakWaterType { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public double? BreakWaterHeight { internal get; set; } - - /// - /// Gets or sets the value for . - /// - public bool? UseForeshore { internal get; set; } - } } } \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj =================================================================== diff -u -r4fa75e2c07753d69a156377821eec5caaff7fc11 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision 4fa75e2c07753d69a156377821eec5caaff7fc11) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -46,7 +46,6 @@ Properties\GlobalAssembly.cs - Fisheye: Tag f03b47d0d73983de35188874a094ae07f1ea13fa refers to a dead (removed) revision in file `Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Configurations/Helpers/WaveReductionConversionExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj =================================================================== diff -u -r4fa75e2c07753d69a156377821eec5caaff7fc11 -rf03b47d0d73983de35188874a094ae07f1ea13fa --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 4fa75e2c07753d69a156377821eec5caaff7fc11) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision f03b47d0d73983de35188874a094ae07f1ea13fa) @@ -51,7 +51,6 @@ Properties\GlobalAssembly.cs -