public void Export_PersistenceFactoryThrowsException_NoFileWritten() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_PersistenceFactoryThrowsException_NoFileWritten)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { ThrowException = true, WriteFile = true }; var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call exporter.Export(); // Assert Assert.IsFalse(File.Exists(filePath)); Assert.IsFalse(File.Exists($"{filePath}.temp")); } }
public void Export_PersistenceFactoryThrowsException_LogsErrorAndReturnsFalse() { // Setup const string filePath = "ValidFilePath"; MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { ThrowException = true }; var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call var exportResult = true; void Call() => exportResult = exporter.Export(); // Assert 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."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error)); Assert.IsFalse(exportResult); } }
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_RunsSuccessful_SetsDataCorrectlyAndReturnsTrue() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_RunsSuccessful_SetsDataCorrectlyAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { WriteFile = true }; var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call bool exportResult = exporter.Export(); // Assert PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistenceFactory.PersistableDataModel); Assert.AreEqual($"{filePath}.temp", persistenceFactory.FilePath); var persister = (MacroStabilityInwardsTestPersister)persistenceFactory.CreatedPersister; Assert.IsTrue(persister.PersistCalled); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }