Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs =================================================================== diff -u -r272cfc214b19eee23c9d875bc000a2b7a9a1a78e -rcf5a6ebe9b52b43e570be69a123ba838d7b936c3 --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs (.../HydraulicBoundaryLocationCalculationsExporter.cs) (revision 272cfc214b19eee23c9d875bc000a2b7a9a1a78e) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsExporter.cs (.../HydraulicBoundaryLocationCalculationsExporter.cs) (revision cf5a6ebe9b52b43e570be69a123ba838d7b936c3) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Compression; using System.Linq; using Core.Common.Base.IO; using Core.Common.Util; @@ -79,7 +78,7 @@ return false; } - ZipFile.CreateFromDirectory(tempFolderPath, filePath); + HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(tempFolderPath, filePath); return true; } catch (Exception e) Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs =================================================================== diff -u -r272cfc214b19eee23c9d875bc000a2b7a9a1a78e -rcf5a6ebe9b52b43e570be69a123ba838d7b936c3 --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision 272cfc214b19eee23c9d875bc000a2b7a9a1a78e) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs (.../HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter.cs) (revision cf5a6ebe9b52b43e570be69a123ba838d7b936c3) @@ -23,7 +23,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.IO.Compression; using Core.Common.Base.IO; using Core.Common.Util; using log4net; @@ -91,7 +90,7 @@ return false; } - ZipFile.CreateFromDirectory(tempFolderPath, filePath); + HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(tempFolderPath, filePath); return true; } Index: Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs =================================================================== diff -u -r052b1eeb395a60708c12cefdaca64bfaf456aa6f -rcf5a6ebe9b52b43e570be69a123ba838d7b936c3 --- Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs (.../HydraulicBoundaryLocationCalculationsExportHelper.cs) (revision 052b1eeb395a60708c12cefdaca64bfaf456aa6f) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/HydraulicBoundaryLocationCalculationsExportHelper.cs (.../HydraulicBoundaryLocationCalculationsExportHelper.cs) (revision cf5a6ebe9b52b43e570be69a123ba838d7b936c3) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.IO.Compression; using System.Linq; using Core.Common.Util; using Riskeer.Common.Data.Hydraulics; @@ -73,6 +74,26 @@ calculations, calculationsType, exportedCalculationFileNames, folderPath)); } + /// + /// Creates a zip file on the from the files that are at . + /// + /// + /// + /// Thrown when + /// or is invalid. + public static void CreateZipFileFromExportedFiles(string sourceFolderPath, string destinationFilePath) + { + IOUtils.ValidateFolderPath(sourceFolderPath); + IOUtils.ValidateFilePath(destinationFilePath); + + if (File.Exists(destinationFilePath)) + { + File.Delete(destinationFilePath); + } + + ZipFile.CreateFromDirectory(sourceFolderPath, destinationFilePath); + } + private static bool ExportCalculationsForTargetProbability( Tuple, double> calculationsForTargetProbability, HydraulicBoundaryLocationCalculationsType calculationsType, Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs =================================================================== diff -u -r052b1eeb395a60708c12cefdaca64bfaf456aa6f -rcf5a6ebe9b52b43e570be69a123ba838d7b936c3 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs (.../HydraulicBoundaryLocationCalculationsExportHelperTest.cs) (revision 052b1eeb395a60708c12cefdaca64bfaf456aa6f) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/HydraulicBoundaryLocationCalculationsExportHelperTest.cs (.../HydraulicBoundaryLocationCalculationsExportHelperTest.cs) (revision cf5a6ebe9b52b43e570be69a123ba838d7b936c3) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.IO.Compression; using System.Linq; using System.Security.AccessControl; using Core.Common.TestUtil; @@ -206,6 +207,95 @@ } } + [Test] + public void CreateZipFileFromExportedFiles_SourceFolderPathNull_ThrowsArgumentException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(null, "test"); + + // Assert + Assert.Throws(Call); + } + + [Test] + public void CreateZipFileFromExportedFiles_DestinationFilePathNull_ThrowsArgumentException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles("test", null); + + // Assert + Assert.Throws(Call); + } + + [Test] + public void CreateZipFileFromExportedFiles_ValidPaths_CreatesExpectedZipFile() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(CreateZipFileFromExportedFiles_ValidPaths_CreatesExpectedZipFile)); + Directory.CreateDirectory(directoryPath); + + string sourceFolderPath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO), + nameof(HydraulicBoundaryLocationCalculationsExportHelper)); + string destinationFilePath = Path.Combine(directoryPath, "test.zip"); + + try + { + // Call + HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(sourceFolderPath, destinationFilePath); + + // Assert + Assert.IsTrue(File.Exists(destinationFilePath)); + + using (ZipArchive zipArchive = ZipFile.OpenRead(destinationFilePath)) + { + var expectedFiles = new[] + { + "ExpectedWaterLevelExport.dbf", + "ExpectedWaterLevelExport.shp", + "ExpectedWaterLevelExport.shx", + "ExpectedWaveHeightExport.dbf", + "ExpectedWaveHeightExport.shp", + "ExpectedWaveHeightExport.shx" + }; + CollectionAssert.IsSubsetOf(expectedFiles, zipArchive.Entries.Select(e => e.FullName)); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + [Test] + public void CreateZipFileFromExportedFiles_FileAlreadyExists_DoesNotThrow() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(CreateZipFileFromExportedFiles_FileAlreadyExists_DoesNotThrow)); + Directory.CreateDirectory(directoryPath); + + string sourceFolderPath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO), + nameof(HydraulicBoundaryLocationCalculationsExportHelper)); + string destinationFilePath = Path.Combine(directoryPath, "test.zip"); + + try + { + HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(sourceFolderPath, destinationFilePath); + + // Precondition + Assert.IsTrue(File.Exists(destinationFilePath)); + + // Call + void Call() => HydraulicBoundaryLocationCalculationsExportHelper.CreateZipFileFromExportedFiles(sourceFolderPath, destinationFilePath); + + // Assert + Assert.DoesNotThrow(Call); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + private static string GetExpectedShapeFileName(HydraulicBoundaryLocationCalculationsType calculationsType, double targetProbability) {