Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs =================================================================== diff -u -r6f3f5cd43feafa96fdedaeb2ccb01240c4261de1 -r62d53cd1f3e85be9b340e24d3a84d71493a8fe71 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision 6f3f5cd43feafa96fdedaeb2ccb01240c4261de1) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision 62d53cd1f3e85be9b340e24d3a84d71493a8fe71) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2019. All rights reserved. +// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // @@ -102,7 +102,7 @@ private bool ExportCalculationItemsRecursively(CalculationGroup groupToExport, string currentFolderPath) { - CreateDirectory(currentFolderPath); + CreateDirectoryWhenNeeded(groupToExport, currentFolderPath); var continueExport = true; var exportedGroups = new Dictionary(); @@ -112,7 +112,7 @@ { switch (calculationItem) { - case CalculationGroup nestedGroup when HasChildrenWithOutput(nestedGroup): + case CalculationGroup nestedGroup when HasChildren(nestedGroup): continueExport = ExportCalculationGroup(nestedGroup, currentFolderPath, exportedGroups); break; case MacroStabilityInwardsCalculation calculation when !calculation.HasOutput: @@ -132,17 +132,16 @@ return true; } - private static bool HasChildrenWithOutput(CalculationGroup nestedGroup) + private static bool HasChildren(CalculationGroup nestedGroup) { - MacroStabilityInwardsCalculation[] calculations = nestedGroup.GetCalculations() - .Cast() - .ToArray(); - return calculations.Any() && calculations.Any(calculation => calculation.HasOutput); + return nestedGroup.GetCalculations() + .Cast() + .Any(); } - private static void CreateDirectory(string currentFolderPath) + private static void CreateDirectoryWhenNeeded(CalculationGroup nestedGroup, string currentFolderPath) { - if (!Directory.Exists(currentFolderPath)) + if (nestedGroup.HasOutput() && !Directory.Exists(currentFolderPath)) { Directory.CreateDirectory(currentFolderPath); } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs =================================================================== diff -u -r6f3f5cd43feafa96fdedaeb2ccb01240c4261de1 -r62d53cd1f3e85be9b340e24d3a84d71493a8fe71 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision 6f3f5cd43feafa96fdedaeb2ccb01240c4261de1) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision 62d53cd1f3e85be9b340e24d3a84d71493a8fe71) @@ -538,10 +538,10 @@ } [Test] - public void Export_NestedCalculationGroupWithCalculationsWithoutOutput_FolderNotExportedAndReturnsTrue() + public void Export_NestedCalculationGroupWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue() { // Setup - string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithCalculationsWithoutOutput_FolderNotExportedAndReturnsTrue)}"); + string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); @@ -564,9 +564,14 @@ using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call - bool exportResult = exporter.Export(); + var exportResult = false; + void Call() => exportResult = exporter.Export(); // Assert + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, new[] + { + 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))); } @@ -578,10 +583,10 @@ } [Test] - public void Export_NestedCalculationGroupWithGroupsWithCalculationsWithoutOutput_FolderNotExportedAndReturnsTrue() + public void Export_NestedCalculationGroupWithGroupsWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue() { // Setup - string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithGroupsWithCalculationsWithoutOutput_FolderNotExportedAndReturnsTrue)}"); + string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithGroupsWithCalculationsWithoutOutput_FolderNotExportedAndMessageLoggedAndReturnsTrue)}"); Directory.CreateDirectory(folderPath); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false); @@ -611,10 +616,15 @@ using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call - bool exportResult = exporter.Export(); + var exportResult = false; + void Call() => exportResult = exporter.Export(); // Assert - Assert.IsTrue(exportResult); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, new[] + { + new Tuple($"Berekening '{calculation1.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn), + new Tuple($"Berekening '{calculation2.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn), + }); Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name, nestedGroup2.Name))); Assert.IsFalse(Directory.Exists(Path.Combine(folderPath, nestedGroup1.Name))); } @@ -659,9 +669,14 @@ using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call - bool exportResult = exporter.Export(); + var exportResult = false; + void Call() => exportResult = exporter.Export(); // Assert + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, new[] + { + 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}"));