Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs =================================================================== diff -u -r1b7dec5dc5d682b37d0191d99da2ff640cc56022 -rf6dd19ee061fc2754d81eb3677c26fbdb504fc49 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs (.../MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs) (revision 1b7dec5dc5d682b37d0191d99da2ff640cc56022) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/MacroStabilityInwards/MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs (.../MacroStabilityInwardsSoilLayerTwoDEntityReadExtensionsTest.cs) (revision f6dd19ee061fc2754d81eb3677c26fbdb504fc49) @@ -21,9 +21,11 @@ using System; using System.Drawing; +using System.Linq; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Read.MacroStabilityInwards; using Application.Ringtoets.Storage.Serializers; +using Application.Ringtoets.Storage.TestUtil.MacroStabilityInwards; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; @@ -53,56 +55,48 @@ public void Read_WithValues_ReturnsMacroStabilityInwardsSoilLayer2DWithDoubleParameterValues() { // Setup - var random = new Random(31); - int color = Color.FromKnownColor(random.NextEnumValue()).ToArgb(); - bool isAquifer = random.NextBoolean(); - const double abovePhreaticLevelMean = 0.3; - const double abovePhreaticLevelCoefficientOfVariation = 0.2; - const double abovePhreaticLevelShift = 0.1; - const double belowPhreaticLevelMean = 0.6; - const double belowPhreaticLevelCoefficientOfVariation = 0.5; - const double belowPhreaticLevelShift = 0.4; - double cohesionMean = random.NextDouble(); - double cohesionCoefficientOfVariation = random.NextDouble(); - double frictionAngleMean = random.NextDouble(); - double frictionAngleCoefficientOfVariation = random.NextDouble(); - double shearStrengthRatioMean = random.NextDouble(); - double shearStrengthRatioCoefficientOfVariation = random.NextDouble(); - double strengthIncreaseExponentMean = random.NextDouble(); - double strengthIncreaseExponentCoefficientOfVariation = random.NextDouble(); - double popMean = random.NextDouble(); - double popCoefficientOfVariation = random.NextDouble(); + MacroStabilityInwardsSoilLayerTwoDEntity entity = CreateMacroStabilityInwardsSoilLayerTwoDEntity(); - var outerRingPoints = new[] + // Call + MacroStabilityInwardsSoilLayer2D layer = entity.Read(); + + // Assert + AssertMacroStabilityInwardsSoilLayer2D(entity, layer); + } + + [Test] + public void Read_WithNestedLayers_ReturnsMacroStabilityInwardsSoilLayer2DWithNestedLayers() + { + // Setup + MacroStabilityInwardsSoilLayerTwoDEntity entity = MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity(); + + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Add(CreateMacroStabilityInwardsSoilLayerTwoDEntity()); + + // Call + MacroStabilityInwardsSoilLayer2D layer = entity.Read(); + + // Assert + Assert.IsNotNull(layer); + Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count, + layer.NestedLayers.Count()); + + for (var i = 0; i < entity.MacroStabilityInwardsSoilLayerTwoDEntity1.Count; i++) { - CreateRandomPoint2D(random), - CreateRandomPoint2D(random), - CreateRandomPoint2D(random), - CreateRandomPoint2D(random) - }; + AssertMacroStabilityInwardsSoilLayer2D(entity.MacroStabilityInwardsSoilLayerTwoDEntity1.ElementAt(i), + layer.NestedLayers.ElementAt(i)); + } + } + [Test] + public void Read_WithNullValues_ReturnsMacroStabilityInwardsSoilLayer2DWithNaNValues() + { + // Setup var entity = new MacroStabilityInwardsSoilLayerTwoDEntity { - IsAquifer = Convert.ToByte(isAquifer), - Color = color, - MaterialName = random.Next().ToString(), - AbovePhreaticLevelMean = abovePhreaticLevelMean, - AbovePhreaticLevelCoefficientOfVariation = abovePhreaticLevelCoefficientOfVariation, - AbovePhreaticLevelShift = abovePhreaticLevelShift, - BelowPhreaticLevelMean = belowPhreaticLevelMean, - BelowPhreaticLevelCoefficientOfVariation = belowPhreaticLevelCoefficientOfVariation, - BelowPhreaticLevelShift = belowPhreaticLevelShift, - CohesionMean = cohesionMean, - CohesionCoefficientOfVariation = cohesionCoefficientOfVariation, - FrictionAngleMean = frictionAngleMean, - FrictionAngleCoefficientOfVariation = frictionAngleCoefficientOfVariation, - ShearStrengthRatioMean = shearStrengthRatioMean, - ShearStrengthRatioCoefficientOfVariation = shearStrengthRatioCoefficientOfVariation, - StrengthIncreaseExponentMean = strengthIncreaseExponentMean, - StrengthIncreaseExponentCoefficientOfVariation = strengthIncreaseExponentCoefficientOfVariation, - PopMean = popMean, - PopCoefficientOfVariation = popCoefficientOfVariation, - OuterRingXml = new Point2DXmlSerializer().ToXml(outerRingPoints) + MaterialName = nameof(MacroStabilityInwardsSoilLayerTwoDEntity), + OuterRingXml = new Point2DXmlSerializer().ToXml(CreateRandomRing(new Random(31)).Points) }; // Call @@ -111,120 +105,146 @@ // Assert Assert.IsNotNull(layer); IMacroStabilityInwardsSoilLayerData data = layer.Data; - Assert.AreEqual(isAquifer, data.IsAquifer); - Assert.AreEqual(Color.FromArgb(color), data.Color); Assert.AreEqual(entity.MaterialName, data.MaterialName); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) abovePhreaticLevelMean, - CoefficientOfVariation = (RoundedDouble) abovePhreaticLevelCoefficientOfVariation, - Shift = (RoundedDouble) abovePhreaticLevelShift + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN }, data.AbovePhreaticLevel); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) belowPhreaticLevelMean, - CoefficientOfVariation = (RoundedDouble) belowPhreaticLevelCoefficientOfVariation, - Shift = (RoundedDouble) belowPhreaticLevelShift + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN, + Shift = RoundedDouble.NaN }, data.BelowPhreaticLevel); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) cohesionMean, - CoefficientOfVariation = (RoundedDouble) cohesionCoefficientOfVariation + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN }, data.Cohesion); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) frictionAngleMean, - CoefficientOfVariation = (RoundedDouble) frictionAngleCoefficientOfVariation + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN }, data.FrictionAngle); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) shearStrengthRatioMean, - CoefficientOfVariation = (RoundedDouble) shearStrengthRatioCoefficientOfVariation + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN }, data.ShearStrengthRatio); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) strengthIncreaseExponentMean, - CoefficientOfVariation = (RoundedDouble) strengthIncreaseExponentCoefficientOfVariation + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN }, data.StrengthIncreaseExponent); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) popMean, - CoefficientOfVariation = (RoundedDouble) popCoefficientOfVariation + Mean = RoundedDouble.NaN, + CoefficientOfVariation = RoundedDouble.NaN }, data.Pop); - - CollectionAssert.AreEqual(outerRingPoints, layer.OuterRing.Points); } - [Test] - public void Read_WithNullValues_ReturnsMacroStabilityInwardsSoilLayer2DWithNaNValues() + private static void AssertMacroStabilityInwardsSoilLayer2D(MacroStabilityInwardsSoilLayerTwoDEntity entity, + IMacroStabilityInwardsSoilLayer2D layer) { - // Setup - var entity = new MacroStabilityInwardsSoilLayerTwoDEntity - { - MaterialName = nameof(MacroStabilityInwardsSoilLayerTwoDEntity), - OuterRingXml = new Point2DXmlSerializer().ToXml(CreateRandomRing(new Random(31)).Points) - }; - - // Call - MacroStabilityInwardsSoilLayer2D layer = entity.Read(); - - // Assert Assert.IsNotNull(layer); IMacroStabilityInwardsSoilLayerData data = layer.Data; + Assert.AreEqual(Convert.ToBoolean(entity.IsAquifer), data.IsAquifer); + Assert.AreEqual(Color.FromArgb(Convert.ToInt32(entity.Color)), data.Color); Assert.AreEqual(entity.MaterialName, data.MaterialName); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN, - Shift = RoundedDouble.NaN + Mean = (RoundedDouble) entity.AbovePhreaticLevelMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.AbovePhreaticLevelCoefficientOfVariation.ToNullAsNaN(), + Shift = (RoundedDouble) entity.AbovePhreaticLevelShift.ToNullAsNaN() }, data.AbovePhreaticLevel); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN, - Shift = RoundedDouble.NaN + Mean = (RoundedDouble) entity.BelowPhreaticLevelMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.BelowPhreaticLevelCoefficientOfVariation.ToNullAsNaN(), + Shift = (RoundedDouble) entity.BelowPhreaticLevelShift.ToNullAsNaN() }, data.BelowPhreaticLevel); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN + Mean = (RoundedDouble) entity.CohesionMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.CohesionCoefficientOfVariation.ToNullAsNaN() }, data.Cohesion); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN + Mean = (RoundedDouble) entity.FrictionAngleMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.FrictionAngleCoefficientOfVariation.ToNullAsNaN() }, data.FrictionAngle); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN + Mean = (RoundedDouble) entity.ShearStrengthRatioMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.ShearStrengthRatioCoefficientOfVariation.ToNullAsNaN() }, data.ShearStrengthRatio); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN + Mean = (RoundedDouble) entity.StrengthIncreaseExponentMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.StrengthIncreaseExponentCoefficientOfVariation.ToNullAsNaN() }, data.StrengthIncreaseExponent); DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2) { - Mean = RoundedDouble.NaN, - CoefficientOfVariation = RoundedDouble.NaN + Mean = (RoundedDouble) entity.PopMean.ToNullAsNaN(), + CoefficientOfVariation = (RoundedDouble) entity.PopCoefficientOfVariation.ToNullAsNaN() }, data.Pop); + + CollectionAssert.AreEqual(new Point2DXmlSerializer().FromXml(entity.OuterRingXml), + layer.OuterRing.Points); + CollectionAssert.IsEmpty(layer.NestedLayers); } + private static MacroStabilityInwardsSoilLayerTwoDEntity CreateMacroStabilityInwardsSoilLayerTwoDEntity() + { + var random = new Random(31); + var entity = new MacroStabilityInwardsSoilLayerTwoDEntity + { + IsAquifer = Convert.ToByte(random.NextBoolean()), + Color = Color.FromKnownColor(random.NextEnumValue()).ToArgb(), + MaterialName = random.Next().ToString(), + AbovePhreaticLevelMean = random.GetFromRange(2.0, 3.0), + AbovePhreaticLevelCoefficientOfVariation = random.NextDouble(), + AbovePhreaticLevelShift = random.GetFromRange(0.0, 1.0), + BelowPhreaticLevelMean = random.GetFromRange(2.0, 3.0), + BelowPhreaticLevelCoefficientOfVariation = random.NextDouble(), + BelowPhreaticLevelShift = random.GetFromRange(0.0, 1.0), + 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(), + OuterRingXml = new Point2DXmlSerializer().ToXml(new[] + { + CreateRandomPoint2D(random), + CreateRandomPoint2D(random), + CreateRandomPoint2D(random), + CreateRandomPoint2D(random) + }) + }; + return entity; + } + private static Ring CreateRandomRing(Random random) { return new Ring(new[]