Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r41bb6fead786a8604ac48a292f51c7154cf74196 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 41bb6fead786a8604ac48a292f51c7154cf74196) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -317,6 +317,33 @@ } /// + /// Looks up a localized string similar to Kon geen ondergrond modellen verkrijgen van de database.. + /// + public static string StochasticSoilModelDatabaseReader_failed_to_read_database { + get { + return ResourceManager.GetString("StochasticSoilModelDatabaseReader_failed_to_read_database", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het uitlezen van een stochastisch ondergrondsmodel misgelukt, deze zal worden overgeslagen.. + /// + public static string StochasticSoilModelDatabaseReader_failed_to_read_soil_model { + get { + return ResourceManager.GetString("StochasticSoilModelDatabaseReader_failed_to_read_soil_model", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De coördinaten van het stochastisch ondergrondsmodel bevatten geen geldige waarde.. + /// + public static string StochasticSoilModelDatabaseReader_SegmentPoint_has_invalid_value { + get { + return ResourceManager.GetString("StochasticSoilModelDatabaseReader_SegmentPoint_has_invalid_value", resourceCulture); + } + } + + /// /// Looks up a localized string similar to op regel {0}. /// public static string TextFile_On_LineNumber_0_ { Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx =================================================================== diff -u -r41bb6fead786a8604ac48a292f51c7154cf74196 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision 41bb6fead786a8604ac48a292f51c7154cf74196) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -204,4 +204,13 @@ Profielmeting heeft een geometrie die een lijn met lengte 0 beschrijft. + + Het uitlezen van een stochastisch ondergrondsmodel misgelukt, deze zal worden overgeslagen. + + + Kon geen ondergrond modellen verkrijgen van de database. + + + De coördinaten van het stochastisch ondergrondsmodel bevatten geen geldige waarde. + \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj =================================================================== diff -u -r968645e02cdc2c21c899fa8099589c779138be54 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 968645e02cdc2c21c899fa8099589c779138be54) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -48,6 +48,16 @@ + + + + + + + + + + @@ -97,6 +107,10 @@ + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/DSoilQueryBuilder.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/DSoilQueryBuilder.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/DSoilQueryBuilder.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; + +namespace Ringtoets.Piping.IO.SoilProfile +{ + public static class DSoilQueryBuilder + { + public static string GetStochasticSoilModelOfPipingMechanismQuery() + { + return String.Format(@"SELECT SP.{8}, SP.{9}, S.{10}, SSM.{11}, SSM.{12} " + + "FROM {0} M " + + "INNER JOIN {1} S USING({4}) " + + "INNER JOIN {2} SSM USING({5}) " + + "INNER JOIN {3} SP USING({6}) " + + "WHERE M.{7} = @{7} ORDER BY SSM.{12};", + MechanismDatabaseColumns.TableName, + SegmentDatabaseColumns.TableName, + StochasticSoilModelDatabaseColumns.TableName, + SegmentPointsDatabaseColumns.TableName, + SegmentDatabaseColumns.MechanismId, + StochasticSoilModelDatabaseColumns.StochasticSoilModelId, + SegmentPointsDatabaseColumns.SegmentId, + MechanismDatabaseColumns.MechanismName, + SegmentPointsDatabaseColumns.CoordinateX, + SegmentPointsDatabaseColumns.CoordinateY, + SegmentDatabaseColumns.SegmentName, + StochasticSoilModelDatabaseColumns.StochasticSoilModelName, + StochasticSoilModelDatabaseColumns.StochasticSoilModelId + ); + } + + public static string GetAllStochasticSoilProfileQuery() + { + return String.Format("SELECT {1}, {2}, {3}, {4} FROM {0} ORDER BY {1};", + StochasticSoilProfileDatabaseColumns.TableName, + StochasticSoilProfileDatabaseColumns.StochasticSoilModelId, + StochasticSoilProfileDatabaseColumns.Probability, + StochasticSoilProfileDatabaseColumns.SoilProfile1DId, + StochasticSoilProfileDatabaseColumns.SoilProfile2DId + ); + } + + public static string GetCheckVersionQuery() + { + return String.Format( + "SELECT {2} FROM {0} WHERE {1} = 'VERSION' AND {2} = @{2};", + MetaDataDatabaseColumns.TableName, + MetaDataDatabaseColumns.Key, + MetaDataDatabaseColumns.Value + ); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MechanismDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MechanismDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MechanismDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,30 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + internal static class MechanismDatabaseColumns + { + internal const string TableName = "Mechanism"; + internal const string MechanismId = "ME_ID"; + internal const string MechanismName = "ME_Name"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MetaDataDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MetaDataDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/MetaDataDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,9 @@ +namespace Ringtoets.Piping.IO.SoilProfile +{ + internal static class MetaDataDatabaseColumns + { + internal const string TableName = "_MetaData"; + internal const string Key = "Key"; + internal const string Value = "Value"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + internal static class SegmentDatabaseColumns + { + internal const string TableName = "Segment"; + internal const string SegmentId = "SE_ID"; + internal const string StochasticSoilModelId = "SSM_ID"; + internal const string MechanismId = "ME_ID"; + internal const string SegmentName = "SE_Name"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentPointsDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentPointsDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SegmentPointsDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + internal static class SegmentPointsDatabaseColumns + { + internal const string TableName = "SegmentPoints"; + internal const string SegmentPointsId = "SEGP_ID"; + internal const string SegmentId = "SE_ID"; + internal const string CoordinateX = "XWorld"; + internal const string CoordinateY = "YWorld"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,34 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + /// + /// This class contains the names of the table and columns of the table + /// 'StochasticSoilModel' of the DSoil-Model database. + /// + internal static class StochasticSoilModelDatabaseColumns + { + internal const string TableName = "StochasticSoilModel"; + internal const string StochasticSoilModelId = "SSM_ID"; + internal const string StochasticSoilModelName = "SSM_Name"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseReader.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseReader.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelDatabaseReader.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,251 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SQLite; +using Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.Utils.Builders; +using log4net; +using Ringtoets.Piping.IO.Properties; + +namespace Ringtoets.Piping.IO.SoilProfile +{ + public class StochasticSoilModelDatabaseReader : SqLiteDatabaseReaderBase + { + private const string databaseRequiredVersion = "15.0.5.0"; + private const string pipingMechanismName = "Piping"; + + private static readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilModelDatabaseReader)); + + private SQLiteDataReader stochasticSoilProfilesDataReader; + + public StochasticSoilModelDatabaseReader(string databaseFilePath) : base(databaseFilePath) + { + VerifyVersion(); + } + + /// + /// Reads the of failure mechanism "Piping" from the databae. + /// + /// List of , read from the database. + /// Thrown when failed to read the database. + public IEnumerable GetStochasticSoilModelSegmentOfPiping() + { + var stochasticSoilModelSegmentsQuery = DSoilQueryBuilder.GetStochasticSoilModelOfPipingMechanismQuery(); + var sqliteParameter = new SQLiteParameter + { + DbType = DbType.String, + ParameterName = String.Format("@{0}", MechanismDatabaseColumns.MechanismName), + Value = pipingMechanismName + }; + + try + { + if (!PrepareStochasticSoilProfilesDataReader()) + { + return null; + } + using (SQLiteDataReader dataReader = CreateDataReader(stochasticSoilModelSegmentsQuery, sqliteParameter)) + { + return ReadStochasticSoilModels(dataReader); + } + } + catch (SQLiteException exception) + { + var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilModelDatabaseReader_failed_to_read_database); + throw new CriticalFileReadException(message, exception); + } + } + + public override void Dispose() + { + if (stochasticSoilProfilesDataReader != null) + { + stochasticSoilProfilesDataReader.Dispose(); + } + base.Dispose(); + } + + private IEnumerable ReadStochasticSoilModels(SQLiteDataReader dataReader) + { + var segmentSoilModels = new List(); + StochasticSoilModelSegment currentStochasticSoilModelSegment = null; + while (MoveNext(dataReader)) + { + // Read Points + var point2D = ReadSegmentPoint(dataReader); + if (point2D == null) + { + continue; + } + + // Read SoilModels + var segmentSoilModel = ReadSoilModels(dataReader); + if (currentStochasticSoilModelSegment == null || + segmentSoilModel.SegmentSoilModelId != currentStochasticSoilModelSegment.SegmentSoilModelId) + { + currentStochasticSoilModelSegment = segmentSoilModel; + + var probabilityList = ReadProbability(currentStochasticSoilModelSegment.SegmentSoilModelId); + if (probabilityList == null) + { + // Probability could not be read, ignore StochasticSoilModelSegment + continue; + } + foreach (var probability in probabilityList) + { + currentStochasticSoilModelSegment.StochasticSoilProfileProbabilities.Add(probability); + } + + // Add + segmentSoilModels.Add(segmentSoilModel); + } + currentStochasticSoilModelSegment.SegmentPoints.Add(point2D); + } + return segmentSoilModels; + } + + private bool PrepareStochasticSoilProfilesDataReader() + { + var stochasticSoilModelSegmentsQuery = DSoilQueryBuilder.GetAllStochasticSoilProfileQuery(); + stochasticSoilProfilesDataReader = CreateDataReader(stochasticSoilModelSegmentsQuery); + + if (!stochasticSoilProfilesDataReader.HasRows) + { + return false; + } + MoveNext(stochasticSoilProfilesDataReader); + return true; + } + + private IEnumerable ReadProbability(long stochasticSoilModelId) + { + var probabilityList = new List(); + try + { + long currentStochasticSoilModelId; + do + { + currentStochasticSoilModelId = ReadStochasticSoilModelId(stochasticSoilProfilesDataReader); + if (currentStochasticSoilModelId == stochasticSoilModelId) + { + probabilityList.Add(ReadStochasticSoilProfileProbability(stochasticSoilProfilesDataReader)); + } + if (currentStochasticSoilModelId <= stochasticSoilModelId) + { + MoveNext(stochasticSoilProfilesDataReader); + } + } while (currentStochasticSoilModelId <= stochasticSoilModelId && stochasticSoilProfilesDataReader.HasRows); + } + catch (Exception exception) + { + if (exception is FormatException || exception is OverflowException || exception is InvalidCastException) + { + log.Warn(Resources.StochasticSoilModelDatabaseReader_failed_to_read_soil_model); + return null; + } + throw; + } + return probabilityList; + } + + private static long ReadStochasticSoilModelId(SQLiteDataReader dataReader) + { + return Convert.ToInt64(dataReader[StochasticSoilProfileDatabaseColumns.StochasticSoilModelId]); + } + + private static StochasticSoilProfileProbability ReadStochasticSoilProfileProbability(SQLiteDataReader dataReader) + { + var valueSoilProfile1DId = dataReader[StochasticSoilProfileDatabaseColumns.SoilProfile1DId]; + var soilProfile1DId = (valueSoilProfile1DId.Equals(DBNull.Value)) ? (long?) null : Convert.ToInt64(valueSoilProfile1DId); + + var valueSoilProfile2DId = dataReader[StochasticSoilProfileDatabaseColumns.SoilProfile2DId]; + var soilProfile2DId = (valueSoilProfile2DId.Equals(DBNull.Value)) ? (long?) null : Convert.ToInt64(valueSoilProfile2DId); + + var valueProbability = dataReader[StochasticSoilProfileDatabaseColumns.Probability]; + var probability = (valueProbability.Equals(DBNull.Value)) ? 0 : Convert.ToDouble(valueProbability); + + return new StochasticSoilProfileProbability(probability, soilProfile1DId, soilProfile2DId); + } + + private StochasticSoilModelSegment ReadSoilModels(SQLiteDataReader dataReader) + { + var stochasticSoilModelId = Convert.ToInt64(dataReader[StochasticSoilModelDatabaseColumns.StochasticSoilModelId]); + var stochasticSoilModelName = Convert.ToString(dataReader[StochasticSoilModelDatabaseColumns.StochasticSoilModelName]); + var segmentName = Convert.ToString(dataReader[SegmentDatabaseColumns.SegmentName]); + return new StochasticSoilModelSegment(stochasticSoilModelId, stochasticSoilModelName, segmentName); + } + + private void VerifyVersion() + { + var checkVersionQuery = DSoilQueryBuilder.GetCheckVersionQuery(); + var sqliteParameter = new SQLiteParameter + { + DbType = DbType.String, + ParameterName = String.Format("@{0}", MetaDataDatabaseColumns.Value), + Value = databaseRequiredVersion + }; + + try + { + using (SQLiteDataReader dataReader = CreateDataReader(checkVersionQuery, sqliteParameter)) + { + if (!dataReader.HasRows) + { + Dispose(); + throw new CriticalFileReadException(String.Format( + Resources.PipingSoilProfileReader_Database_incorrect_version_requires_Version_0_, + databaseRequiredVersion)); + } + } + } + catch (SQLiteException exception) + { + Dispose(); + var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilModelDatabaseReader_failed_to_read_database); + throw new CriticalFileReadException(message, exception); + } + } + + private Point2D ReadSegmentPoint(SQLiteDataReader dataReader) + { + try + { + double coordinateX = Convert.ToDouble(dataReader[SegmentPointsDatabaseColumns.CoordinateX]); + double coordinateY = Convert.ToDouble(dataReader[SegmentPointsDatabaseColumns.CoordinateY]); + return new Point2D(coordinateX, coordinateY); + } + catch (Exception exception) + { + if (exception is FormatException || exception is OverflowException || exception is InvalidCastException) + { + log.Warn(Resources.StochasticSoilModelDatabaseReader_SegmentPoint_has_invalid_value); + return null; + } + throw; + } + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelSegment.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelSegment.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilModelSegment.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Core.Common.Base.Geometry; + +namespace Ringtoets.Piping.IO.SoilProfile +{ + public class StochasticSoilModelSegment + { + public StochasticSoilModelSegment(long segmentSoilModelId, string segmentSoilModelName, string segmentName) + { + SegmentSoilModelId = segmentSoilModelId; + SegmentSoilModelName = segmentSoilModelName; + SegmentName = segmentName; + SegmentPoints = new List(); + StochasticSoilProfileProbabilities = new List(); + } + + public long SegmentSoilModelId { get; private set; } + public string SegmentSoilModelName { get; private set; } + + public string SegmentName { get; private set; } + + public List SegmentPoints { get; private set; } + public List StochasticSoilProfileProbabilities { get; private set; } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileDatabaseColumns.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileDatabaseColumns.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileDatabaseColumns.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + internal static class StochasticSoilProfileDatabaseColumns + { + internal const string TableName = "StochasticSoilProfile"; + internal const string StochasticSoilModelId = "SSM_ID"; + internal const string SoilProfile1DId = "SP1D_ID"; + internal const string SoilProfile2DId = "SP2D_ID"; + internal const string Probability = "Probability"; + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileProbability.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileProbability.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/StochasticSoilProfileProbability.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,37 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Ringtoets.Piping.IO.SoilProfile +{ + public class StochasticSoilProfileProbability + { + public StochasticSoilProfileProbability(double probability, long? soilProfile1DId, long? soilProfile2DId) + { + Probability = probability; + SoilProfile1DId = soilProfile1DId; + SoilProfile2DId = soilProfile2DId; + } + + public long? SoilProfile1DId { get; private set; } + public long? SoilProfile2DId { get; private set; } + public double Probability { get; private set; } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/packages.config =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/packages.config (.../packages.config) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/packages.config (.../packages.config) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -23,5 +23,6 @@ All rights reserved. --> + \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj =================================================================== diff -u -rd36795ad93a8aaf9daccd85f143b15562f963fb3 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision d36795ad93a8aaf9daccd85f143b15562f963fb3) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -51,6 +51,7 @@ + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net40\System.Data.SQLite.dll True @@ -65,6 +66,10 @@ + + + + @@ -108,6 +113,9 @@ + + Copying.licenseheader + Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/DSoilQueryBuilderTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/DSoilQueryBuilderTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/DSoilQueryBuilderTest.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using NUnit.Framework; +using Ringtoets.Piping.IO.SoilProfile; + +namespace Ringtoets.Piping.IO.Test.SoilProfile +{ + [TestFixture] + public class DSoilQueryBuilderTest + { + [Test] + public void GetStochasticSoilModelOfPipingMechanismQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT SP.XWorld, SP.YWorld, S.SE_Name, SSM.SSM_Name, SSM.SSM_ID " + + "FROM Mechanism M " + + "INNER JOIN Segment S USING(ME_ID) " + + "INNER JOIN StochasticSoilModel SSM USING(SSM_ID) " + + "INNER JOIN SegmentPoints SP USING(SE_ID) " + + "WHERE M.ME_Name = @ME_Name ORDER BY SSM.SSM_ID;"; + + // Call + string query = DSoilQueryBuilder.GetStochasticSoilModelOfPipingMechanismQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetAllStochasticSoilProfileQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT SSM_ID, Probability, SP1D_ID, SP2D_ID " + + "FROM StochasticSoilProfile " + + "ORDER BY SSM_ID;"; + + // Call + string query = DSoilQueryBuilder.GetAllStochasticSoilProfileQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetCheckVersionQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT Value " + + "FROM _MetaData " + + "WHERE Key = 'VERSION' AND Value = @Value;"; + + // Call + string query = DSoilQueryBuilder.GetCheckVersionQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs =================================================================== diff -u -rc6dd26c14af11a7e13f783f578466e46b463165a -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision c6dd26c14af11a7e13f783f578466e46b463165a) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -1,4 +1,25 @@ -using System; +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -12,11 +33,11 @@ using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.IO.SoilProfile; -using Ringtoets.Piping.IO.Test.TestHelpers; using UtilsResources = Core.Common.Utils.Properties.Resources; namespace Ringtoets.Piping.IO.Test.SoilProfile { + [TestFixture] public class PipingSoilProfileReaderTest { private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "PipingSoilProfilesReader"); @@ -95,7 +116,6 @@ var dbName = "emptyschema.soil"; var dbFile = Path.Combine(testDataPath, dbName); - // Call using (var pipingSoilProfileReader = new PipingSoilProfileReader(dbFile)) { @@ -238,9 +258,9 @@ Assert.AreEqual("Profile", profile.Name); Assert.AreEqual(3, profile.Layers.Count()); CollectionAssert.AreEqual(Enumerable.Repeat(false, 3), profile.Layers.Select(l => l.IsAquifer)); - CollectionAssert.AreEqual(Enumerable.Repeat((double?)null, 3), profile.Layers.Select(l => l.AbovePhreaticLevel)); - CollectionAssert.AreEqual(Enumerable.Repeat((double?)null, 3), profile.Layers.Select(l => l.BelowPhreaticLevel)); - CollectionAssert.AreEqual(Enumerable.Repeat((double?)null, 3), profile.Layers.Select(l => l.DryUnitWeight)); + CollectionAssert.AreEqual(Enumerable.Repeat((double?) null, 3), profile.Layers.Select(l => l.AbovePhreaticLevel)); + CollectionAssert.AreEqual(Enumerable.Repeat((double?) null, 3), profile.Layers.Select(l => l.BelowPhreaticLevel)); + CollectionAssert.AreEqual(Enumerable.Repeat((double?) null, 3), profile.Layers.Select(l => l.DryUnitWeight)); } } Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelDatabaseReaderTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelDatabaseReaderTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelDatabaseReaderTest.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,310 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Data.SQLite; +using System.IO; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using Core.Common.Utils.Builders; +using NUnit.Framework; +using Ringtoets.Piping.IO.Properties; +using Ringtoets.Piping.IO.SoilProfile; +using UtilsResources = Core.Common.Utils.Properties.Resources; + +namespace Ringtoets.Piping.IO.Test.SoilProfile +{ + [TestFixture] + public class StochasticSoilModelDatabaseReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "StochasticSoilModelDatabaseReader"); + + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + var testFile = Path.Combine(testDataPath, "none.soil"); + + // Call + TestDelegate test = () => new StochasticSoilModelDatabaseReader(testFile).Dispose(); + + // Assert + var exception = Assert.Throws(test); + var expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(UtilsResources.Error_File_does_not_exist); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string fileName) + { + // Setup + var expectedMessage = String.Format("Fout bij het lezen van bestand '{0}': {1}", + fileName, UtilsResources.Error_Path_must_be_specified); + // Call + TestDelegate test = () => new StochasticSoilModelDatabaseReader(fileName).Dispose(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + [TestCase("text.txt")] + [TestCase("empty.soil")] + public void Constructor_IncorrectFormatFileOrInvalidSchema_ThrowsPipingCriticalFileReadException(string dbName) + { + // Setup + var dbFile = Path.Combine(testDataPath, dbName); + var expectedMessage = new FileReaderErrorMessageBuilder(dbFile). + Build(String.Format(Resources.StochasticSoilModelDatabaseReader_failed_to_read_database, dbName)); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + // Call + TestDelegate test = () => new StochasticSoilModelDatabaseReader(dbFile).Dispose(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ParameteredConstructor_PathToExistingFile_ExpectedValues() + { + // Setup + var dbName = "emptyschema.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + + // Call + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Assert + Assert.AreEqual(dbFile, stochasticSoilModelDatabaseReader.Path); + Assert.IsInstanceOf(stochasticSoilModelDatabaseReader); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void Constructor_IncorrectVersion_ThrowsCriticalFileReadException() + { + // Setup + const string version = "15.0.5.0"; + string expectedVersionMessage = String.Format(Resources.PipingSoilProfileReader_Database_incorrect_version_requires_Version_0_, version); + const string dbName = "incorrectversion.soil"; + var dbFile = Path.Combine(testDataPath, dbName); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + // Call + TestDelegate test = () => new StochasticSoilModelDatabaseReader(dbFile).Dispose(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedVersionMessage, exception.Message); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetStochasticSoilModelSegmentOfPiping_EmptyFileThatPassesVersionCheck_ReturnsEmptyList() + { + // Setup + var dbName = "emptyschema.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + IEnumerable stochasticSoilModelSegment; + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Call + stochasticSoilModelSegment = stochasticSoilModelDatabaseReader.GetStochasticSoilModelSegmentOfPiping(); + } + + // Assert + Assert.IsNull(stochasticSoilModelSegment); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetStochasticSoilModelSegmentOfPiping_CompleteScenario_ReturnsExpectedValues() + { + // Setup + List segmentSoilModels; + const string dbName = "complete.soil"; + var dbFile = Path.Combine(testDataPath, dbName); + const int expectedSegmentSoilModels = 3; + + const string expectedSegmentName1 = "36005_Piping"; + const string expectedSegmentSoilModelName1 = "36005_Piping"; + const long expectedSegmentSoilModelId1 = 2; + const long expectedSegmentSoilModelPoints1 = 1797; + const long expectedSegmentSoilModelProbabilities1 = 10; + + const string expectedSegmentName2 = "36006_Piping"; + const string expectedSegmentSoilModelName2 = "36006_Piping"; + const long expectedSegmentSoilModelId2 = 4; + const long expectedSegmentSoilModelPoints2 = 144; + const long expectedSegmentSoilModelProbabilities2 = 6; + + const string expectedSegmentName3 = "36007_Piping"; + const string expectedSegmentSoilModelName3 = "36007_Piping"; + const long expectedSegmentSoilModelId3 = 6; + const long expectedSegmentSoilModelPoints3 = 606; + const long expectedSegmentSoilModelProbabilities3 = 8; + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Call + segmentSoilModels = stochasticSoilModelDatabaseReader.GetStochasticSoilModelSegmentOfPiping().ToList(); + } + + // Assert + Assert.IsInstanceOf>(segmentSoilModels); + CollectionAssert.AllItemsAreInstancesOfType(segmentSoilModels, typeof(StochasticSoilModelSegment)); + Assert.AreEqual(expectedSegmentSoilModels, segmentSoilModels.Count); + + StochasticSoilModelSegment stochasticSoilModelSegmentSoilModel1 = segmentSoilModels[0]; + Assert.AreEqual(expectedSegmentName1, stochasticSoilModelSegmentSoilModel1.SegmentName); + Assert.AreEqual(expectedSegmentSoilModelName1, stochasticSoilModelSegmentSoilModel1.SegmentSoilModelName); + Assert.AreEqual(expectedSegmentSoilModelId1, stochasticSoilModelSegmentSoilModel1.SegmentSoilModelId); + Assert.AreEqual(expectedSegmentSoilModelPoints1, stochasticSoilModelSegmentSoilModel1.SegmentPoints.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel1.SegmentPoints, typeof(Point2D)); + Assert.AreEqual(expectedSegmentSoilModelProbabilities1, stochasticSoilModelSegmentSoilModel1.StochasticSoilProfileProbabilities.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel1.StochasticSoilProfileProbabilities, typeof(StochasticSoilProfileProbability)); + + StochasticSoilModelSegment stochasticSoilModelSegmentSoilModel2 = segmentSoilModels[1]; + Assert.AreEqual(expectedSegmentName2, stochasticSoilModelSegmentSoilModel2.SegmentName); + Assert.AreEqual(expectedSegmentSoilModelName2, stochasticSoilModelSegmentSoilModel2.SegmentSoilModelName); + Assert.AreEqual(expectedSegmentSoilModelId2, stochasticSoilModelSegmentSoilModel2.SegmentSoilModelId); + Assert.AreEqual(expectedSegmentSoilModelPoints2, stochasticSoilModelSegmentSoilModel2.SegmentPoints.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel2.SegmentPoints, typeof(Point2D)); + Assert.AreEqual(expectedSegmentSoilModelProbabilities2, stochasticSoilModelSegmentSoilModel2.StochasticSoilProfileProbabilities.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel2.StochasticSoilProfileProbabilities, typeof(StochasticSoilProfileProbability)); + + StochasticSoilModelSegment stochasticSoilModelSegmentSoilModel3 = segmentSoilModels[2]; + Assert.AreEqual(expectedSegmentName3, stochasticSoilModelSegmentSoilModel3.SegmentName); + Assert.AreEqual(expectedSegmentSoilModelName3, stochasticSoilModelSegmentSoilModel3.SegmentSoilModelName); + Assert.AreEqual(expectedSegmentSoilModelId3, stochasticSoilModelSegmentSoilModel3.SegmentSoilModelId); + Assert.AreEqual(expectedSegmentSoilModelPoints3, stochasticSoilModelSegmentSoilModel3.SegmentPoints.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel3.SegmentPoints, typeof(Point2D)); + Assert.AreEqual(expectedSegmentSoilModelProbabilities3, stochasticSoilModelSegmentSoilModel3.StochasticSoilProfileProbabilities.Count); + CollectionAssert.AllItemsAreInstancesOfType(stochasticSoilModelSegmentSoilModel3.StochasticSoilProfileProbabilities, typeof(StochasticSoilProfileProbability)); + } + + [Test] + public void GetStochasticSoilModelSegmentOfPiping_SchemaWithoutSoilModelTables_ThrowsCriticalFileReadException() + { + // Setup + var dbName = "withoutSoilModelTables.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.StochasticSoilModelDatabaseReader_failed_to_read_database); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + // Call + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => stochasticSoilModelDatabaseReader.GetStochasticSoilModelSegmentOfPiping(); + + // Assert + CriticalFileReadException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetStochasticSoilModelSegmentOfPiping_InvalidSegmentPoint_SkipsPoint() + { + // Setup + var dbName = "invalidSegmentPoint.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + List stochasticSoilModelSegmentList = null; + const string expectedLogMessage = "De coördinaten van het stochastisch ondergrondsmodel bevatten geen geldige waarde."; + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + // Call + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Call + Action action = () => { stochasticSoilModelSegmentList = stochasticSoilModelDatabaseReader.GetStochasticSoilModelSegmentOfPiping().ToList(); }; + TestHelper.AssertLogMessageIsGenerated(action, expectedLogMessage, 1); + } + + // Assert + Assert.IsInstanceOf>(stochasticSoilModelSegmentList); + Assert.AreEqual(2, stochasticSoilModelSegmentList.Count); + + StochasticSoilModelSegment stochasticSoilModelSegment1 = stochasticSoilModelSegmentList[0]; + Assert.AreEqual(1, stochasticSoilModelSegment1.StochasticSoilProfileProbabilities.Count); + + StochasticSoilModelSegment stochasticSoilModelSegment2 = stochasticSoilModelSegmentList[1]; + Assert.AreEqual(1, stochasticSoilModelSegment2.StochasticSoilProfileProbabilities.Count); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetStochasticSoilModelSegmentOfPiping_InvalidSoilProfile_SkipsModel() + { + // Setup + var dbName = "invalidStochasticSoilProfile.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + List stochasticSoilModelSegmentList = null; + const string expectedLogMessage = "Het uitlezen van een stochastisch ondergrondsmodel misgelukt, deze zal worden overgeslagen."; + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + // Call + using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelDatabaseReader(dbFile)) + { + // Call + Action action = () => { stochasticSoilModelSegmentList = stochasticSoilModelDatabaseReader.GetStochasticSoilModelSegmentOfPiping().ToList(); }; + TestHelper.AssertLogMessageIsGenerated(action, expectedLogMessage, 1); + } + + // Assert + Assert.IsInstanceOf>(stochasticSoilModelSegmentList); + Assert.AreEqual(0, stochasticSoilModelSegmentList.Count); + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelSegmentTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelSegmentTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilModelSegmentTest.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,95 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.IO.SoilProfile; + +namespace Ringtoets.Piping.IO.Test.SoilProfile +{ + [TestFixture] + public class StochasticSoilModelSegmentTest + { + [Test] + [TestCase(1234L, "", "")] + [TestCase(5678L, "segmentSoilModelName", "segmentName")] + public void Constructor_Always_ExpectedValues(long segmentSoilModelId, string segmentSoilModelName, string segmentName) + { + // Call + StochasticSoilModelSegment stochasticSoilModelSegment = new StochasticSoilModelSegment(segmentSoilModelId, segmentSoilModelName, segmentName); + + // Assert + Assert.IsInstanceOf(stochasticSoilModelSegment); + Assert.AreEqual(segmentSoilModelId, stochasticSoilModelSegment.SegmentSoilModelId); + Assert.AreEqual(segmentSoilModelName, stochasticSoilModelSegment.SegmentSoilModelName); + Assert.AreEqual(segmentName, stochasticSoilModelSegment.SegmentName); + CollectionAssert.IsEmpty(stochasticSoilModelSegment.SegmentPoints); + CollectionAssert.IsEmpty(stochasticSoilModelSegment.StochasticSoilProfileProbabilities); + } + + [Test] + public void PropertySegmentPoints_Always_ReturnsExpectedValues() + { + // Setup + const long expectedSegmentSoilModelId = 1234L; + const string expectedSegmentSoilModelName = "someSegmentSoilModelName"; + const string expectedSegmentName = "someSegmentName"; + StochasticSoilModelSegment stochasticSoilModelSegment = new StochasticSoilModelSegment(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName); + var point2D = new Point2D(1.0, 2.0); + + // Call + stochasticSoilModelSegment.SegmentPoints.Add(point2D); + + // Assert + Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModelSegment.SegmentSoilModelId); + Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModelSegment.SegmentSoilModelName); + Assert.AreEqual(expectedSegmentName, stochasticSoilModelSegment.SegmentName); + Assert.AreEqual(1, stochasticSoilModelSegment.SegmentPoints.Count); + Assert.AreEqual(point2D, stochasticSoilModelSegment.SegmentPoints[0]); + } + + [Test] + public void PropertyStochasticSoilProfileProbabilities_Always_ReturnsExpectedValues() + { + // Setup + const long expectedSegmentSoilModelId = 1234L; + const string expectedSegmentSoilModelName = "someSegmentSoilModelName"; + const string expectedSegmentName = "someSegmentName"; + StochasticSoilModelSegment stochasticSoilModelSegment = new StochasticSoilModelSegment(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName); + + MockRepository mockRepository = new MockRepository(); + var stochasticSoilProfileProbabilityMock = mockRepository.StrictMock(1.0, null, null); + mockRepository.ReplayAll(); + + // Call + stochasticSoilModelSegment.StochasticSoilProfileProbabilities.Add(stochasticSoilProfileProbabilityMock); + + // Assert + Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModelSegment.SegmentSoilModelId); + Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModelSegment.SegmentSoilModelName); + Assert.AreEqual(expectedSegmentName, stochasticSoilModelSegment.SegmentName); + Assert.AreEqual(1, stochasticSoilModelSegment.StochasticSoilProfileProbabilities.Count); + Assert.AreEqual(stochasticSoilProfileProbabilityMock, stochasticSoilModelSegment.StochasticSoilProfileProbabilities[0]); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilProfileProbabilityTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilProfileProbabilityTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/StochasticSoilProfileProbabilityTest.cs (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1,47 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using NUnit.Framework; +using Ringtoets.Piping.IO.SoilProfile; + +namespace Ringtoets.Piping.IO.Test.SoilProfile +{ + [TestFixture] + public class StochasticSoilProfileProbabilityTest + { + [Test] + [TestCase(1.0, null, null)] + [TestCase(2.0, 1234L, null)] + [TestCase(3.0, 1235L, 5678L)] + [TestCase(4.0, null, 5679L)] + public void Constructor_Always_ExpectedValues(double probability, long? soilProfile1DId, long? soilProfile2DId) + { + // Call + StochasticSoilProfileProbability stochasticSoilProfileProbability = new StochasticSoilProfileProbability(probability, soilProfile1DId, soilProfile2DId); + + // Assert + Assert.IsInstanceOf(stochasticSoilProfileProbability); + Assert.AreEqual(probability, stochasticSoilProfileProbability.Probability); + Assert.AreEqual(soilProfile1DId, stochasticSoilProfileProbability.SoilProfile1DId); + Assert.AreEqual(soilProfile2DId, stochasticSoilProfileProbability.SoilProfile2DId); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/complete.soil =================================================================== diff -u -ra483049c20ef6d26addd0718d0f31ae1922e6f49 -r14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7 Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/complete.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/empty.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/emptyschema.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/incorrectversion.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/invalidSegmentPoint.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/invalidStochasticSoilProfile.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/text.txt =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/text.txt (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/text.txt (revision 14db78eb3fc065c42f2d92c60d9d6b4b43dc9bd7) @@ -0,0 +1 @@ +SomeText \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/StochasticSoilModelDatabaseReader/withoutSoilModelTables.soil =================================================================== diff -u Binary files differ