/// <inheritdoc /> /// <remarks> /// To avoid problems with writing to an existing file, the export is done to a temp file first. /// When the export was successful the file is moved to the given <see cref="filePath"/>. /// </remarks> public bool Export() { ValidateData(); PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, generalInput, getNormativeAssessmentLevelFunc, filePath); string tempFilePath = $"{filePath}.temp"; try { using (IPersister persister = persistenceFactory.CreateArchivePersister(tempFilePath, persistableDataModel)) { persister.Persist(); } MoveTempFileToFinal(tempFilePath); } catch (Exception) { File.Delete(tempFilePath); log.ErrorFormat("{0} {1}", string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported); return(false); } return(true); }
public void Create_GetAssessmentLevelFuncNull_ThrowsArgumentNullException() { // Call void Call() => PersistableDataModelFactory.Create(new MacroStabilityInwardsCalculation(), new GeneralMacroStabilityInwardsInput(), null, string.Empty); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("getNormativeAssessmentLevelFunc", exception.ParamName); }
public void Create_GeneralInputNull_ThrowsArgumentNullException() { // Call void Call() => PersistableDataModelFactory.Create(new MacroStabilityInwardsCalculation(), null, AssessmentSectionTestHelper.GetTestAssessmentLevel, string.Empty); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("generalInput", exception.ParamName); }
public void Create_CalculationWithoutOutput_ThrowsInvalidOperationException() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); // Call void Call() => PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, string.Empty); // Assert var exception = Assert.Throws <InvalidOperationException>(Call); Assert.AreEqual("Calculation must have output.", exception.Message); }
public void Create_WithValidData_ReturnsPersistableDataModel() { // Setup const string filePath = "ValidFilePath"; MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath); // Assert PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel); } }