Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs =================================================================== diff -u -r8cdbb1c76ccda6f711ec3bb02339896e7eb660c0 -r868b45ff456a9f30061487dacfe75d003b3a9e4e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 8cdbb1c76ccda6f711ec3bb02339896e7eb660c0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 868b45ff456a9f30061487dacfe75d003b3a9e4e) @@ -60,7 +60,6 @@ } ValidateStochasticParameters(soilLayer); - return new MacroStabilityInwardsSoilLayer1D(soilLayer.Top, ConvertSoilLayerData(soilLayer)); } @@ -82,7 +81,6 @@ } ValidateStochasticParameters(soilLayer); - return ConvertLayerRecursively(soilLayer); } @@ -95,7 +93,7 @@ /// in a valid transformed instance. private static MacroStabilityInwardsSoilLayer2D ConvertLayerRecursively(SoilLayer2D soilLayer) { - return new MacroStabilityInwardsSoilLayer2D(TransformSegmentsToRing(soilLayer.OuterLoop.Segments), + return new MacroStabilityInwardsSoilLayer2D(TransformSegmentsToRing(soilLayer.OuterLoop.Segments, soilLayer.MaterialName), ConvertSoilLayerData(soilLayer), soilLayer.NestedLayers.Select(ConvertLayerRecursively).ToArray()); } @@ -108,14 +106,16 @@ /// in a valid transformed instance. private static MacroStabilityInwardsSoilLayerData ConvertSoilLayerData(SoilLayerBase soilLayer) { + string soilLayerMaterialName = soilLayer.MaterialName; return new MacroStabilityInwardsSoilLayerData { - ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel), - UsePop = TransformUsePop(soilLayer.UsePop), + ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel, soilLayerMaterialName), + UsePop = TransformUsePop(soilLayer.UsePop, soilLayerMaterialName), - MaterialName = soilLayer.MaterialName, - IsAquifer = TransformIsAquifer(soilLayer.IsAquifer), + MaterialName = soilLayerMaterialName, + IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerMaterialName), Color = SoilLayerColorConverter.Convert(soilLayer.Color), + AbovePhreaticLevel = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble) soilLayer.AbovePhreaticLevelMean, @@ -161,19 +161,22 @@ /// is aquifer property of soil layers. /// /// The value to transform. + /// The name of the soil layer. /// A based on . /// Thrown when /// could not be transformed. - private static bool TransformIsAquifer(double? isAquifer) + private static bool TransformIsAquifer(double? isAquifer, string soilLayerName) { try { return SoilLayerIsAquiferConverter.Convert(isAquifer); } - catch (NotSupportedException) + catch (NotSupportedException e) { - throw new ImportedDataTransformException(string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, - RingtoetsCommonIOResources.SoilLayerData_IsAquifer_DisplayName)); + string exceptionMessage = CreateErrorMessage(soilLayerName, + string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, + RingtoetsCommonIOResources.SoilLayerData_IsAquifer_DisplayName)); + throw new ImportedDataTransformException(exceptionMessage, e); } } @@ -182,10 +185,11 @@ /// use POP property of soil layers. /// /// The value to transform. + /// The name of the soil layer. /// A based on . /// Thrown when /// could not be transformed. - private static bool TransformUsePop(double? usePop) + private static bool TransformUsePop(double? usePop, string soilLayerName) { if (!usePop.HasValue) { @@ -197,21 +201,26 @@ return false; } - throw new ImportedDataTransformException(string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, - Resources.SoilLayerData_UsePop_Description)); + string exceptionMessage = CreateErrorMessage(soilLayerName, + string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, + Resources.SoilLayerData_UsePop_Description)); + throw new ImportedDataTransformException(exceptionMessage); } /// /// Transforms a to a for the /// shear strength model of soil layers. /// /// The value to transform. + /// The name of the soil layer. /// A based /// on . /// Thrown when /// could not be transformed. - private static MacroStabilityInwardsShearStrengthModel TransformShearStrengthModel(double? shearStrengthModel) + private static MacroStabilityInwardsShearStrengthModel TransformShearStrengthModel(double? shearStrengthModel, + string soilLayerName) { + string exceptionMessage; if (!shearStrengthModel.HasValue) { return MacroStabilityInwardsShearStrengthModel.CPhi; @@ -226,29 +235,36 @@ } if (Math.Abs(shearStrengthModel.Value - 1) < tolerance) { - throw new ImportedDataTransformException(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformShearStrengthModel_No_MacroStabilityInwardsShearStrengthModel); + exceptionMessage = CreateErrorMessage(soilLayerName, + Resources.MacroStabilityInwardsSoilLayerTransformer_TransformShearStrengthModel_No_MacroStabilityInwardsShearStrengthModel); + throw new ImportedDataTransformException(exceptionMessage); } - throw new ImportedDataTransformException(string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, - Resources.SoilLayerData_ShearStrengthModel_Description)); + exceptionMessage = CreateErrorMessage(soilLayerName, + string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0, + Resources.SoilLayerData_ShearStrengthModel_Description)); + throw new ImportedDataTransformException(exceptionMessage); } /// /// Transforms a collection of to . /// /// The segments to transform. + /// The name of the soil layer. /// A based on . /// Thrown when /// could not be transformed to a . - private static Ring TransformSegmentsToRing(IEnumerable segments) + private static Ring TransformSegmentsToRing(IEnumerable segments, string soilLayerName) { try { return new Ring(segments.Select(s => s.FirstPoint)); } catch (ArgumentException e) { - throw new ImportedDataTransformException(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformSegmentToRing_Invalid_geometry_for_Ring, e); + string exceptionMessage = CreateErrorMessage(soilLayerName, + Resources.MacroStabilityInwardsSoilLayerTransformer_TransformSegmentToRing_Invalid_geometry_for_Ring); + throw new ImportedDataTransformException(exceptionMessage, e); } } @@ -261,37 +277,52 @@ /// stochastic parameters is not defined as log normal or is shifted when it should not be. private static void ValidateStochasticParameters(SoilLayerBase soilLayer) { - DistributionHelper.ValidateShiftedLogNormalDistribution(soilLayer.AbovePhreaticLevelDistributionType, - Resources.SoilLayerData_AbovePhreaticLevelDistribution_Description); + try + { + DistributionHelper.ValidateShiftedLogNormalDistribution(soilLayer.AbovePhreaticLevelDistributionType, + Resources.SoilLayerData_AbovePhreaticLevelDistribution_Description); - DistributionHelper.ValidateShiftedLogNormalDistribution( - soilLayer.BelowPhreaticLevelDistributionType, - Resources.SoilLayerData_BelowPhreaticLevelDistribution_DisplayName); + DistributionHelper.ValidateShiftedLogNormalDistribution( + soilLayer.BelowPhreaticLevelDistributionType, + Resources.SoilLayerData_BelowPhreaticLevelDistribution_DisplayName); - DistributionHelper.ValidateLogNormalDistribution( - soilLayer.CohesionDistributionType, - soilLayer.CohesionShift, - Resources.SoilLayerData_CohesionDistribution_DisplayName); + DistributionHelper.ValidateLogNormalDistribution( + soilLayer.CohesionDistributionType, + soilLayer.CohesionShift, + Resources.SoilLayerData_CohesionDistribution_DisplayName); - DistributionHelper.ValidateLogNormalDistribution( - soilLayer.FrictionAngleDistributionType, - soilLayer.FrictionAngleShift, - Resources.SoilLayerData_FrictionAngleDistribution_DisplayName); + DistributionHelper.ValidateLogNormalDistribution( + soilLayer.FrictionAngleDistributionType, + soilLayer.FrictionAngleShift, + Resources.SoilLayerData_FrictionAngleDistribution_DisplayName); - DistributionHelper.ValidateLogNormalDistribution( - soilLayer.ShearStrengthRatioDistributionType, - soilLayer.ShearStrengthRatioShift, - Resources.SoilLayerData_ShearStrengthRatioDistribution_DisplayName); + DistributionHelper.ValidateLogNormalDistribution( + soilLayer.ShearStrengthRatioDistributionType, + soilLayer.ShearStrengthRatioShift, + Resources.SoilLayerData_ShearStrengthRatioDistribution_DisplayName); - DistributionHelper.ValidateLogNormalDistribution( - soilLayer.StrengthIncreaseExponentDistributionType, - soilLayer.StrengthIncreaseExponentShift, - Resources.SoilLayerData_StrengthIncreaseExponentDistribution_DisplayName); + DistributionHelper.ValidateLogNormalDistribution( + soilLayer.StrengthIncreaseExponentDistributionType, + soilLayer.StrengthIncreaseExponentShift, + Resources.SoilLayerData_StrengthIncreaseExponentDistribution_DisplayName); - DistributionHelper.ValidateLogNormalDistribution( - soilLayer.PopDistributionType, - soilLayer.PopShift, - Resources.SoilLayerData_PopDistribution_DisplayName); + DistributionHelper.ValidateLogNormalDistribution( + soilLayer.PopDistributionType, + soilLayer.PopShift, + Resources.SoilLayerData_PopDistribution_DisplayName); + } + catch (ImportedDataTransformException e) + { + string errorMessage = CreateErrorMessage(soilLayer.MaterialName, e.Message); + throw new ImportedDataTransformException(errorMessage, e); + } } + + private static string CreateErrorMessage(string soilLayerName, string errorMessage) + { + return string.Format(RingtoetsCommonIOResources.Transform_Error_occurred_when_transforming_SoilLayer_0_errorMessage_1, + soilLayerName, + errorMessage); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs =================================================================== diff -u -r8cdbb1c76ccda6f711ec3bb02339896e7eb660c0 -r868b45ff456a9f30061487dacfe75d003b3a9e4e --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision 8cdbb1c76ccda6f711ec3bb02339896e7eb660c0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision 868b45ff456a9f30061487dacfe75d003b3a9e4e) @@ -189,7 +189,9 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Gebruik POP'."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -222,7 +224,9 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("Er is geen schuifsterkte model opgegeven.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Er is geen schuifsterkte model opgegeven."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -237,7 +241,9 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Schuifsterkte model'."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -271,7 +277,10 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("Ongeldige waarde voor parameter 'Is aquifer'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Is aquifer'."); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); } [Test] @@ -298,7 +307,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet verschoven lognormaal verdeeld zijn.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet verschoven lognormaal verdeeld zijn."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -310,7 +321,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet lognormaal verdeeld zijn.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet lognormaal verdeeld zijn."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -322,7 +335,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet lognormaal verdeeld zijn met een verschuiving gelijk aan 0.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet lognormaal verdeeld zijn met een verschuiving gelijk aan 0."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -407,7 +422,9 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Gebruik POP'."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -441,7 +458,9 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("Er is geen schuifsterkte model opgegeven.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Er is geen schuifsterkte model opgegeven."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -456,7 +475,9 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Schuifsterkte model'."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -490,7 +511,10 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("Ongeldige waarde voor parameter 'Is aquifer'.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + "Ongeldige waarde voor parameter 'Is aquifer'."); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); } [Test] @@ -518,7 +542,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet verschoven lognormaal verdeeld zijn.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet verschoven lognormaal verdeeld zijn."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -530,7 +556,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet lognormaal verdeeld zijn.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet lognormaal verdeeld zijn."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -542,7 +570,9 @@ // Assert Exception exception = Assert.Throws(test); - Assert.AreEqual($"Parameter '{parameter}' moet lognormaal verdeeld zijn met een verschuiving gelijk aan 0.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, + $"Parameter '{parameter}' moet lognormaal verdeeld zijn met een verschuiving gelijk aan 0."); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -554,7 +584,9 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("De laag bevat een ongeldige geometrie.", exception.Message); + string expectedMessage = CreateExpectedErrorMessage(soilLayer.MaterialName, + "De laag bevat een ongeldige geometrie."); + Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf(exception.InnerException); } @@ -598,6 +630,11 @@ layer.PopCoefficientOfVariation = random.NextDouble(); } + private static string CreateExpectedErrorMessage(string materialName, string errorMessage) + { + return $"Er is een fout opgetreden bij het inlezen van grondlaag '{materialName}': {errorMessage}"; + } + private static void AssertSoilLayer(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual) { AssertOuterRing(original, actual);