Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -ree206fe08782d701c721a3cee64ab452352e1b0a -r72a2809486183c2a0ecfd8a529b4518f852d250d --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ee206fe08782d701c721a3cee64ab452352e1b0a) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -1649,6 +1649,33 @@ } /// + /// Looks up a localized string similar to Kon geen ondergrondschematisaties verkrijgen uit de database.. + /// + public static string SoilProfileReader_Error_reading_soil_profile_from_database { + get { + return ResourceManager.GetString("SoilProfileReader_Error_reading_soil_profile_from_database", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ondergrondschematisatie bevat geen geldige waarde in kolom '{0}'.. + /// + public static string SoilProfileReader_Profile_has_invalid_value_on_Column_0_ { + get { + return ResourceManager.GetString("SoilProfileReader_Profile_has_invalid_value_on_Column_0_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ondergrondschematisatie '{0}'. + /// + public static string SoilProfileReader_SoilProfileName_0_ { + get { + return ResourceManager.GetString("SoilProfileReader_SoilProfileName_0_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kon geen stochastische ondergrondmodellen verkrijgen uit de database.. /// public static string StochasticSoilModelDatabaseReader_Failed_to_read_database { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -ree206fe08782d701c721a3cee64ab452352e1b0a -r72a2809486183c2a0ecfd8a529b4518f852d250d --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision ee206fe08782d701c721a3cee64ab452352e1b0a) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -824,4 +824,13 @@ De ondergrondschematisatie verwijst naar een ongeldige waarde. + + Kon geen ondergrondschematisaties verkrijgen uit de database. + + + ondergrondschematisatie '{0}' + + + Ondergrondschematisatie bevat geen geldige waarde in kolom '{0}'. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r0ec64f4150d76a9530b3bed3f1af18334b5bf673 -r72a2809486183c2a0ecfd8a529b4518f852d250d --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 0ec64f4150d76a9530b3bed3f1af18334b5bf673) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -122,17 +122,19 @@ + + + - Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/Schema/SoilProfileTableDefinitions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/Schema/SoilProfileTableDefinitions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/Schema/SoilProfileTableDefinitions.cs (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1,55 @@ +// 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.Common.IO.SoilProfile.Schema +{ + /// + /// Defines the table and column names of the table 'StochasticSoilProfile' in the DSoil-Model database. + /// + internal static class SoilProfileTableDefinitions + { + public const string SoilProfileId = "SoilProfileId"; + public const string Dimension = "Dimension"; + public const string IsAquifer = "IsAquifer"; + public const string ProfileName = "ProfileName"; + public const string IntersectionX = "IntersectionX"; + public const string Bottom = "Bottom"; + public const string Top = "Top"; + public const string Color = "Color"; + public const string MaterialName = "MaterialName"; + public const string LayerGeometry = "LayerGeometry"; + public const string BelowPhreaticLevelDistribution = "BelowPhreaticLevelDistribution"; + public const string BelowPhreaticLevelShift = "BelowPhreaticLevelShift"; + public const string BelowPhreaticLevelMean = "BelowPhreaticLevelMean"; + public const string BelowPhreaticLevelDeviation = "BelowPhreaticLevelDeviation"; + public const string PermeabilityDistribution = "PermeabKxDistribution"; + public const string PermeabilityShift = "PermeabKxShift"; + public const string PermeabilityMean = "PermeabKxMean"; + public const string PermeabilityCoefficientOfVariation = "PermeabKxCoefficientOfVariation"; + public const string DiameterD70Distribution = "DiameterD70Distribution"; + public const string DiameterD70Shift = "DiameterD70Shift"; + public const string DiameterD70Mean = "DiameterD70Mean"; + public const string DiameterD70CoefficientOfVariation = "DiameterD70CoefficientOfVariation"; + + public const string LayerCount = "LayerCount"; + public const string ProfileCount = "nrOfRows"; + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1,271 @@ +// 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.Data; +using System.Data.SQLite; +using Core.Common.Base.IO; +using Core.Common.IO.Readers; +using Core.Common.Utils.Builders; +using Ringtoets.Common.IO.Properties; +using Ringtoets.Common.IO.SoilProfile.Schema; + +namespace Ringtoets.Common.IO.SoilProfile +{ + /// + /// This class reads a DSoil database file and reads 1d profiles from this database. + /// + public class SoilProfile1DReader : SqLiteDatabaseReaderBase, IRowBasedDatabaseReader + { + private IDataReader dataReader; + + /// + /// Creates a new instance of , which will use the + /// as its source. + /// + /// The path of the database file to open. + /// Thrown when: + /// + /// The contains invalid characters. + /// No file could be found at . + /// + /// + public SoilProfile1DReader(string databaseFilePath) : base(databaseFilePath) {} + + /// + /// Gets a value indicating whether or not more soil profiles can be read using + /// the . + /// + public bool HasNext { get; private set; } + + /// + /// Initializes the database reader. + /// + public void Initialize() + { + PrepareReader(); + MoveNext(); + } + + /// + /// Reads the information for the next soil profile from the database and creates a + /// instance of the information. + /// + /// The next from the database, or null + /// if no more soil profile can be read. + /// Thrown when the database returned incorrect + /// values for required properties. + public SoilProfile1D ReadSoilProfile() + { + try + { + SoilProfile1D soilProfile = TryReadSoilProfile(); + MoveNext(); + return soilProfile; + } + catch (SystemException exception) when (exception is FormatException || + exception is OverflowException || + exception is InvalidCastException) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.SoilProfileReader_Error_reading_soil_profile_from_database); + throw new CriticalFileReadException(message, exception); + } + } + + public void MoveNext() + { + HasNext = MoveNext(dataReader); + } + + public T Read(string columnName) + { + return (T) dataReader[columnName]; + } + + public T ReadOrDefault(string columnName) + { + object valueObject = dataReader[columnName]; + if (valueObject.Equals(DBNull.Value)) + { + return default(T); + } + return (T) valueObject; + } + + protected override void Dispose(bool disposing) + { + if (dataReader != null) + { + dataReader.Close(); + dataReader.Dispose(); + dataReader = null; + } + base.Dispose(disposing); + } + + private SoilProfile1D TryReadSoilProfile() + { + var criticalProperties = new RequiredProfileProperties(this); + var soilProfile = new SoilProfile1D(criticalProperties.ProfileName, criticalProperties.Bottom); + + for (var i = 1; i <= criticalProperties.LayerCount; i++) + { + MoveNext(); + } + + return soilProfile; + } + + private void PrepareReader() + { + string subQueryGetNumberOfLayerProfile1D = + "SELECT " + + "SP1D_ID, " + + $"COUNT(*) AS {SoilProfileTableDefinitions.LayerCount} " + + "FROM SoilLayer1D " + + "GROUP BY SP1D_ID"; + + string subQueryGetMaterialPropertiesOfLayer = + "SELECT " + + "mat.MA_ID, " + + $"mat.MA_Name AS {SoilProfileTableDefinitions.MaterialName}, " + + $"max(case when pn.PN_Name = 'Color' then pv.PV_Value end) {SoilProfileTableDefinitions.Color}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Dist_Type end) {SoilProfileTableDefinitions.BelowPhreaticLevelDistribution}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Shift end) {SoilProfileTableDefinitions.BelowPhreaticLevelShift}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Mean end) {SoilProfileTableDefinitions.BelowPhreaticLevelMean}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Deviation end) {SoilProfileTableDefinitions.BelowPhreaticLevelDeviation}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Dist_Type end) {SoilProfileTableDefinitions.PermeabilityDistribution}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Shift end) {SoilProfileTableDefinitions.PermeabilityShift}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Mean end) {SoilProfileTableDefinitions.PermeabilityMean}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Variation end) {SoilProfileTableDefinitions.PermeabilityCoefficientOfVariation}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Dist_Type end) {SoilProfileTableDefinitions.DiameterD70Distribution}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Shift end) {SoilProfileTableDefinitions.DiameterD70Shift}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Mean end) {SoilProfileTableDefinitions.DiameterD70Mean}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Variation end) {SoilProfileTableDefinitions.DiameterD70CoefficientOfVariation} " + + "FROM ParameterNames AS pn " + + "LEFT JOIN ParameterValues AS pv USING(PN_ID) " + + "LEFT JOIN Stochast AS s USING(PN_ID) " + + "JOIN Materials AS mat " + + "WHERE pv.MA_ID = mat.MA_ID OR s.MA_ID = mat.MA_ID " + + "GROUP BY mat.MA_ID "; + + string subQueryGetLayerPropertiesOfLayer1D = + "SELECT " + + "SL1D_ID, " + + $"PV_Value AS {SoilProfileTableDefinitions.IsAquifer} " + + "FROM ParameterNames " + + "JOIN LayerParameterValues USING(PN_ID) " + + $"WHERE PN_NAME = '{SoilProfileTableDefinitions.IsAquifer}'"; + + string querySoilProfile1D = + "SELECT " + + $"1 AS {SoilProfileTableDefinitions.Dimension}, " + + $"sp1d.SP1D_Name AS {SoilProfileTableDefinitions.ProfileName}, " + + $"layerCount.{SoilProfileTableDefinitions.LayerCount}, " + + $"sp1d.BottomLevel AS {SoilProfileTableDefinitions.Bottom}, " + + $"sl1d.TopLevel AS {SoilProfileTableDefinitions.Top}, " + + $"{SoilProfileTableDefinitions.MaterialName}, " + + $"{SoilProfileTableDefinitions.IsAquifer}, " + + $"{SoilProfileTableDefinitions.Color}, " + + $"{SoilProfileTableDefinitions.BelowPhreaticLevelDistribution}, " + + $"{SoilProfileTableDefinitions.BelowPhreaticLevelShift}, " + + $"{SoilProfileTableDefinitions.BelowPhreaticLevelMean}, " + + $"{SoilProfileTableDefinitions.BelowPhreaticLevelDeviation}, " + + $"{SoilProfileTableDefinitions.DiameterD70Distribution}, " + + $"{SoilProfileTableDefinitions.DiameterD70Shift}, " + + $"{SoilProfileTableDefinitions.DiameterD70Mean}, " + + $"{SoilProfileTableDefinitions.DiameterD70CoefficientOfVariation}, " + + $"{SoilProfileTableDefinitions.PermeabilityDistribution}, " + + $"{SoilProfileTableDefinitions.PermeabilityShift}, " + + $"{SoilProfileTableDefinitions.PermeabilityMean}, " + + $"{SoilProfileTableDefinitions.PermeabilityCoefficientOfVariation}, " + + $"sp1d.SP1D_ID AS {SoilProfileTableDefinitions.SoilProfileId} " + + "FROM Segment AS segment " + + "JOIN (SELECT SSM_ID, SP1D_ID, SP2D_ID FROM StochasticSoilProfile GROUP BY SSM_ID, SP1D_ID, SP2D_ID) ssp USING(SSM_ID) " + + "JOIN SoilProfile1D sp1d USING (SP1D_ID) " + + $"JOIN ({subQueryGetNumberOfLayerProfile1D}) {SoilProfileTableDefinitions.LayerCount} USING (SP1D_ID) " + + "JOIN SoilLayer1D sl1d USING (SP1D_ID) " + + $"LEFT JOIN ({subQueryGetMaterialPropertiesOfLayer}) materialProperties USING(MA_ID) " + + $"LEFT JOIN ({subQueryGetLayerPropertiesOfLayer1D}) layerProperties USING(SL1D_ID) " + + "GROUP BY sp1d.SP1D_ID, sl1d.SL1D_ID;"; + + try + { + dataReader = CreateDataReader(querySoilProfile1D); + } + catch (SQLiteException exception) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.SoilProfileReader_Error_reading_soil_profile_from_database); + throw new CriticalFileReadException(message, exception); + } + } + + private class RequiredProfileProperties + { + /// + /// Creates a new instance of , which contains properties + /// that are required to create a complete . If these properties + /// cannot be read, then the reader can proceed to the next profile. + /// + /// The to read the required profile property values from. + /// Thrown when the values in the database could not be + /// casted to the expected column types. + internal RequiredProfileProperties(IRowBasedDatabaseReader reader) + { + const string readColumn = SoilProfileTableDefinitions.Bottom; + try + { + ProfileName = reader.Read(SoilProfileTableDefinitions.ProfileName); + Bottom = reader.Read(readColumn); + LayerCount = reader.Read(SoilProfileTableDefinitions.LayerCount); + ProfileId = reader.Read(SoilProfileTableDefinitions.SoilProfileId); + } + catch (InvalidCastException e) + { + string message = new FileReaderErrorMessageBuilder(reader.Path) + .WithSubject(string.Format(Resources.SoilProfileReader_SoilProfileName_0_, ProfileName)) + .Build(string.Format(Resources.SoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn)); + throw new SoilProfileReadException(message, ProfileName, e); + } + } + + /// + /// The bottom of the profile. + /// + public double Bottom { get; } + + /// + /// The name of the profile to read. + /// + public string ProfileName { get; } + + /// + /// The number of layers that the profile has to read. + /// + public long LayerCount { get; } + + /// + /// Gets the database identifier of the profile. + /// + public long ProfileId { get; } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfileReadException.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfileReadException.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfileReadException.cs (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1,120 @@ +// 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.Runtime.Serialization; + +namespace Ringtoets.Common.IO.SoilProfile +{ + /// + /// Exception thrown when something went wrong while trying to read a . + /// + [Serializable] + public class SoilProfileReadException : Exception + { + private const string profileNameKey = nameof(ProfileName); + + /// + /// Initializes a new instance of the class. + /// + public SoilProfileReadException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public SoilProfileReadException(string message) : base(message) {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The message that describes the error. + /// The name of the profile for which this exception was thrown. + public SoilProfileReadException(string message, string profileName) + : base(message) + { + ProfileName = profileName; + } + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, + /// or null if no inner exception is specified. + public SoilProfileReadException(string message, Exception inner) + : base(message, inner) {} + + /// + /// Initializes a new instance of the class with a specified error message + /// and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The name of the profile for which this exception was thrown. + /// The exception that is the cause of the current exception, + /// or null if no inner exception is specified. + public SoilProfileReadException(string message, string profileName, Exception innerException) + : base(message, innerException) + { + ProfileName = profileName; + } + + /// + /// Initializes a new instance of with + /// serialized data. + /// The that holds the serialized + /// object data about the exception being thrown. + /// The that contains contextual + /// information about the source or destination. + /// The parameter is + /// null. + /// The class name is null or + /// is zero (0). + private SoilProfileReadException(SerializationInfo info, StreamingContext context) : base(info, context) + { + ProfileName = info.GetString(profileNameKey); + } + + /// + /// The name of the profile for which this exception was thrown. + /// + public string ProfileName + { + get + { + return (string) Data[profileNameKey]; + } + private set + { + Data[profileNameKey] = value; + } + } + + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue(profileNameKey, ProfileName); + } + } +} \ No newline at end of file Fisheye: Tag 72a2809486183c2a0ecfd8a529b4518f852d250d refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfileReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r0ec64f4150d76a9530b3bed3f1af18334b5bf673 -r72a2809486183c2a0ecfd8a529b4518f852d250d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 0ec64f4150d76a9530b3bed3f1af18334b5bf673) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -112,11 +112,12 @@ + + - Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1,132 @@ +// 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.ObjectModel; +using System.IO; +using Core.Common.Base.IO; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using Core.Common.Utils.Builders; +using NUnit.Framework; +using Ringtoets.Common.IO.SoilProfile; + +namespace Ringtoets.Common.IO.Test.SoilProfile +{ + [TestFixture] + public class SoilProfile1DReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(SoilProfile1DReader)); + + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + string testFile = Path.Combine(testDataPath, "does not exist"); + + // Call + TestDelegate test = () => + { + using (new SoilProfile1DReader(testFile)) {} + }; + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build("Het bestand bestaat niet."); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + [TestCaseSource(typeof(InvalidPathHelper), nameof(InvalidPathHelper.InvalidPaths))] + public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string fileName) + { + // Call + TestDelegate test = () => + { + using (new SoilProfile1DReader(fileName)) {} + }; + + // Assert + Assert.Throws(test); + } + + [Test] + public void Constructor_PathToExistingFile_ExpectedValues() + { + // Setup + string dbFile = Path.Combine(testDataPath, "emptySchema.soil"); + + // Call + using (var reader = new SoilProfile1DReader(dbFile)) + { + // Assert + Assert.AreEqual(dbFile, reader.Path); + Assert.IsInstanceOf(reader); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void Initialize_IncorrectFormatFileOrInvalidSchema_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "text.txt"); + + using (var reader = new SoilProfile1DReader(dbFile)) + { + // Call + TestDelegate test = () => reader.Initialize(); + + // Assert + var exception = Assert.Throws(test); + + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build( + "Kon geen ondergrondschematisaties verkrijgen uit de database."); + Assert.AreEqual(expectedMessage, exception.Message); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadSoilProfile_DatabaseWith1DAnd1DSoilProfileWithoutSoilLayers_ReturnOneProfile() + { + // Setup + string dbFile = Path.Combine(testDataPath, "1dprofileWithEmpty1d.soil"); + + var result = new Collection(); + using (var reader = new SoilProfile1DReader(dbFile)) + { + reader.Initialize(); + + // Call + while (reader.HasNext) + { + result.Add(reader.ReadSoilProfile()); + } + } + + // Assert + Assert.AreEqual(1, result.Count); + Assert.AreEqual("Profile", result[0].Name); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfileReadExceptionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfileReadExceptionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfileReadExceptionTest.cs (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1,107 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.IO.SoilProfile; + +namespace Ringtoets.Common.IO.Test.SoilProfile +{ + [TestFixture] + public class SoilProfileReadExceptionTest : + CustomExceptionDesignGuidelinesTestFixture + { + [Test] + public void TypeParameterAndMessageConstructor_ExpectedValues() + { + // Setup + const string profileName = ""; + const string messageText = ""; + + // Call + var exception = new SoilProfileReadException(messageText, profileName); + + // Assert + base.AssertMessageConstructedInstance(exception, messageText, false); + Assert.AreEqual(profileName, exception.ProfileName); + Assert.AreEqual(1, exception.Data.Count); + Assert.AreEqual(exception.ProfileName, exception.Data[nameof(exception.ProfileName)]); + } + + [Test] + public void TypeParameterAndMessageAndInnerExceptionConstructor_ExpectedValues() + { + // Setup + var innerException = new Exception(); + const string profileName = ""; + const string messageText = ""; + + // Call + var exception = new SoilProfileReadException(messageText, profileName, innerException); + + // Assert + AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, false); + Assert.AreEqual(profileName, exception.ProfileName); + Assert.AreEqual(1, exception.Data.Count); + Assert.AreEqual(exception.ProfileName, exception.Data[nameof(exception.ProfileName)]); + } + + protected override void AssertDefaultConstructedInstance(SoilProfileReadException exception) + { + base.AssertDefaultConstructedInstance(exception); + CollectionAssert.IsEmpty(exception.Data); + Assert.IsNull(exception.ProfileName); + } + + protected override void AssertMessageConstructedInstance(SoilProfileReadException exception, string messageText, + bool assertData = true) + { + base.AssertMessageConstructedInstance(exception, messageText, assertData); + if (assertData) + { + Assert.IsNull(exception.ProfileName); + } + } + + protected override void AssertMessageAndInnerExceptionConstructedInstance(SoilProfileReadException exception, string messageText, + Exception innerException, bool assertData = true) + { + base.AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, assertData); + if (assertData) + { + Assert.IsNull(exception.ProfileName); + } + } + + protected override SoilProfileReadException CreateFullyConfiguredException() + { + var originalInnerException = new Exception("inner"); + return new SoilProfileReadException("", "", originalInnerException); + } + + protected override void AssertRoundTripResult(SoilProfileReadException originalException, SoilProfileReadException persistedException) + { + base.AssertRoundTripResult(originalException, persistedException); + Assert.AreEqual(originalException.ProfileName, persistedException.ProfileName); + } + } +} \ No newline at end of file Fisheye: Tag 72a2809486183c2a0ecfd8a529b4518f852d250d refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SoilProfile1DReader/1dprofileWithEmpty1d.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SoilProfile1DReader/emptyschema.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SoilProfile1DReader/text.txt =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SoilProfile1DReader/text.txt (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SoilProfile1DReader/text.txt (revision 72a2809486183c2a0ecfd8a529b4518f852d250d) @@ -0,0 +1 @@ \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilProfileReader/invalidStochasticSoilProfile1d.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilProfileReader/invalidStochasticSoilProfile2d.soil =================================================================== diff -u Binary files differ