Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs =================================================================== diff -u -rda9908d5c3fce6bdd556453e5da99f927c852489 -r543cee7c690b143f71686df24fd86c43099ff917 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision da9908d5c3fce6bdd556453e5da99f927c852489) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision 543cee7c690b143f71686df24fd86c43099ff917) @@ -26,9 +26,11 @@ using Components.Persistence.Stability; using Core.Common.Base.Data; using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; using Core.Common.Util; using log4net; using Riskeer.Common.Data.Calculation; +using Riskeer.Common.IO.Helpers; using Riskeer.Common.Util.Helpers; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.IO.Properties; @@ -109,7 +111,29 @@ public bool Export() { - return ExportCalculationItemsRecursively(calculationGroup, folderPath); + try + { + if (!ExportCalculationItemsRecursively(calculationGroup, tempFolderPath)) + { + return false; + } + + ZipFileExportHelper.CreateZipFileFromExportedFiles(tempFolderPath, filePath); + + return true; + } + catch (CriticalFileWriteException e) + { + log.ErrorFormat("{0} {1}", string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported); + return false; + } + finally + { + if (Directory.Exists(tempFolderPath)) + { + Directory.Delete(tempFolderPath, true); + } + } } private bool ExportCalculationItemsRecursively(CalculationGroup groupToExport, string currentFolderPath) @@ -178,18 +202,19 @@ log.InfoFormat(CoreGuiResources.GuiExportHandler_ExportItemUsingDialog_Start_exporting_DataType_0_, calculation.Name); string uniqueName = NamingHelper.GetUniqueName(exportedCalculations, ((ICalculationBase) calculation).Name, c => c.Value); - string filePath = GetCalculationFilePath(currentFolderPath, uniqueName); + string calculationFilePath = GetCalculationFilePath(currentFolderPath, uniqueName); - var exporter = new MacroStabilityInwardsCalculationExporter(calculation, generalInput, persistenceFactory, filePath, () => getNormativeAssessmentLevelFunc(calculation)); + var exporter = new MacroStabilityInwardsCalculationExporter(calculation, generalInput, persistenceFactory, calculationFilePath, () => getNormativeAssessmentLevelFunc(calculation)); bool exportSucceeded = exporter.Export(); if (!exportSucceeded) { - log.ErrorFormat("{0} {1}", string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported); + log.ErrorFormat("{0} {1}", string.Format("Er is een onverwachte fout opgetreden tijdens het schrijven van \'{0}\'.", calculation.Name), + Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported); return false; } - log.InfoFormat(CoreGuiResources.GuiExportHandler_ExportItemUsingDialog_Data_from_0_exported_to_file_1, calculation.Name, filePath); + log.InfoFormat("Gegevens van \'{0}\' zijn geëxporteerd.", calculation.Name); exportedCalculations.Add(calculation, uniqueName); return true; } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs =================================================================== diff -u -rda9908d5c3fce6bdd556453e5da99f927c852489 -r543cee7c690b143f71686df24fd86c43099ff917 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision da9908d5c3fce6bdd556453e5da99f927c852489) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision 543cee7c690b143f71686df24fd86c43099ff917) @@ -20,7 +20,10 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.IO; +using System.IO.Compression; +using System.Linq; using Components.Persistence.Stability; using Core.Common.Base.IO; using Core.Common.TestUtil; @@ -149,6 +152,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationExporterReturnsFalse_ReturnsFalse)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation = CreateCalculation("calculation"); @@ -163,7 +167,7 @@ }; var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), - persistenceFactory, folderPath, fileExtension, + persistenceFactory, filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -173,8 +177,7 @@ void Call() => exportResult = exporter.Export(); // Assert - string filePath = Path.Combine(folderPath, $"{calculation.Name}.stix"); - string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. Er is geen D-GEO Suite Stability Project geëxporteerd."; + var expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van '{calculation.Name}'. Er is geen D-GEO Suite Stability Project geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple(expectedMessage, LogLevelConstant.Error)); Assert.IsFalse(exportResult); } @@ -191,6 +194,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithOnlyCalculations_WritesFilesAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -200,7 +204,7 @@ calculationGroup.Children.Add(calculation2); var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -212,8 +216,11 @@ // Assert Assert.IsTrue(exportResult); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}")); + AssertFilesExistInZip(new[] + { + $"{calculation1.Name}.{fileExtension}", + $"{calculation2.Name}.{fileExtension}" + }, filePath); } } finally @@ -228,6 +235,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationsWithoutOutput_LogWarningsAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2", false); @@ -237,7 +245,7 @@ calculationGroup.Children.Add(calculation2); var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -255,8 +263,7 @@ new Tuple($"Berekening '{calculation2.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn) }); Assert.IsTrue(exportResult); - Assert.IsFalse(File.Exists(Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}"))); - Assert.IsFalse(File.Exists(Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}"))); + Assert.IsFalse(File.Exists(filePath)); } } finally @@ -271,6 +278,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithNestedGroupsAndCalculations_WritesFilesAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -294,7 +302,7 @@ rootCalculationGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootCalculationGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -306,10 +314,13 @@ // Assert Assert.IsTrue(exportResult); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation3.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name, $"{calculation4.Name}.{fileExtension}")); + AssertFilesExistInZip(new[] + { + $"{calculation1.Name}.{fileExtension}", + $"{calculation2.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{calculation3.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}" + }, filePath); } } finally @@ -324,6 +335,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithNestedGroupsAndCalculations_LogsMessages)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -347,7 +359,7 @@ rootCalculationGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootCalculationGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -359,27 +371,25 @@ void Call() => exportResult = exporter.Export(); // Assert - string calculation1FilePath = Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}"); - string calculation2FilePath = Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}"); - string calculation3FilePath = Path.Combine(folderPath, nestedGroup1.Name, $"{calculation3.Name}.{fileExtension}"); - string calculation4FilePath = Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name, $"{calculation4.Name}.{fileExtension}"); - TestHelper.AssertLogMessagesAreGenerated(Call, new[] { $"Exporteren van '{calculation1.Name}' is gestart.", - $"Gegevens van '{calculation1.Name}' zijn geëxporteerd naar bestand '{calculation1FilePath}'.", + $"Gegevens van '{calculation1.Name}' zijn geëxporteerd.", $"Exporteren van '{calculation2.Name}' is gestart.", - $"Gegevens van '{calculation2.Name}' zijn geëxporteerd naar bestand '{calculation2FilePath}'.", + $"Gegevens van '{calculation2.Name}' zijn geëxporteerd.", $"Exporteren van '{calculation3.Name}' is gestart.", - $"Gegevens van '{calculation3.Name}' zijn geëxporteerd naar bestand '{calculation3FilePath}'.", + $"Gegevens van '{calculation3.Name}' zijn geëxporteerd.", $"Exporteren van '{calculation4.Name}' is gestart.", - $"Gegevens van '{calculation4.Name}' zijn geëxporteerd naar bestand '{calculation4FilePath}'." + $"Gegevens van '{calculation4.Name}' zijn geëxporteerd." }); Assert.IsTrue(exportResult); - AssertCalculationExists(calculation1FilePath); - AssertCalculationExists(calculation2FilePath); - AssertCalculationExists(calculation3FilePath); - AssertCalculationExists(calculation4FilePath); + AssertFilesExistInZip(new[] + { + $"{calculation1.Name}.{fileExtension}", + $"{calculation2.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{calculation3.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}" + }, filePath); } } finally @@ -394,6 +404,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithCalculationsWithSameName_WritesFilesAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -407,7 +418,7 @@ calculationGroup.Children.Add(calculation4); var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -419,10 +430,14 @@ // Assert Assert.IsTrue(exportResult); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation3.Name} (1).{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{calculation4.Name} (2).{fileExtension}")); + + AssertFilesExistInZip(new[] + { + $"{calculation1.Name}.{fileExtension}", + $"{calculation2.Name}.{fileExtension}", + $"{calculation3.Name} (1).{fileExtension}", + $"{calculation4.Name} (2).{fileExtension}" + }, filePath); } } finally @@ -437,6 +452,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupsWithSameName_WritesFilesAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -470,7 +486,7 @@ rootGroup.Children.Add(nestedGroup3); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -482,11 +498,15 @@ // Assert Assert.IsTrue(exportResult); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation1.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation2.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup2.Name} (1)", $"{calculation3.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup2.Name} (1)", $"{calculation4.Name} (1).{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup3.Name} (2)", $"{calculation5.Name}.{fileExtension}")); + + AssertFilesExistInZip(new[] + { + $"{nestedGroup1.Name}/{calculation1.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{calculation2.Name}.{fileExtension}", + $"{nestedGroup2.Name} (1)/{calculation3.Name}.{fileExtension}", + $"{nestedGroup2.Name} (1)/{calculation4.Name} (1).{fileExtension}", + $"{nestedGroup3.Name} (2)/{calculation5.Name}.{fileExtension}" + }, filePath); } } finally @@ -501,6 +521,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupsWithSameName_WritesFilesAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); var rootGroup = new CalculationGroup { @@ -513,7 +534,7 @@ rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -525,7 +546,7 @@ // Assert Assert.IsTrue(exportResult); - Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name))); + Assert.IsFalse(File.Exists(filePath)); } } finally @@ -540,6 +561,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithEmptyCalculationGroups_FolderNotExportedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); var rootGroup = new CalculationGroup { @@ -557,7 +579,7 @@ rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -569,8 +591,7 @@ // Assert Assert.IsTrue(exportResult); - Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name))); - Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name))); + Assert.IsFalse(File.Exists(filePath)); } } finally @@ -585,6 +606,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); @@ -600,7 +622,7 @@ rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -617,7 +639,7 @@ new Tuple($"Berekening '{calculation1.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn) }); Assert.IsTrue(exportResult); - Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name))); + Assert.IsFalse(File.Exists(filePath)); } } finally @@ -632,6 +654,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithGroupsWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2", false); @@ -654,7 +677,7 @@ rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -687,6 +710,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithGroupsWithCalculationsWithAndWithoutOutput_FolderNotExportedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -709,7 +733,7 @@ rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try @@ -726,8 +750,11 @@ new Tuple($"Berekening '{calculation1.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn) }); Assert.IsTrue(exportResult); - Assert.IsFalse(File.Exists(Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name, $"{calculation1.Name}.{fileExtension}"))); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name, $"{calculation2.Name}.{fileExtension}")); + + AssertFilesExistInZip(new[] + { + $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation2.Name}.{fileExtension}" + }, filePath); } } finally @@ -742,6 +769,7 @@ // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_ErrorDuringSingleCalculationExport_LogsErrorAndReturnsFalse)}"); Directory.CreateDirectory(folderPath); + string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); @@ -768,7 +796,7 @@ rootGroup.Children.Add(nestedGroup2); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), - new PersistenceFactory(), folderPath, fileExtension, + new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); Directory.CreateDirectory(Path.Combine(folderPath, nestedGroup2.Name)); string lockedCalculationFilePath = Path.Combine(folderPath, nestedGroup2.Name, $"{calculation3.Name}.{fileExtension}"); @@ -788,9 +816,15 @@ string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{lockedCalculationFilePath}'. Er is geen D-GEO Suite Stability Project geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple(expectedMessage, LogLevelConstant.Error)); Assert.IsFalse(exportResult); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation1.Name}.{fileExtension}")); - AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation2.Name}.{fileExtension}")); - Assert.IsFalse(File.Exists(Path.Combine(folderPath, nestedGroup2.Name, $"{calculation4.Name}.{fileExtension}"))); + AssertFilesExistInZip(new[] + { + $"{nestedGroup1.Name}/{calculation1.Name}.{fileExtension}", + $"{nestedGroup1.Name}/{calculation2.Name}.{fileExtension}" + }, filePath); + AssertFilesDoNotExistInZip(new[] + { + $"{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}" + }, filePath); } } finally @@ -799,12 +833,22 @@ } } - private static void AssertCalculationExists(string calculationPath) + private static void AssertFilesExistInZip(IEnumerable expectedFiles, string filePath) { - Assert.IsTrue(File.Exists(calculationPath)); - Assert.IsFalse(File.Exists($"{calculationPath}.temp")); + using (ZipArchive zipArchive = ZipFile.OpenRead(filePath)) + { + CollectionAssert.IsSubsetOf(expectedFiles, zipArchive.Entries.Select(e => e.FullName)); + } } + private static void AssertFilesDoNotExistInZip(IEnumerable expectedFiles, string filePath) + { + using (ZipArchive zipArchive = ZipFile.OpenRead(filePath)) + { + CollectionAssert.IsNotSubsetOf(expectedFiles, zipArchive.Entries.Select(e => e.FullName)); + } + } + private static MacroStabilityInwardsCalculationScenario CreateCalculation(string calculationName, bool setOutput = true) { MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj =================================================================== diff -u -r66cd5ef08ec60ee1e2729efff87123457db700c6 -r543cee7c690b143f71686df24fd86c43099ff917 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj (.../Riskeer.MacroStabilityInwards.IO.Test.csproj) (revision 66cd5ef08ec60ee1e2729efff87123457db700c6) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj (.../Riskeer.MacroStabilityInwards.IO.Test.csproj) (revision 543cee7c690b143f71686df24fd86c43099ff917) @@ -12,6 +12,7 @@ +