Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs =================================================================== diff -u -r01c40dbdf75bccae38a7728556afe2f8968f55c0 -rba15c9f55b24837d54f40959316ef7d9dc8d41ae --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision 01c40dbdf75bccae38a7728556afe2f8968f55c0) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision ba15c9f55b24837d54f40959316ef7d9dc8d41ae) @@ -27,6 +27,7 @@ using Core.Common.IO.Exceptions; using Core.Common.Util; using log4net; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.IO.Helpers; using Riskeer.Integration.IO.Helpers; @@ -42,6 +43,7 @@ private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter)); private readonly IEnumerable, double>> locationCalculationsForTargetProbabilities; + private readonly IAssessmentSection assessmentSection; private readonly HydraulicBoundaryLocationCalculationsType calculationsType; private readonly string filePath; private readonly string tempFolderPath; @@ -50,22 +52,29 @@ /// Creates a new instance of . /// /// The collection of calculations to export. + /// The assessment section the collection of calculations belong to. /// The type of the calculations to export. /// The path of the file to export to. /// Thrown when - /// is null. + /// or is null. /// Thrown when /// is invalid. /// Thrown when is invalid. public HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( IEnumerable, double>> locationCalculationsForTargetProbabilities, + IAssessmentSection assessmentSection, HydraulicBoundaryLocationCalculationsType calculationsType, string filePath) { if (locationCalculationsForTargetProbabilities == null) { throw new ArgumentNullException(nameof(locationCalculationsForTargetProbabilities)); } + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + if (!Enum.IsDefined(typeof(HydraulicBoundaryLocationCalculationsType), calculationsType)) { throw new InvalidEnumArgumentException(nameof(calculationsType), @@ -76,6 +85,7 @@ IOUtils.ValidateFilePath(filePath); this.locationCalculationsForTargetProbabilities = locationCalculationsForTargetProbabilities; + this.assessmentSection = assessmentSection; this.calculationsType = calculationsType; this.filePath = filePath; string folderPath = Path.GetDirectoryName(filePath); @@ -87,7 +97,7 @@ try { if (!HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities( - locationCalculationsForTargetProbabilities, calculationsType, tempFolderPath)) + locationCalculationsForTargetProbabilities, assessmentSection, calculationsType, tempFolderPath)) { return false; } Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs =================================================================== diff -u -r01c40dbdf75bccae38a7728556afe2f8968f55c0 -rba15c9f55b24837d54f40959316ef7d9dc8d41ae --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs) (revision 01c40dbdf75bccae38a7728556afe2f8968f55c0) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporterTest.cs) (revision ba15c9f55b24837d54f40959316ef7d9dc8d41ae) @@ -30,6 +30,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.Util.Helpers; using Riskeer.Integration.IO.Exporters; @@ -42,41 +44,70 @@ [Test] public void Constructor_LocationCalculationsForTargetProbabilitiesNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - null, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); + null, assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("locationCalculationsForTargetProbabilities", exception.ParamName); + mocks.VerifyAll(); } [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( + Enumerable.Empty, double>>(), null, HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void Constructor_InvalidHydraulicBoundaryLocationCalculationsType_ThrowsInvalidEnumArgumentException() { // Setup const HydraulicBoundaryLocationCalculationsType calculationsType = (HydraulicBoundaryLocationCalculationsType) 99; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - Enumerable.Empty, double>>(), calculationsType, string.Empty); + Enumerable.Empty, double>>(), assessmentSection, 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); + mocks.VerifyAll(); } [Test] public void Constructor_FilePathNull_ThrowsArgumentException() { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call void Call() => new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - Enumerable.Empty, double>>(), + Enumerable.Empty, double>>(), assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, null); // Assert Assert.Throws(Call); + mocks.VerifyAll(); } [Test] @@ -85,13 +116,18 @@ // Setup string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + // Call var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - Enumerable.Empty, double>>(), + Enumerable.Empty, double>>(), assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); // Assert Assert.IsInstanceOf(exporter); + mocks.VerifyAll(); } [Test] @@ -101,6 +137,11 @@ string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogsErrorAndReturnsFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData()); + mocks.ReplayAll(); var calculationsForTargetProbabilities = new[] { @@ -109,7 +150,7 @@ }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - calculationsForTargetProbabilities, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); + calculationsForTargetProbabilities, assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); try { @@ -131,6 +172,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -140,6 +183,11 @@ string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CreatingZipFileThrowsCriticalFileWriteException_LogsErrorAndReturnsFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData()); + mocks.ReplayAll(); var calculationsForTargetProbabilities = new[] { @@ -148,7 +196,7 @@ }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - calculationsForTargetProbabilities, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); + calculationsForTargetProbabilities, assessmentSection, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); try { @@ -171,6 +219,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -183,19 +233,24 @@ string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData()); + mocks.ReplayAll(); var random = new Random(21); var calculationsForTargetProbabilities = new[] { new Tuple, double>( - new List(), random.NextDouble(0, 0.1)), + Enumerable.Empty(), random.NextDouble(0, 0.1)), new Tuple, double>( - new List(), random.NextDouble(0, 0.01)) + Enumerable.Empty(), random.NextDouble(0, 0.01)) }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - calculationsForTargetProbabilities, calculationsType, filePath); + calculationsForTargetProbabilities, assessmentSection, calculationsType, filePath); try { @@ -220,6 +275,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } [Test] @@ -233,14 +290,21 @@ Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryData).Return(new HydraulicBoundaryData()); + mocks.ReplayAll(); + var calculationsForTargetProbabilities = new[] { - new Tuple, double>(new List(), 0.1), - new Tuple, double>(new List(), 0.1) + new Tuple, double>( + Enumerable.Empty(), 0.1), + new Tuple, double>( + Enumerable.Empty(), 0.1) }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( - calculationsForTargetProbabilities, calculationsType, filePath); + calculationsForTargetProbabilities, assessmentSection, calculationsType, filePath); try { @@ -265,6 +329,8 @@ { DirectoryHelper.TryDelete(directoryPath); } + + mocks.VerifyAll(); } private static string GetReturnPeriodText(double targetProbability)