Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r31a621e36dfd14666d4ec7bb492b5eb5ea8a9265 -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 31a621e36dfd14666d4ec7bb492b5eb5ea8a9265) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e) @@ -80,6 +80,7 @@ + Code Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs =================================================================== diff -u -r31a621e36dfd14666d4ec7bb492b5eb5ea8a9265 -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensions.cs) (revision 31a621e36dfd14666d4ec7bb492b5eb5ea8a9265) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer1DCreateExtensions.cs (.../MacroStabilityInwardsSoilLayer1DCreateExtensions.cs) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e) @@ -39,7 +39,8 @@ /// The layer to create a database entity for. /// Index at which this instance resides inside its parent container. /// A new . - internal static MacroStabilityInwardsSoilLayer1DEntity Create(this MacroStabilityInwardsSoilLayer1D layer, int order) + internal static MacroStabilityInwardsSoilLayer1DEntity Create(this MacroStabilityInwardsSoilLayer1D layer, + int order) { MacroStabilityInwardsSoilLayerProperties properties = layer.Properties; return new MacroStabilityInwardsSoilLayer1DEntity Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensions.cs (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e) @@ -0,0 +1,81 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Core.Common.Utils.Extensions; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Application.Ringtoets.Storage.Create.MacroStabilityInwards +{ + /// + /// Extension methods for related to creating + /// a . + /// + internal static class MacroStabilityInwardsSoilLayer2DCreateExtensions + { + /// + /// Creates a based on the information + /// of the . + /// + /// The layer to create a database entity for. + /// Index at which this instance resides inside its parent container. + /// A new . + internal static MacroStabilityInwardsSoilLayer2DEntity Create(this MacroStabilityInwardsSoilLayer2D layer, + int order) + { + MacroStabilityInwardsSoilLayerProperties properties = layer.Properties; + return new MacroStabilityInwardsSoilLayer2DEntity + { + IsAquifer = Convert.ToByte(properties.IsAquifer), + MaterialName = properties.MaterialName.DeepClone(), + Color = properties.Color.ToArgb(), + UsePop = Convert.ToByte(properties.UsePop), + ShearStrengthModel = Convert.ToByte(properties.ShearStrengthModel), + + AbovePhreaticLevelMean = properties.AbovePhreaticLevelMean.ToNaNAsNull(), + AbovePhreaticLevelCoefficientOfVariation = properties.AbovePhreaticLevelCoefficientOfVariation.ToNaNAsNull(), + AbovePhreaticLevelShift = properties.AbovePhreaticLevelShift.ToNaNAsNull(), + + BelowPhreaticLevelMean = properties.BelowPhreaticLevelMean.ToNaNAsNull(), + BelowPhreaticLevelCoefficientOfVariation = properties.BelowPhreaticLevelCoefficientOfVariation.ToNaNAsNull(), + BelowPhreaticLevelShift = properties.BelowPhreaticLevelShift.ToNaNAsNull(), + + CohesionMean = properties.CohesionMean.ToNaNAsNull(), + CohesionCoefficientOfVariation = properties.CohesionCoefficientOfVariation.ToNaNAsNull(), + + FrictionAngleMean = properties.FrictionAngleMean.ToNaNAsNull(), + FrictionAngleCoefficientOfVariation = properties.FrictionAngleCoefficientOfVariation.ToNaNAsNull(), + + ShearStrengthRatioMean = properties.ShearStrengthRatioMean.ToNaNAsNull(), + ShearStrengthRatioCoefficientOfVariation = properties.ShearStrengthRatioCoefficientOfVariation.ToNaNAsNull(), + + StrengthIncreaseExponentMean = properties.StrengthIncreaseExponentMean.ToNaNAsNull(), + StrengthIncreaseExponentCoefficientOfVariation = properties.StrengthIncreaseExponentCoefficientOfVariation.ToNaNAsNull(), + + PopMean = properties.PopMean.ToNaNAsNull(), + PopCoefficientOfVariation = properties.PopCoefficientOfVariation.ToNaNAsNull(), + + Order = order + }; + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r31a621e36dfd14666d4ec7bb492b5eb5ea8a9265 -r6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 31a621e36dfd14666d4ec7bb492b5eb5ea8a9265) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e) @@ -98,6 +98,7 @@ + Code Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/MacroStabilityInwards/MacroStabilityInwardsSoilLayer2DCreateExtensionsTest.cs (revision 6b3a6850b43d0098dcaf52c23b9a74d2e678bf8e) @@ -0,0 +1,192 @@ +// 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.Drawing; +using Application.Ringtoets.Storage.Create.MacroStabilityInwards; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Application.Ringtoets.Storage.Test.Create.MacroStabilityInwards +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayer2DCreateExtensionsTest + { + [Test] + public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet() + { + // Setup + var random = new Random(31); + var soilLayer = new MacroStabilityInwardsSoilLayer2D(CreateRandomRing(random), new[] + { + CreateRandomRing(random) + }) + { + Properties = + { + IsAquifer = random.NextBoolean(), + MaterialName = "MaterialName", + Color = Color.FromKnownColor(random.NextEnumValue()), + UsePop = random.NextBoolean(), + ShearStrengthModel = random.NextEnumValue(), + AbovePhreaticLevelMean = random.NextDouble(), + AbovePhreaticLevelCoefficientOfVariation = random.NextDouble(), + AbovePhreaticLevelShift = random.NextDouble(), + BelowPhreaticLevelMean = random.NextDouble(), + BelowPhreaticLevelCoefficientOfVariation = random.NextDouble(), + BelowPhreaticLevelShift = random.NextDouble(), + CohesionMean = random.NextDouble(), + CohesionCoefficientOfVariation = random.NextDouble(), + FrictionAngleMean = random.NextDouble(), + FrictionAngleCoefficientOfVariation = random.NextDouble(), + ShearStrengthRatioMean = random.NextDouble(), + ShearStrengthRatioCoefficientOfVariation = random.NextDouble(), + StrengthIncreaseExponentMean = random.NextDouble(), + StrengthIncreaseExponentCoefficientOfVariation = random.NextDouble(), + PopMean = random.NextDouble(), + PopCoefficientOfVariation = random.NextDouble() + } + }; + int order = random.Next(); + + // Call + MacroStabilityInwardsSoilLayer2DEntity entity = soilLayer.Create(order); + + // Assert + Assert.IsNotNull(entity); + + MacroStabilityInwardsSoilLayerProperties properties = soilLayer.Properties; + Assert.AreEqual(Convert.ToByte(properties.IsAquifer), entity.IsAquifer); + Assert.AreEqual(properties.MaterialName, entity.MaterialName); + Assert.AreEqual(properties.Color.ToArgb(), Convert.ToInt32(entity.Color)); + Assert.AreEqual(Convert.ToByte(properties.UsePop), entity.UsePop); + Assert.AreEqual(Convert.ToByte(properties.ShearStrengthModel), entity.ShearStrengthModel); + Assert.AreEqual(properties.AbovePhreaticLevelMean, entity.AbovePhreaticLevelMean); + Assert.AreEqual(properties.AbovePhreaticLevelCoefficientOfVariation, entity.AbovePhreaticLevelCoefficientOfVariation); + Assert.AreEqual(properties.AbovePhreaticLevelShift, entity.AbovePhreaticLevelShift); + Assert.AreEqual(properties.BelowPhreaticLevelMean, entity.BelowPhreaticLevelMean); + Assert.AreEqual(properties.BelowPhreaticLevelCoefficientOfVariation, entity.BelowPhreaticLevelCoefficientOfVariation); + Assert.AreEqual(properties.BelowPhreaticLevelShift, entity.BelowPhreaticLevelShift); + Assert.AreEqual(properties.CohesionMean, entity.CohesionMean); + Assert.AreEqual(properties.CohesionCoefficientOfVariation, entity.CohesionCoefficientOfVariation); + Assert.AreEqual(properties.FrictionAngleMean, entity.FrictionAngleMean); + Assert.AreEqual(properties.FrictionAngleCoefficientOfVariation, entity.FrictionAngleCoefficientOfVariation); + Assert.AreEqual(properties.ShearStrengthRatioMean, entity.ShearStrengthRatioMean); + Assert.AreEqual(properties.ShearStrengthRatioCoefficientOfVariation, entity.ShearStrengthRatioCoefficientOfVariation); + Assert.AreEqual(properties.StrengthIncreaseExponentMean, entity.StrengthIncreaseExponentMean); + Assert.AreEqual(properties.StrengthIncreaseExponentCoefficientOfVariation, entity.StrengthIncreaseExponentCoefficientOfVariation); + Assert.AreEqual(properties.PopMean, entity.PopMean); + Assert.AreEqual(properties.PopCoefficientOfVariation, entity.PopCoefficientOfVariation); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull() + { + // Setup + var random = new Random(31); + var soilLayer = new MacroStabilityInwardsSoilLayer2D(CreateRandomRing(random), new[] + { + CreateRandomRing(random) + }) + { + Properties = + { + AbovePhreaticLevelMean = double.NaN, + AbovePhreaticLevelCoefficientOfVariation = double.NaN, + AbovePhreaticLevelShift = double.NaN, + BelowPhreaticLevelMean = double.NaN, + BelowPhreaticLevelCoefficientOfVariation = double.NaN, + BelowPhreaticLevelShift = double.NaN, + CohesionMean = double.NaN, + CohesionCoefficientOfVariation = double.NaN, + FrictionAngleMean = double.NaN, + FrictionAngleCoefficientOfVariation = double.NaN, + ShearStrengthRatioMean = double.NaN, + ShearStrengthRatioCoefficientOfVariation = double.NaN, + StrengthIncreaseExponentMean = double.NaN, + StrengthIncreaseExponentCoefficientOfVariation = double.NaN, + PopMean = double.NaN, + PopCoefficientOfVariation = double.NaN + } + }; + + // Call + MacroStabilityInwardsSoilLayer2DEntity entity = soilLayer.Create(0); + + // Assert + Assert.IsNotNull(entity); + Assert.IsNull(entity.AbovePhreaticLevelMean); + Assert.IsNull(entity.AbovePhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.AbovePhreaticLevelShift); + Assert.IsNull(entity.BelowPhreaticLevelMean); + Assert.IsNull(entity.BelowPhreaticLevelCoefficientOfVariation); + Assert.IsNull(entity.BelowPhreaticLevelShift); + Assert.IsNull(entity.CohesionMean); + Assert.IsNull(entity.CohesionCoefficientOfVariation); + Assert.IsNull(entity.FrictionAngleMean); + Assert.IsNull(entity.FrictionAngleCoefficientOfVariation); + Assert.IsNull(entity.ShearStrengthRatioMean); + Assert.IsNull(entity.ShearStrengthRatioCoefficientOfVariation); + Assert.IsNull(entity.StrengthIncreaseExponentMean); + Assert.IsNull(entity.StrengthIncreaseExponentCoefficientOfVariation); + Assert.IsNull(entity.PopMean); + Assert.IsNull(entity.PopCoefficientOfVariation); + } + + [Test] + public void Create_StringPropertiesDoNotShareReference() + { + // Setup + var random = new Random(31); + + const string materialName = "MaterialName"; + var soilLayer = new MacroStabilityInwardsSoilLayer2D(CreateRandomRing(random), new[] + { + CreateRandomRing(random) + }) + { + Properties = + { + MaterialName = materialName + } + }; + + // Call + MacroStabilityInwardsSoilLayer2DEntity entity = soilLayer.Create(0); + + // Assert + TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName); + } + + private static Ring CreateRandomRing(Random random) + { + return new Ring(new[] + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }); + } + } +} \ No newline at end of file