Index: Ringtoets/Common/src/Ringtoets.Common.Service/HydraRingInputParser.cs
===================================================================
diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r156b46b92a4beaf22dc59e628db19be5536468fc
--- Ringtoets/Common/src/Ringtoets.Common.Service/HydraRingInputParser.cs (.../HydraRingInputParser.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/HydraRingInputParser.cs (.../HydraRingInputParser.cs) (revision 156b46b92a4beaf22dc59e628db19be5536468fc)
@@ -19,7 +19,9 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.HydraRing.Calculation.Data;
@@ -49,9 +51,38 @@
/// A calculation input object that implements .
/// A object, null if
/// is false
+ /// Thrown when the break water type is an invalid value.
+ /// Thrown when the break water type is a valid value but unsupported.
public static HydraRingBreakWater ParseBreakWater(IUseBreakWater input)
{
- return input.UseBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null;
+ return input.UseBreakWater ? new HydraRingBreakWater(ConvertBreakWaterType(input.BreakWater.Type), input.BreakWater.Height) : null;
}
+
+ ///
+ /// Converts into an integer value to be used by Hydra-Ring.
+ ///
+ /// The to convert.
+ /// The integer value to be used by Hydra-Ring.
+ /// Thrown when is an invalid value.
+ /// Thrown when is a valid value but unsupported.
+ private static int ConvertBreakWaterType(BreakWaterType type)
+ {
+ if (!Enum.IsDefined(type.GetType(), type))
+ {
+ throw new InvalidEnumArgumentException(nameof(type), (int) type, type.GetType());
+ }
+
+ switch (type)
+ {
+ case BreakWaterType.Caisson:
+ return 1;
+ case BreakWaterType.Wall:
+ return 2;
+ case BreakWaterType.Dam:
+ return 3;
+ default:
+ throw new NotSupportedException($"Value '{type}' is not supported.");
+ }
+ }
}
}
\ No newline at end of file