Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs =================================================================== diff -u -r129bee0491f9f29f4cd10662d812d1b541502129 -ra80b9805cc043daa3363a8253943a5791f112bfb --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs (.../HydraulicBoundaryLocationCalculationsExporter.cs) (revision 129bee0491f9f29f4cd10662d812d1b541502129) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs (.../HydraulicBoundaryLocationCalculationsExporter.cs) (revision a80b9805cc043daa3363a8253943a5791f112bfb) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using Core.Common.Base.IO; using Core.Common.IO.Exceptions; using Core.Common.Util; @@ -49,6 +50,8 @@ /// The type of calculations. /// Thrown when is null. /// Thrown when is invalid. + /// Thrown when the + /// is an invalid value. public HydraulicBoundaryLocationCalculationsExporter(IEnumerable calculations, string filePath, HydraulicBoundaryLocationCalculationsType calculationsType) { @@ -59,6 +62,13 @@ IOUtils.ValidateFilePath(filePath); + if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) + { + throw new InvalidEnumArgumentException(nameof(calculationsType), + (int) calculationsType, + typeof(HydraulicBoundaryLocationCalculationsType)); + } + this.calculations = calculations; this.filePath = filePath; this.calculationsType = calculationsType; Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs =================================================================== diff -u -r129bee0491f9f29f4cd10662d812d1b541502129 -ra80b9805cc043daa3363a8253943a5791f112bfb --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs (.../HydraulicBoundaryLocationCalculationsWriter.cs) (revision 129bee0491f9f29f4cd10662d812d1b541502129) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs (.../HydraulicBoundaryLocationCalculationsWriter.cs) (revision a80b9805cc043daa3363a8253943a5791f112bfb) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Core.Common.IO.Exceptions; using Core.Components.Gis.Data; @@ -46,6 +47,8 @@ /// Thrown when or /// is null. /// Thrown when is invalid. + /// Thrown when the + /// is an invalid value. /// Thrown when the shapefile cannot be written. public static void WriteHydraulicBoundaryLocationCalculations(IEnumerable calculations, string filePath, HydraulicBoundaryLocationCalculationsType calculationsType) @@ -60,6 +63,13 @@ throw new ArgumentNullException(nameof(filePath)); } + if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) + { + throw new InvalidEnumArgumentException(nameof(calculationsType), + (int) calculationsType, + typeof(HydraulicBoundaryLocationCalculationsType)); + } + var pointShapeFileWriter = new PointShapeFileWriter(); foreach (MapPointData mapDataLocation in calculations.Select(c => CreateCalculationData(c, calculationsType))) Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsExporterTest.cs =================================================================== diff -u -r129bee0491f9f29f4cd10662d812d1b541502129 -ra80b9805cc043daa3363a8253943a5791f112bfb --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsExporterTest.cs (.../HydraulicBoundaryLocationCalculationsExporterTest.cs) (revision 129bee0491f9f29f4cd10662d812d1b541502129) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsExporterTest.cs (.../HydraulicBoundaryLocationCalculationsExporterTest.cs) (revision a80b9805cc043daa3363a8253943a5791f112bfb) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.ComponentModel; using System.IO; using System.Linq; using System.Security.AccessControl; @@ -58,6 +59,24 @@ } [Test] + public void Constructor_InvalidHydraulicBoundaryLocationCalculationsType_ThrowsInvalidEnumArgumentException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); + const HydraulicBoundaryLocationCalculationsType hydraulicBoundaryLocationCalculationsType = (HydraulicBoundaryLocationCalculationsType) 99; + + // Call + void Call() => new HydraulicBoundaryLocationCalculationsExporter( + Enumerable.Empty(), filePath, hydraulicBoundaryLocationCalculationsType); + + // Assert + string expectedMessage = $"The value of argument 'calculationsType' ({hydraulicBoundaryLocationCalculationsType}) " + + $"is invalid for Enum type '{nameof(HydraulicBoundaryLocationCalculationsType)}'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + Assert.AreEqual("calculationsType", exception.ParamName); + } + + [Test] public void Constructor_ExpectedValues() { // Setup Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs =================================================================== diff -u -r129bee0491f9f29f4cd10662d812d1b541502129 -ra80b9805cc043daa3363a8253943a5791f112bfb --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs (.../HydraulicBoundaryLocationCalculationsWriterTest.cs) (revision 129bee0491f9f29f4cd10662d812d1b541502129) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs (.../HydraulicBoundaryLocationCalculationsWriterTest.cs) (revision a80b9805cc043daa3363a8253943a5791f112bfb) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.ComponentModel; using System.IO; using System.Linq; using Core.Common.TestUtil; @@ -59,6 +60,23 @@ } [Test] + public void WriteHydraulicBoundaryLocationCalculations_InvalidHydraulicBoundaryLocationCalculationsType_ThrowsInvalidEnumArgumentException() + { + // Setup + const HydraulicBoundaryLocationCalculationsType hydraulicBoundaryLocationCalculationsType = (HydraulicBoundaryLocationCalculationsType) 99; + + // Call + void Call() => HydraulicBoundaryLocationCalculationsWriter.WriteHydraulicBoundaryLocationCalculations( + Enumerable.Empty(), string.Empty, hydraulicBoundaryLocationCalculationsType); + + // Assert + string expectedMessage = $"The value of argument 'calculationsType' ({hydraulicBoundaryLocationCalculationsType}) " + + $"is invalid for Enum type '{nameof(HydraulicBoundaryLocationCalculationsType)}'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + Assert.AreEqual("calculationsType", exception.ParamName); + } + + [Test] [TestCase(HydraulicBoundaryLocationCalculationsType.WaterLevel, "ExpectedWaterLevelExport")] [TestCase(HydraulicBoundaryLocationCalculationsType.WaveHeight, "ExpectedWaveHeightExport")] public void WriteHydraulicBoundaryLocationCalculations_ValidData_WritesShapeFile(HydraulicBoundaryLocationCalculationsType calculationsType,