Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs =================================================================== diff -u -r63b9c8a671b9f3d9eeb74f9a2cf93e0b8d63d84e -rc45c5e9b2cf66499f4f175d2605826c4cdec5774 --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision 63b9c8a671b9f3d9eeb74f9a2cf93e0b8d63d84e) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision c45c5e9b2cf66499f4f175d2605826c4cdec5774) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.IO.Compression; using System.Linq; @@ -43,7 +44,8 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter)); - private readonly IEnumerable, double, HydraulicBoundaryLocationCalculationsType>> locationCalculationsForTargetProbabilities; + private readonly IEnumerable, double>> locationCalculationsForTargetProbabilities; + private readonly HydraulicBoundaryLocationCalculationsType calculationsType; private readonly string filePath; private readonly string tempFolderPath; @@ -52,22 +54,33 @@ /// /// The collection of /// to export. + /// The type of the calculations to export. /// The path of the file to export to. /// Thrown when /// is null. + /// Thrown when + /// is invalid. /// Thrown when is invalid. public HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - IEnumerable, double, HydraulicBoundaryLocationCalculationsType>> locationCalculationsForTargetProbabilities, - string filePath) + IEnumerable, double>> locationCalculationsForTargetProbabilities, + HydraulicBoundaryLocationCalculationsType calculationsType, string filePath) { if (locationCalculationsForTargetProbabilities == null) { throw new ArgumentNullException(nameof(locationCalculationsForTargetProbabilities)); } + if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) + { + throw new InvalidEnumArgumentException(nameof(calculationsType), + (int) calculationsType, + typeof(HydraulicBoundaryLocationCalculationsType)); + } + IOUtils.ValidateFilePath(filePath); this.locationCalculationsForTargetProbabilities = locationCalculationsForTargetProbabilities; + this.calculationsType = calculationsType; this.filePath = filePath; string folderPath = Path.GetDirectoryName(filePath); tempFolderPath = Path.Combine(folderPath, "~temp"); @@ -106,12 +119,11 @@ } private bool ExportLocationCalculationsForTargetProbability( - Tuple, double, HydraulicBoundaryLocationCalculationsType> calculationsForTargetProbability, + Tuple, double> calculationsForTargetProbability, IDictionary, string> exportedCalculations) { IEnumerable calculations = calculationsForTargetProbability.Item1; double targetProbability = calculationsForTargetProbability.Item2; - HydraulicBoundaryLocationCalculationsType calculationsType = calculationsForTargetProbability.Item3; string exportType = calculationsType == HydraulicBoundaryLocationCalculationsType.WaterLevel ? Resources.WaterLevels_DisplayName Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs =================================================================== diff -u -r63b9c8a671b9f3d9eeb74f9a2cf93e0b8d63d84e -rc45c5e9b2cf66499f4f175d2605826c4cdec5774 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs) (revision 63b9c8a671b9f3d9eeb74f9a2cf93e0b8d63d84e) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs) (revision c45c5e9b2cf66499f4f175d2605826c4cdec5774) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.IO.Compression; using System.Linq; @@ -41,19 +42,37 @@ public void Constructor_LocationCalculationsForTargetProbabilitiesNull_ThrowsArgumentNullException() { // Call - void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter(null, string.Empty); + void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + null, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("locationCalculationsForTargetProbabilities", exception.ParamName); } [Test] + public void Constructor_InvalidHydraulicBoundaryLocationCalculationsType_ThrowsInvalidEnumArgumentException() + { + // Setup + const HydraulicBoundaryLocationCalculationsType calculationsType = (HydraulicBoundaryLocationCalculationsType) 99; + + // Call + void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + Enumerable.Empty, double>>(), calculationsType, string.Empty); + + // Assert + var expectedMessage = $"The value of argument 'calculationsType' ({calculationsType}) is invalid for Enum type '{nameof(HydraulicBoundaryLocationCalculationsType)}'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); + Assert.AreEqual("calculationsType", exception.ParamName); + } + + [Test] public void Constructor_FilePathNull_ThrowsArgumentException() { // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - Enumerable.Empty, double, HydraulicBoundaryLocationCalculationsType>>(), null); + Enumerable.Empty, double>>(), + HydraulicBoundaryLocationCalculationsType.WaterLevel, null); // Assert Assert.Throws(Call); @@ -67,8 +86,8 @@ // Call var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - Enumerable.Empty, double, HydraulicBoundaryLocationCalculationsType>>(), - filePath); + Enumerable.Empty, double>>(), + HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); // Assert Assert.IsInstanceOf(exporter); @@ -84,11 +103,12 @@ var calculationsForTargetProbabilities = new[] { - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - Enumerable.Empty(), 0.1, HydraulicBoundaryLocationCalculationsType.WaterLevel) + new Tuple, double>( + Enumerable.Empty(), 0.1) }; - var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter(calculationsForTargetProbabilities, filePath); + var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + calculationsForTargetProbabilities, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); string expectedFilePath = Path.Combine(directoryPath, "~temp", "Waterstanden_10.shp"); @@ -114,7 +134,10 @@ } [Test] - public void Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue() + [TestCase(HydraulicBoundaryLocationCalculationsType.WaterLevel, "Waterstanden")] + [TestCase(HydraulicBoundaryLocationCalculationsType.WaveHeight, "Golfhoogten")] + public void Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue( + HydraulicBoundaryLocationCalculationsType calculationsType, string expectedCalculationsTypeName) { // Setup string directoryPath = TestHelper.GetScratchPadPath($"{nameof(Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue)}"); @@ -125,15 +148,14 @@ var calculationsForTargetProbabilities = new[] { - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), random.NextDouble(0, 0.1), - HydraulicBoundaryLocationCalculationsType.WaterLevel), - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), random.NextDouble(0, 0.1), - HydraulicBoundaryLocationCalculationsType.WaveHeight) + new Tuple, double>( + new List(), random.NextDouble(0, 0.1)), + new Tuple, double>( + new List(), random.NextDouble(0, 0.01)) }; - var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter(calculationsForTargetProbabilities, filePath); + var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + calculationsForTargetProbabilities, calculationsType, filePath); try { @@ -145,8 +167,8 @@ string[] expectedFiles = { - $"Waterstanden_{GetReturnPeriodText(calculationsForTargetProbabilities.First().Item2)}.shp", - $"Golfhoogten_{GetReturnPeriodText(calculationsForTargetProbabilities.Last().Item2)}.shp" + $"{expectedCalculationsTypeName}_{GetReturnPeriodText(calculationsForTargetProbabilities.First().Item2)}.shp", + $"{expectedCalculationsTypeName}_{GetReturnPeriodText(calculationsForTargetProbabilities.Last().Item2)}.shp" }; using (ZipArchive zipArchive = ZipFile.OpenRead(filePath)) @@ -161,7 +183,10 @@ } [Test] - public void Export_WithDoubleHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue() + [TestCase(HydraulicBoundaryLocationCalculationsType.WaterLevel, "Waterstanden")] + [TestCase(HydraulicBoundaryLocationCalculationsType.WaveHeight, "Golfhoogten")] + public void Export_WithDoubleHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue( + HydraulicBoundaryLocationCalculationsType calculationsType, string expectedCalculationsTypeName) { // Setup string directoryPath = TestHelper.GetScratchPadPath($"{nameof(Export_WithDoubleHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue)}"); @@ -170,17 +195,12 @@ var calculationsForTargetProbabilities = new[] { - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), 0.1, HydraulicBoundaryLocationCalculationsType.WaterLevel), - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), 0.1, HydraulicBoundaryLocationCalculationsType.WaterLevel), - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), 0.001, HydraulicBoundaryLocationCalculationsType.WaveHeight), - new Tuple, double, HydraulicBoundaryLocationCalculationsType>( - new List(), 0.001, HydraulicBoundaryLocationCalculationsType.WaveHeight) + new Tuple, double>(new List(), 0.1), + new Tuple, double>(new List(), 0.1) }; - var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter(calculationsForTargetProbabilities, filePath); + var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + calculationsForTargetProbabilities, calculationsType, filePath); try { @@ -192,10 +212,8 @@ string[] expectedFiles = { - "Waterstanden_10.shp", - "Waterstanden_10 (1).shp", - "Golfhoogten_1.000.shp", - "Golfhoogten_1.000 (1).shp" + $"{expectedCalculationsTypeName}_10.shp", + $"{expectedCalculationsTypeName}_10 (1).shp" }; using (ZipArchive zipArchive = ZipFile.OpenRead(filePath))