Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/IO/HydraulicModelsSettingsCsvReader.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/IO/HydraulicModelsSettingsCsvReader.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/IO/HydraulicModelsSettingsCsvReader.cs (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -0,0 +1,145 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Settings; + +namespace Ringtoets.HydraRing.Calculation.IO +{ + /// + /// The reader for in csv format. + /// + internal class HydraulicModelsSettingsCsvReader : HydraRingSettingsCsvReader>> + { + private readonly Dictionary columns = new Dictionary + { + { + ringIdKey, 0 + }, + { + variableKey, 1 + }, + { + timeIntegrationSchemeIdKey, 2 + } + }; + + private readonly Dictionary failureMechanismTypes = new Dictionary + { + { + assessmentLevelKey, HydraRingFailureMechanismType.AssessmentLevel + }, + { + waveHeightKey, HydraRingFailureMechanismType.WaveHeight + }, + { + wavePeakPeriodKey, HydraRingFailureMechanismType.WavePeakPeriod + }, + { + waveSpectralPeriodKey, HydraRingFailureMechanismType.WaveSpectralPeriod + }, + { + qVariantKey, HydraRingFailureMechanismType.QVariant + }, + { + dikeHeightKey, HydraRingFailureMechanismType.DikesHeight + }, + { + grassKey, HydraRingFailureMechanismType.DikesOvertopping + }, + { + heightStructuresKey, HydraRingFailureMechanismType.StructuresOvertopping + }, + { + closingStructuresKey, HydraRingFailureMechanismType.StructuresClosure + }, + { + structuresStructuralFailureKey, HydraRingFailureMechanismType.StructuresStructuralFailure + } + }; + + /// + /// Creates a new instance of . + /// + /// The file contents to read. + /// Thrown when is not set. + public HydraulicModelsSettingsCsvReader(string fileContents) + : base(fileContents, new Dictionary>()) {} + + protected override void CreateSetting(IList line) + { + // Get failure mechanism + var failureMechanismType = GetFailureMechanismType(line); + + if (!Settings.ContainsKey(failureMechanismType)) + { + Settings.Add(failureMechanismType, new Dictionary()); + } + + // Get TrajectId + var ringId = GetRingId(line); + if (!Settings[failureMechanismType].ContainsKey(ringId)) + { + Settings[failureMechanismType].Add(ringId, GetHydraulicModelsSetting(line)); + } + } + + private HydraRingFailureMechanismType GetFailureMechanismType(IList line) + { + return failureMechanismTypes[GetStringValueFromElement(line[columns[variableKey]])]; + } + + private string GetRingId(IList line) + { + return GetStringValueFromElement(line[columns[ringIdKey]]); + } + + private HydraulicModelsSetting GetHydraulicModelsSetting(IList line) + { + return new HydraulicModelsSetting(GetIntValueFromElement(line[columns[timeIntegrationSchemeIdKey]])); + } + + #region Csv column names + + private const string ringIdKey = "TrajectID"; + private const string variableKey = "Variable"; + private const string timeIntegrationSchemeIdKey = "TimeIntegrationSchemeIdKey"; + + #endregion + + #region Variable names + + private const string assessmentLevelKey = "Toetspeil"; + private const string waveHeightKey = "Hs"; + private const string wavePeakPeriodKey = "Tp"; + private const string waveSpectralPeriodKey = "Tm-1,0"; + private const string qVariantKey = "Q"; + private const string dikeHeightKey = "HBN"; + private const string grassKey = "Gras"; + private const string heightStructuresKey = "KwHoogte"; + private const string closingStructuresKey = "KwSluiten"; + private const string structuresStructuralFailureKey = "KwPuntconstructies"; + + #endregion + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj =================================================================== diff -u -rc7e32b257edeb48a4f426fa414ac253440c54228 -r44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision c7e32b257edeb48a4f426fa414ac253440c54228) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -70,6 +70,7 @@ + Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/DesignTablesSettingsCsvReaderTest.cs =================================================================== diff -u -rc99a72f80fc8db3a8a6fd0db0d1181bcda1e0f8f -r44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/DesignTablesSettingsCsvReaderTest.cs (.../DesignTablesSettingsCsvReaderTest.cs) (revision c99a72f80fc8db3a8a6fd0db0d1181bcda1e0f8f) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/DesignTablesSettingsCsvReaderTest.cs (.../DesignTablesSettingsCsvReaderTest.cs) (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -65,7 +65,7 @@ { string fileContents = streamReader.ReadToEnd(); - DesignTablesSettingsCsvReader reader = new DesignTablesSettingsCsvReader(fileContents); + var reader = new DesignTablesSettingsCsvReader(fileContents); IDictionary> expectedDictionary = GetDictionary(); // Call Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/HydraulicModelsSettingsCsvReaderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/HydraulicModelsSettingsCsvReaderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/IO/HydraulicModelsSettingsCsvReaderTest.cs (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -0,0 +1,182 @@ +// 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.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Settings; +using Ringtoets.HydraRing.Calculation.IO; + +namespace Ringtoets.HydraRing.Calculation.Test.IO +{ + [TestFixture] + public class HydraulicModelsSettingsCsvReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation, "Settings"); + + [Test] + public void Constructor_ExpectedValues() + { + // Call + HydraulicModelsSettingsCsvReader reader = new HydraulicModelsSettingsCsvReader("path.csv"); + + // Assert + Assert.IsInstanceOf>>>(reader); + } + + [Test] + public void Constructor_PathNotSet_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new HydraulicModelsSettingsCsvReader(null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "File contents must be set."); + } + + [Test] + public void ReadSettings_ValidFile_ReturnsSettings() + { + // Setup + string testFile = Path.Combine(testDataPath, "HydraulicModelsSettingsTest.csv"); + + using (StreamReader streamReader = new StreamReader(testFile)) + { + string fileContents = streamReader.ReadToEnd(); + + var reader = new HydraulicModelsSettingsCsvReader(fileContents); + IDictionary> expectedDictionary = GetDictionary(); + + // Call + IDictionary> settings = reader.ReadSettings(); + + // Assert + Assert.AreEqual(10, settings.Count); + + foreach (KeyValuePair> expectedMechanism in expectedDictionary) + { + Assert.IsTrue(settings.ContainsKey(expectedMechanism.Key)); + Assert.IsInstanceOf>(settings[expectedMechanism.Key]); + + foreach (KeyValuePair expectedDesignTablesSetting in expectedMechanism.Value) + { + Assert.IsTrue(settings[expectedMechanism.Key].ContainsKey(expectedDesignTablesSetting.Key)); + Assert.IsInstanceOf(settings[expectedMechanism.Key][expectedDesignTablesSetting.Key]); + + HydraulicModelsSetting setting = settings[expectedMechanism.Key][expectedDesignTablesSetting.Key]; + + Assert.AreEqual(expectedDesignTablesSetting.Value.TimeIntergrationSchemeId, setting.TimeIntergrationSchemeId); + } + } + } + } + + private static IDictionary> GetDictionary() + { + return new Dictionary> + { + { + HydraRingFailureMechanismType.AssessmentLevel, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.QVariant, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.WaveHeight, new Dictionary + { + { + "205", new HydraulicModelsSetting(2) + } + } + }, + { + HydraRingFailureMechanismType.WavePeakPeriod, new Dictionary + { + { + "205", new HydraulicModelsSetting(3) + } + } + }, + { + HydraRingFailureMechanismType.WaveSpectralPeriod, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.DikesHeight, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.DikesOvertopping, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.StructuresOvertopping, new Dictionary + { + { + "205", new HydraulicModelsSetting(1) + } + } + }, + { + HydraRingFailureMechanismType.StructuresClosure, new Dictionary + { + { + "205", new HydraulicModelsSetting(2) + } + } + }, + { + HydraRingFailureMechanismType.StructuresStructuralFailure, new Dictionary + { + { + "205", new HydraulicModelsSetting(2) + } + } + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj =================================================================== diff -u -r37e90777a8ff40061ba8f613963a77a1d1264947 -r44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision 37e90777a8ff40061ba8f613963a77a1d1264947) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -76,6 +76,7 @@ + Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Settings/HydraulicModelsSettingsTest.csv =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Settings/HydraulicModelsSettingsTest.csv (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Settings/HydraulicModelsSettingsTest.csv (revision 44d85a660b65ecf101a5cd1e9b0a8eafe7ff8bad) @@ -0,0 +1,11 @@ +"TrajectID;""Variabele"";""TimeIntegrationSchemeID""" +"205;""Toetspeil"";1" +"205;""Q"";1" +"205;""Hs"";2" +"205;""Tp"";3" +"205;""Tm-1,0"";1" +"205;""HBN"";1" +"205;""Gras"";1" +"205;""KwHoogte"";1" +"205;""KwSluiten"";2" +"205;""KwPuntconstructies"";2" \ No newline at end of file