Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter.cs =================================================================== diff -u -r01c40dbdf75bccae38a7728556afe2f8968f55c0 -rcc37d0acc2c31aaaec7b2372f9bb047ecce15f03 --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter.cs) (revision 01c40dbdf75bccae38a7728556afe2f8968f55c0) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter.cs) (revision cc37d0acc2c31aaaec7b2372f9bb047ecce15f03) @@ -26,6 +26,7 @@ using Core.Common.IO.Exceptions; using Core.Common.Util; using log4net; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using RiskeerCommonIOResources = Riskeer.Common.IO.Properties.Resources; @@ -39,27 +40,36 @@ private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter)); private readonly IEnumerable calculations; + private readonly IAssessmentSection assessmentSection; private readonly string filePath; private readonly HydraulicBoundaryLocationCalculationsType calculationsType; /// /// Creates a new instance of . /// /// The calculations to export. + /// The assessment section the calculations belong to. /// The path of the file to export to. /// The type of calculations. - /// Thrown when is null. + /// Thrown when or + /// is null. /// Thrown when is invalid. /// Thrown when the /// is an invalid value. public HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(IEnumerable calculations, + IAssessmentSection assessmentSection, string filePath, HydraulicBoundaryLocationCalculationsType calculationsType) { if (calculations == null) { throw new ArgumentNullException(nameof(calculations)); } + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + IOUtils.ValidateFilePath(filePath); if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) @@ -70,6 +80,7 @@ } this.calculations = calculations; + this.assessmentSection = assessmentSection; this.filePath = filePath; this.calculationsType = calculationsType; } @@ -79,7 +90,7 @@ try { HydraulicBoundaryLocationCalculationsForTargetProbabilityWriter.WriteHydraulicBoundaryLocationCalculations( - calculations, filePath, calculationsType); + calculations, assessmentSection, filePath, calculationsType); } catch (CriticalFileWriteException e) { Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporterTest.cs =================================================================== diff -u -r01c40dbdf75bccae38a7728556afe2f8968f55c0 -rcc37d0acc2c31aaaec7b2372f9bb047ecce15f03 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityExporterTest.cs) (revision 01c40dbdf75bccae38a7728556afe2f8968f55c0) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilityExporterTest.cs) (revision cc37d0acc2c31aaaec7b2372f9bb047ecce15f03) @@ -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.Integration.IO.Exporters; @@ -40,55 +42,90 @@ [Test] public void Constructor_CalculationsNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call - void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(null, string.Empty, HydraulicBoundaryLocationCalculationsType.WaterLevel); + void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( + null, assessmentSection, string.Empty, HydraulicBoundaryLocationCalculationsType.WaterLevel); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("calculations", exception.ParamName); + mocks.VerifyAll(); } [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( + Enumerable.Empty(), null, string.Empty, HydraulicBoundaryLocationCalculationsType.WaterLevel); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void Constructor_FilePathNull_ThrowsArgumentException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( - Enumerable.Empty(), null, HydraulicBoundaryLocationCalculationsType.WaterLevel); + Enumerable.Empty(), assessmentSection, null, HydraulicBoundaryLocationCalculationsType.WaterLevel); // Assert Assert.Throws(Call); + mocks.VerifyAll(); } [Test] public void Constructor_InvalidHydraulicBoundaryLocationCalculationsType_ThrowsInvalidEnumArgumentException() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); const HydraulicBoundaryLocationCalculationsType hydraulicBoundaryLocationCalculationsType = (HydraulicBoundaryLocationCalculationsType) 99; // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( - Enumerable.Empty(), filePath, hydraulicBoundaryLocationCalculationsType); + Enumerable.Empty(), assessmentSection, 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); + mocks.VerifyAll(); } [Test] public void Constructor_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); // Call var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter( - Enumerable.Empty(), filePath, HydraulicBoundaryLocationCalculationsType.WaterLevel); + Enumerable.Empty(), assessmentSection, filePath, HydraulicBoundaryLocationCalculationsType.WaterLevel); // Assert Assert.IsInstanceOf(exporter); + mocks.VerifyAll(); } [Test] @@ -104,10 +141,30 @@ Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, $"{fileName}.shp"); + 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(); + var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(new[] { - new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2)) - }, filePath, calculationsType); + new HydraulicBoundaryLocationCalculation(location) + }, assessmentSection, filePath, calculationsType); // Precondition FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, false); @@ -123,13 +180,15 @@ directoryPath, fileName, Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO), nameof(HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter)), - expectedExportFileName, 28, 8, 628); + expectedExportFileName, 28, 8, 915); Assert.IsTrue(isExported); } finally { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -141,11 +200,31 @@ string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_WriterThrowsCriticalFileWriteException_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, $"{fileName}.shp"); + + 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(); + var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(new[] { - new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2)) - }, filePath, HydraulicBoundaryLocationCalculationsType.WaterLevel); + new HydraulicBoundaryLocationCalculation(location) + }, assessmentSection, filePath, HydraulicBoundaryLocationCalculationsType.WaterLevel); try { @@ -166,6 +245,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter/ExpectedWaterLevelExport.dbf =================================================================== diff -u -rfd40e419b411422c5cdf99a35a00b09b856268d1 -rcc37d0acc2c31aaaec7b2372f9bb047ecce15f03 Binary files differ Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter/ExpectedWaveHeightExport.dbf =================================================================== diff -u -rfd40e419b411422c5cdf99a35a00b09b856268d1 -rcc37d0acc2c31aaaec7b2372f9bb047ecce15f03 Binary files differ