public void Export_NestedCalculationGroupWithGroupsWithCalculationsWithAndWithoutOutput_FolderNotExportedAndReturnsTrue() { // 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"); var rootGroup = new CalculationGroup { Name = "root" }; var nestedGroup1 = new CalculationGroup { Name = "group1" }; var nestedGroup2 = new CalculationGroup { Name = "group2" }; nestedGroup2.Children.Add(calculation2); nestedGroup2.Children.Add(calculation1); nestedGroup1.Children.Add(nestedGroup2); rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, new[] { new Tuple <string, LogLevelConstant>($"Berekening '{calculation1.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn) }); Assert.IsTrue(exportResult); AssertFilesExistInZip(new[] { $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation2.Name}.{fileExtension}" }, filePath); } } finally { DirectoryHelper.TryDelete(folderPath); } }
public void Export_CalculationGroupWithNestedGroupsAndCalculations_WritesFilesAndReturnsTrue() { // 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"); MacroStabilityInwardsCalculationScenario calculation3 = CreateCalculation("calculation3"); MacroStabilityInwardsCalculationScenario calculation4 = CreateCalculation("calculation4"); var rootCalculationGroup = new CalculationGroup(); var nestedGroup1 = new CalculationGroup { Name = "NestedGroup1" }; var nestedGroup2 = new CalculationGroup { Name = "NestedGroup2" }; nestedGroup2.Children.Add(calculation4); nestedGroup1.Children.Add(calculation3); nestedGroup1.Children.Add(nestedGroup2); rootCalculationGroup.Children.Add(calculation1); rootCalculationGroup.Children.Add(calculation2); rootCalculationGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootCalculationGroup, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call bool exportResult = exporter.Export(); // Assert Assert.IsTrue(exportResult); AssertFilesExistInZip(new[] { $"{calculation1.Name}.{fileExtension}", $"{calculation2.Name}.{fileExtension}", $"{nestedGroup1.Name}/{calculation3.Name}.{fileExtension}", $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}" }, filePath); } } finally { DirectoryHelper.TryDelete(folderPath); } }
public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var persistenceFactory = mocks.Stub <IPersistenceFactory>(); mocks.ReplayAll(); // Call var exporter = new MacroStabilityInwardsCalculationGroupExporter(new CalculationGroup(), new GeneralMacroStabilityInwardsInput(), persistenceFactory, "ValidFolderPath", "extension", c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); // Assert Assert.IsInstanceOf <IFileExporter>(exporter); mocks.VerifyAll(); }
public void Export_NestedCalculationGroupWithEmptyCalculationGroups_FolderNotExportedAndReturnsTrue() { // 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 { Name = "root" }; var nestedGroup1 = new CalculationGroup { Name = "group1" }; var nestedGroup2 = new CalculationGroup { Name = "group2" }; nestedGroup1.Children.Add(nestedGroup2); rootGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call bool exportResult = exporter.Export(); // Assert Assert.IsTrue(exportResult); Assert.IsFalse(File.Exists(filePath)); } } finally { DirectoryHelper.TryDelete(folderPath); } }
public void Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse() { // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse)}"); Directory.CreateDirectory(folderPath); string filePath = Path.Combine(folderPath, "test.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); var calculationGroup = new CalculationGroup(); calculationGroup.Children.Add(calculation1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var helper = new FileDisposeHelper(filePath)) { helper.LockFiles(); // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " + "Er zijn geen D-GEO Suite Stability Projecten geëxporteerd."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage); Assert.IsFalse(isExported); } } finally { DirectoryHelper.TryDelete(folderPath); } }
public void Export_CalculationExportReturnsFalse_LogsErrorAndReturnsFalse(CalculationGroup calculationGroup) { // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationExportReturnsFalse_LogsErrorAndReturnsFalse)}"); Directory.CreateDirectory(folderPath); string filePath = Path.Combine(folderPath, "export.zip"); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { ThrowException = true }; var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { // Call var exportResult = true; void Call() => exportResult = exporter.Export(); // Assert ICalculation calculation = calculationGroup.GetCalculations().First(); var expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het exporteren van '{calculation.Name}'. Er is geen D-GEO Suite Stability Project geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error)); Assert.IsFalse(exportResult); Assert.IsFalse(File.Exists(filePath)); } finally { DirectoryHelper.TryDelete(folderPath); } } }
public void Export_CalculationGroupWithNestedGroupsAndCalculationsWithExportWarnings_LogsMessagesAndWritesFile() { // Setup string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithNestedGroupsAndCalculationsWithExportWarnings_LogsMessagesAndWritesFile)}"); Directory.CreateDirectory(folderPath); string filePath = Path.Combine(folderPath, "export.zip"); MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); calculation1.InputParameters.StochasticSoilProfile.SoilProfile.Layers.ForEachElementDo(layer => layer.Data.IsAquifer = true); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); calculation2.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)), MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2)) }); MacroStabilityInwardsCalculationScenario calculation3 = CreateCalculation("calculation3"); MacroStabilityInwardsCalculationScenario calculation4 = CreateCalculation("calculation4"); var rootCalculationGroup = new CalculationGroup(); var nestedGroup1 = new CalculationGroup { Name = "NestedGroup1" }; var nestedGroup2 = new CalculationGroup { Name = "NestedGroup2" }; nestedGroup2.Children.Add(calculation4); nestedGroup1.Children.Add(calculation3); nestedGroup1.Children.Add(nestedGroup2); rootCalculationGroup.Children.Add(calculation1); rootCalculationGroup.Children.Add(calculation2); rootCalculationGroup.Children.Add(nestedGroup1); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootCalculationGroup, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert TestHelper.AssertLogMessagesAreGenerated(Call, new[] { $"'{calculation1.Name}': De schematisatie van de berekening bevat meerdere aquifer lagen. De volgorde van de aquifer lagen kan niet bepaald worden tijdens exporteren. Er worden daarom geen lagen als aquifer geëxporteerd.", $"'{calculation2.Name}': De schematisatie van de berekening bevat meerdere stresspunten binnen één laag of stresspunten die niet aan een laag gekoppeld kunnen worden. Er worden daarom geen POP en grensspanningen geëxporteerd." }); Assert.IsTrue(exportResult); AssertFilesExistInZip(new[] { $"{calculation1.Name}.{fileExtension}", $"{calculation2.Name}.{fileExtension}", $"{nestedGroup1.Name}/{calculation3.Name}.{fileExtension}", $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}" }, filePath); } } finally { DirectoryHelper.TryDelete(folderPath); } }