public void Export_SoilProfileWithMultipleAquiferLayers_LogsWarningAndReturnsTrue() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.StochasticSoilProfile.SoilProfile.Layers.ForEachElementDo(layer => layer.Data.IsAquifer = true); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.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."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)), MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2)) }); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.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."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue(double maximumSliceWidth) { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.MaximumSliceWidth = (RoundedDouble)maximumSliceWidth; calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.Name}': De berekening bevat een lamelbreedte van {calculation.InputParameters.MaximumSliceWidth.ToString(null, CultureInfo.CurrentCulture)} meter. D-GEO Suite Stability ondersteunt enkel een maximale lamelbreedte van 1 meter. Er wordt daarom een lamelbreedte van 1 meter geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void Export_RunsSuccessful_WritesFileAndRemovesTempFile() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_RunsSuccessful_WritesFileAndRemovesTempFile)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call bool exportResult = exporter.Export(); // Assert Assert.IsTrue(exportResult); Assert.IsTrue(File.Exists(filePath)); Assert.IsFalse(File.Exists($"{filePath}.temp")); } } finally { File.Delete(filePath); } }
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_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); } }