Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs
===================================================================
diff -u -r399dd53d2efa4adb1a3010184e38515b65cef723 -r166f0d43e8e9d8820a7b95503ed2196d0fc54741
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (.../PipingChartDataFactory.cs) (revision 399dd53d2efa4adb1a3010184e38515b65cef723)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (.../PipingChartDataFactory.cs) (revision 166f0d43e8e9d8820a7b95503ed2196d0fc54741)
@@ -161,13 +161,19 @@
/// The which contains the .
/// The created .
/// Thrown when is null.
+ /// Thrown when is outside the allowable range of values ([0, number_of_soil_layers>).
public static ChartMultipleAreaData CreateSoilLayerChartData(int soilLayerIndex, PipingSoilProfile soilProfile)
{
if (soilProfile == null)
{
throw new ArgumentNullException("soilProfile");
}
+ if (soilLayerIndex < 0 || soilLayerIndex >= soilProfile.Layers.Count())
+ {
+ throw new ArgumentOutOfRangeException("soilLayerIndex");
+ }
+
var soilLayer = soilProfile.Layers.ElementAt(soilLayerIndex);
return new ChartMultipleAreaData(string.Format("{0} {1}", soilLayerIndex + 1, soilLayer.MaterialName))
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs
===================================================================
diff -u -r78053965aab36c2c21e2706e73d84a9dc2cd5f3a -r166f0d43e8e9d8820a7b95503ed2196d0fc54741
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (.../PipingChartDataFactoryTest.cs) (revision 78053965aab36c2c21e2706e73d84a9dc2cd5f3a)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (.../PipingChartDataFactoryTest.cs) (revision 166f0d43e8e9d8820a7b95503ed2196d0fc54741)
@@ -168,11 +168,32 @@
Assert.AreEqual("soilProfile", paramName);
}
+ [TestCase(-1)]
+ [TestCase(2)]
+ [TestCase(3)]
+ public void CreateSoilLayerChartData_InvalidSoilLayerIndex_ThrowsArgumentOutOfRangeException(int soilLayerIndex)
+ {
+ // Setup
+ var layers = new[]
+ {
+ new PipingSoilLayer(0),
+ new PipingSoilLayer(1)
+ };
+ var profile = new PipingSoilProfile("name", -1.0, layers, SoilProfileType.SoilProfile1D, 0);
+
+ // Call
+ TestDelegate test = () => PipingChartDataFactory.CreateSoilLayerChartData(soilLayerIndex, profile);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("soilLayerIndex", paramName);
+ }
+
[Test]
[TestCase("A", 0)]
[TestCase("B", 3)]
[TestCase("Random", 5)]
- public void CreateSoilLayerChartData_ValidSoilProfile_ReturnsEmptyChartDataCollectionWithDefaultStyling(string name, int soilLayerIndex)
+ public void CreateSoilLayerChartData_ValidSoilProfileAndSoilLayerIndex_ReturnsEmptyChartDataCollectionWithDefaultStyling(string name, int soilLayerIndex)
{
var surfaceLine = new RingtoetsPipingSurfaceLine();
surfaceLine.SetGeometry(new[]