Index: Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs =================================================================== diff -u -r3594c0d09a19af6f1b5e1a9a1cbbb407576cb0d9 -r4c2b8b8b3514523496ea7f845aee546e13a1cee1 --- Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs (.../HydraulicBoundaryLocationCalculationsExportHelper.cs) (revision 3594c0d09a19af6f1b5e1a9a1cbbb407576cb0d9) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs (.../HydraulicBoundaryLocationCalculationsExportHelper.cs) (revision 4c2b8b8b3514523496ea7f845aee546e13a1cee1) @@ -25,6 +25,7 @@ using System.IO; using System.Linq; using Core.Common.Util; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Util.Helpers; using Riskeer.Integration.IO.Exporters; @@ -42,15 +43,18 @@ /// Exports the location calculations for a collection of target probabilities. /// /// The collection of calculations to export. + /// The assessment section the collection of calculations belong to. /// The type of the calculations. /// The path of the folder to export to. /// true when the export was successful; false otherwise. - /// Thrown when is null. + /// Thrown when + /// or is null. /// Thrown when is invalid. /// Thrown when /// is invalid. public static bool ExportLocationCalculationsForTargetProbabilities( IEnumerable, double>> calculationsForTargetProbabilities, + IAssessmentSection assessmentSection, HydraulicBoundaryLocationCalculationsType calculationsType, string folderPath) { @@ -59,6 +63,11 @@ throw new ArgumentNullException(nameof(calculationsForTargetProbabilities)); } + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) { throw new InvalidEnumArgumentException(nameof(calculationsType), @@ -70,7 +79,7 @@ var exportedCalculationFileNames = new List(); return calculationsForTargetProbabilities.All(calculations => ExportCalculationsForTargetProbability( - calculations, calculationsType, exportedCalculationFileNames, folderPath)); + calculations, assessmentSection, calculationsType, exportedCalculationFileNames, folderPath)); } /// @@ -95,6 +104,7 @@ private static bool ExportCalculationsForTargetProbability( Tuple, double> calculationsForTargetProbability, + IAssessmentSection assessmentSection, HydraulicBoundaryLocationCalculationsType calculationsType, ICollection exportedCalculationFileNames, string folderPath) @@ -109,7 +119,7 @@ string tempFilePath = Path.Combine(folderPath, $"{uniqueFileName}.{RiskeerCommonIOResources.Shape_file_filter_Extension}"); var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( - calculations, tempFilePath, calculationsType); + calculations, assessmentSection, tempFilePath, calculationsType); return exporter.Export(); } } Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs =================================================================== diff -u -r10841e6edd8568ff52f4892b69a8700e1af7651d -r4c2b8b8b3514523496ea7f845aee546e13a1cee1 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs (.../HydraulicBoundaryLocationCalculationsExportHelperTest.cs) (revision 10841e6edd8568ff52f4892b69a8700e1af7651d) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs (.../HydraulicBoundaryLocationCalculationsExportHelperTest.cs) (revision 4c2b8b8b3514523496ea7f845aee546e13a1cee1) @@ -28,6 +28,8 @@ using Core.Common.TestUtil; using Core.Common.Util; using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.IO.TestUtil; using Riskeer.Common.Util.Helpers; @@ -42,25 +44,48 @@ [Test] public void ExportLocationCalculationsForTargetProbabilities_CalculationsForTargetProbabilitiesNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities( - null, - HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); + null, assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("calculationsForTargetProbabilities", exception.ParamName); + mocks.VerifyAll(); } [Test] + public void ExportLocationCalculationsForTargetProbabilities_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities( + Enumerable.Empty, double>>(), null, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void ExportLocationCalculationsForTargetProbabilities_FolderPathNull_ThrowsArgumentException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities( - Enumerable.Empty, double>>(), HydraulicBoundaryLocationCalculationsType.WaterLevel, null); + Enumerable.Empty, double>>(), assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, null); // Assert Assert.Throws(Call); + mocks.VerifyAll(); } [Test] @@ -69,15 +94,20 @@ // Setup const HydraulicBoundaryLocationCalculationsType calculationsType = (HydraulicBoundaryLocationCalculationsType) 99; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities( - Enumerable.Empty, double>>(), calculationsType, string.Empty); + Enumerable.Empty, double>>(), assessmentSection, calculationsType, string.Empty); // Assert string 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); + mocks.VerifyAll(); } [Test] @@ -89,6 +119,26 @@ // Setup const double targetProbability = 0.05; + var location = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData + { + HydraulicBoundaryDatabases = + { + new HydraulicBoundaryDatabase + { + FilePath = "Just/A/HRD/File", + Locations = + { + location + } + } + } + }); + mocks.ReplayAll(); + string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_ValidData_ReturnsTrueAndWritesCorrectData)); Directory.CreateDirectory(directoryPath); @@ -105,9 +155,9 @@ { new Tuple, double>(new[] { - new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2)) + new HydraulicBoundaryLocationCalculation(location) }, targetProbability) - }, calculationsType, directoryPath); + }, assessmentSection, calculationsType, directoryPath); // Assert Assert.IsTrue(isExported); @@ -117,12 +167,14 @@ directoryPath, shapeFileName, Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO), nameof(HydraulicBoundaryLocationCalculationsExportHelper)), - expectedExportFileName, 28, 8, 628); + expectedExportFileName, 28, 8, 915); } finally { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -133,6 +185,11 @@ // Setup const double targetProbability = 0.00005; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData()); + mocks.ReplayAll(); + string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_DuplicateTargetProbability_ReturnsTrueAndWritesExpectedFiles)); Directory.CreateDirectory(directoryPath); @@ -151,7 +208,7 @@ Enumerable.Empty(), targetProbability), new Tuple, double>( Enumerable.Empty(), targetProbability) - }, calculationsType, directoryPath); + }, assessmentSection, calculationsType, directoryPath); // Assert Assert.IsTrue(isExported); @@ -163,6 +220,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -173,6 +232,26 @@ double targetProbability = random.NextDouble(0, 0.1); var calculationsType = random.NextEnumValue(); + var location = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData + { + HydraulicBoundaryDatabases = + { + new HydraulicBoundaryDatabase + { + FilePath = "Just/A/HRD/File", + Locations = + { + location + } + } + } + }); + mocks.ReplayAll(); + string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); @@ -188,9 +267,9 @@ { new Tuple, double>(new[] { - new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2)) + new HydraulicBoundaryLocationCalculation(location) }, targetProbability) - }, calculationsType, directoryPath); + }, assessmentSection, calculationsType, directoryPath); // Assert string fileName = GetExpectedShapeFileName(calculationsType, targetProbability); @@ -205,6 +284,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsExportHelper/ExpectedWaterLevelExport.dbf =================================================================== diff -u -r252894b5b304c3029dc4b70c626967f5939dd180 -r4c2b8b8b3514523496ea7f845aee546e13a1cee1 Binary files differ Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsExportHelper/ExpectedWaveHeightExport.dbf =================================================================== diff -u -r252894b5b304c3029dc4b70c626967f5939dd180 -r4c2b8b8b3514523496ea7f845aee546e13a1cee1 Binary files differ