Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj
===================================================================
diff -u -re41a8cc75ec6e93aee52452aa50f47638a044feb -r887a554f8ed7f16c3d4ad14e89a91fe6a087fa76
--- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision e41a8cc75ec6e93aee52452aa50f47638a044feb)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 887a554f8ed7f16c3d4ad14e89a91fe6a087fa76)
@@ -132,6 +132,7 @@
+
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/ShearStrengthModelConverter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/ShearStrengthModelConverter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/ShearStrengthModelConverter.cs (revision 887a554f8ed7f16c3d4ad14e89a91fe6a087fa76)
@@ -0,0 +1,68 @@
+// 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.Globalization;
+
+namespace Ringtoets.Common.IO.SoilProfile
+{
+ ///
+ /// This class provides helpers for converting values from the D-Soil Model database into
+ /// .
+ ///
+ public static class ShearStrengthModelConverter
+ {
+ ///
+ /// Converts a nullable into a .
+ ///
+ /// The value to convert.
+ /// The .
+ /// Thrown when
+ /// could not be converted.
+ public static ShearStrengthModel Convert(double? shearStrengthValue)
+ {
+ if (shearStrengthValue == null)
+ {
+ return ShearStrengthModel.None;
+ }
+
+ if (shearStrengthValue.Value.Equals(0.0))
+ {
+ return ShearStrengthModel.None;
+ }
+ if (shearStrengthValue.Value.Equals(1.0))
+ {
+ return ShearStrengthModel.SuCalculated;
+ }
+ if (shearStrengthValue.Value.Equals(2.0))
+ {
+ return ShearStrengthModel.CPhi;
+ }
+ if (shearStrengthValue.Value.Equals(3.0))
+ {
+ return ShearStrengthModel.CPhiOrSuCalculated;
+ }
+
+ string message = $"Cannot convert a value of {shearStrengthValue.Value.ToString(CultureInfo.CurrentCulture)} to {typeof(ShearStrengthModel)}.";
+ throw new ArgumentException(message);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj
===================================================================
diff -u -re41a8cc75ec6e93aee52452aa50f47638a044feb -r887a554f8ed7f16c3d4ad14e89a91fe6a087fa76
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision e41a8cc75ec6e93aee52452aa50f47638a044feb)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 887a554f8ed7f16c3d4ad14e89a91fe6a087fa76)
@@ -113,6 +113,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/ShearStrengthModelConverterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/ShearStrengthModelConverterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/ShearStrengthModelConverterTest.cs (revision 887a554f8ed7f16c3d4ad14e89a91fe6a087fa76)
@@ -0,0 +1,73 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.IO.SoilProfile;
+
+namespace Ringtoets.Common.IO.Test.SoilProfile
+{
+ [TestFixture]
+ public class ShearStrengthModelConverterTest
+ {
+ [Test]
+ public void Convert_Null_ReturnsDefaultValue()
+ {
+ // Call
+ ShearStrengthModel model = ShearStrengthModelConverter.Convert(null);
+
+ // Assert
+ Assert.AreEqual(ShearStrengthModel.None, model);
+ }
+
+ [Test]
+ [TestCase(0, ShearStrengthModel.None)]
+ [TestCase(1, ShearStrengthModel.SuCalculated)]
+ [TestCase(2, ShearStrengthModel.CPhi)]
+ [TestCase(3, ShearStrengthModel.CPhiOrSuCalculated)]
+ public void Convert_ValidValues_ReturnsExpectedValues(double value, ShearStrengthModel expectedShearStrengthModel)
+ {
+ // Call
+ ShearStrengthModel model = ShearStrengthModelConverter.Convert(value);
+
+ // Assert
+ Assert.AreEqual(expectedShearStrengthModel, model);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCase(3.5)]
+ [TestCase(-0.5)]
+ [TestCase(double.NaN)]
+ [TestCase(double.NegativeInfinity)]
+ [TestCase(double.PositiveInfinity)]
+ public void Convert_InvalidNumericValues_ThrowsArgumentException(double value)
+ {
+ // Call
+ TestDelegate call = () => ShearStrengthModelConverter.Convert(value);
+
+ // Assert
+ string expectedErrorMessage = $"Cannot convert a value of {value} to {typeof(ShearStrengthModel)}.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedErrorMessage);
+ }
+ }
+}
\ No newline at end of file