Index: Application/Riskeer/src/Application.Riskeer/App.xaml.cs =================================================================== diff -u -r356d30ff0493a3b0174f61aadbca0cbbf1f8d962 -rf1542ea58cee65e7bb0d7a398cd9359ecd3960bc --- Application/Riskeer/src/Application.Riskeer/App.xaml.cs (.../App.xaml.cs) (revision 356d30ff0493a3b0174f61aadbca0cbbf1f8d962) +++ Application/Riskeer/src/Application.Riskeer/App.xaml.cs (.../App.xaml.cs) (revision f1542ea58cee65e7bb0d7a398cd9359ecd3960bc) @@ -131,7 +131,7 @@ SupportEmailAddressUrl = "https://www.helpdeskwater.nl/onderwerpen/applicaties-modellen/applicaties-per/omgevings/omgevings/riskeer/contact/vraag-ringtoets/", SupportPhoneNumberUrl = "https://www.helpdeskwater.nl/secundaire-navigatie/contact/", ManualFilePath = "Gebruikershandleiding Riskeer 21.1.1.pdf", - OnNewProjectCreatedAction = (g, project) => new AssessmentSectionFromFileHandler(g.ActiveParentWindow, g.DocumentViewController).GetAssessmentSectionFromFile((RiskeerProject) project) + OnNewProjectCreatedAction = (g, project) => new AssessmentSectionFromFileHandler(g.ActiveParentWindow, g.DocumentViewController).GetAssessmentSectionFromFile() }; var mainWindow = new MainWindow(); Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionFromFileHandler.cs =================================================================== diff -u -r356d30ff0493a3b0174f61aadbca0cbbf1f8d962 -rf1542ea58cee65e7bb0d7a398cd9359ecd3960bc --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionFromFileHandler.cs (.../AssessmentSectionFromFileHandler.cs) (revision 356d30ff0493a3b0174f61aadbca0cbbf1f8d962) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionFromFileHandler.cs (.../AssessmentSectionFromFileHandler.cs) (revision f1542ea58cee65e7bb0d7a398cd9359ecd3960bc) @@ -47,7 +47,7 @@ /// /// This class is responsible for adding an from a predefined location. /// - public class AssessmentSectionFromFileHandler : IAssessmentSectionFromFileHandler + public class AssessmentSectionFromFileHandler { private static readonly ILog log = LogManager.GetLogger(typeof(AssessmentSectionFromFileHandler)); private readonly string shapeFileDirectory = RiskeerSettingsHelper.GetCommonDocumentsRiskeerShapeFileDirectory(); @@ -79,6 +79,39 @@ this.viewController = viewController; } + /// + /// Displays available objects to the user and asks to select one. + /// The selected , if any, will be returned. + /// + /// The selected ; or null when cancelled. + /// Thrown when: + /// + /// points to an invalid directory. + /// The path does not contain any shape files. + /// Thrown when the shape file does not contain poly lines. + /// + /// Thrown when: + /// + /// The shape file does not contain the required attributes. + /// The assessment section ids in the shape file are not unique or are missing. + /// No could be read from the shape file. + /// The lower limit norm is not in the interval [0.000001, 0.1] or is ; + /// The signaling norm is not in the interval [0.000001, 0.1] or is ; + /// The signaling norm is larger than the lower limit norm. + /// + public AssessmentSection GetAssessmentSectionFromFile() + { + TryReadSourceFiles(); + return GetAssessmentSectionFromDialog(); + } + + /// + /// Performs the post actions. + /// + /// The + /// to do the actions for. + /// Thrown when + /// is null. public void DoPostHandleActions(AssessmentSection assessmentSection) { if (assessmentSection == null) @@ -89,19 +122,6 @@ viewController.OpenViewForData(assessmentSection); } - public AssessmentSection GetAssessmentSectionFromFile(RiskeerProject project) - { - if (project == null) - { - throw new ArgumentNullException(nameof(project)); - } - - TryReadSourceFiles(); - return GetAssessmentSectionFromDialog(); - } - - #region Set AssessmentSection to Project - private static void SetFailureMechanismsValueN(AssessmentSection assessmentSection, int n) { var roundedN = (RoundedDouble) n; @@ -110,8 +130,6 @@ assessmentSection.HeightStructures.GeneralInput.N = roundedN; } - #endregion - #region Dialog private AssessmentSection GetAssessmentSectionFromDialog() @@ -263,6 +281,21 @@ return assessmentSection; } + /// + /// Tries to create the . + /// + /// The selected . + /// The lower limit norm of the assessment section. + /// The signaling norm which of the assessment section. + /// The norm type of the assessment section. + /// The created . + /// Thrown when: + /// + /// is not in the interval [0.000001, 0.1] or is ; + /// is not in the interval [0.000001, 0.1] or is ; + /// The is larger than . + /// + /// private AssessmentSection TryCreateAssessmentSection(ReferenceLineMeta selectedItem, double lowerLimitNorm, double signalingNorm, @@ -291,6 +324,21 @@ #region Validators + /// + /// Tries to read the source files. + /// + /// Thrown when: + /// + /// points to an invalid directory. + /// The path does not contain any shape files. + /// Thrown when the shape file does not contain poly lines. + /// + /// Thrown when: + /// + /// The shape file does not contain the required attributes. + /// The assessment section ids in the shape file are not unique or are missing. + /// No could be read from the shape file. + /// private void TryReadSourceFiles() { ReadAssessmentSectionSettings(); Fisheye: Tag f1542ea58cee65e7bb0d7a398cd9359ecd3960bc refers to a dead (removed) revision in file `Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/IAssessmentSectionFromFileHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/AssessmentSectionFromFileHandlerTest.cs =================================================================== diff -u -r356d30ff0493a3b0174f61aadbca0cbbf1f8d962 -rf1542ea58cee65e7bb0d7a398cd9359ecd3960bc --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/AssessmentSectionFromFileHandlerTest.cs (.../AssessmentSectionFromFileHandlerTest.cs) (revision 356d30ff0493a3b0174f61aadbca0cbbf1f8d962) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/Handlers/AssessmentSectionFromFileHandlerTest.cs (.../AssessmentSectionFromFileHandlerTest.cs) (revision f1542ea58cee65e7bb0d7a398cd9359ecd3960bc) @@ -84,71 +84,31 @@ } [Test] - public void Constructor_WithData_ExpectedValues() + public void GetAssessmentSectionFromFile_InvalidDirectory_ThrowsCriticalFileReadException() { // Setup var mockRepository = new MockRepository(); var parentDialog = mockRepository.Stub(); var viewController = mockRepository.Stub(); mockRepository.ReplayAll(); - // Call var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog, viewController); - // Assert - Assert.IsInstanceOf>(assessmentSectionFromFileHandler); - mockRepository.VerifyAll(); - } - - [Test] - public void GetAssessmentSectionFromFile_ProjectNull_ThrowsArgumentNullException() - { - // Setup - var mockRepository = new MockRepository(); - var parentDialog = mockRepository.Stub(); - var viewController = mockRepository.Stub(); - mockRepository.ReplayAll(); - - var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog, viewController); - - // Call - void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("project", exception.ParamName); - mockRepository.VerifyAll(); - } - - [Test] - public void GetAssessmentSectionFromFile_InvalidDirectory_ThrowsExceptionProjectNotUpdated() - { - // Setup - var mockRepository = new MockRepository(); - var parentDialog = mockRepository.Stub(); - var viewController = mockRepository.Stub(); - mockRepository.ReplayAll(); - - var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog, viewController); - string pathToNonExistingFolder = Path.Combine(testDataPath, "I do not exist"); SetShapeFileDirectory(assessmentSectionFromFileHandler, pathToNonExistingFolder); - var project = new RiskeerProject(); - // Call - void Action() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert var expectedMessage = $"De map met specificaties voor trajecten '{pathToNonExistingFolder}' is niet gevonden."; - var exception = Assert.Throws(Action); + var exception = Assert.Throws(Call); Assert.AreEqual(expectedMessage, exception.Message); - Assert.IsEmpty(project.AssessmentSections); mockRepository.VerifyAll(); } [Test] - public void GetAssessmentSectionFromFile_validDirectoryWithEmptyShapeFile_ThrowsExceptionWarningProjectNotUpdated() + public void GetAssessmentSectionFromFile_validDirectoryWithEmptyShapeFile_ShowsWarningDialogAndThrowsCriticalFileReadException() { // Setup var mockRepository = new MockRepository(); @@ -169,22 +129,19 @@ messageBox.ClickOk(); }; - var project = new RiskeerProject(); - // Call - void Action() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert const string expectedMessage = "Er kunnen geen trajecten gelezen worden uit het shapebestand."; - var exception = Assert.Throws(Action); + var exception = Assert.Throws(Call); Assert.AreEqual(expectedMessage, exception.Message); Assert.AreEqual(expectedMessage, messageText); - Assert.IsEmpty(project.AssessmentSections); mockRepository.VerifyAll(); } [Test] - public void GetAssessmentSectionFromFile_ValidDirectoryUserClicksCancel_ProjectNotUpdated() + public void GetAssessmentSectionFromFile_ValidDirectoryUserClicksCancel_ReturnsNull() { // Setup var mockRepository = new MockRepository(); @@ -203,14 +160,11 @@ new ButtonTester("Cancel", selectionDialog).Click(); }; - var project = new RiskeerProject(); - // Call - AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert Assert.IsNull(assessmentSection); - Assert.IsEmpty(project.AssessmentSections); mockRepository.VerifyAll(); } @@ -237,10 +191,8 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - // Call - AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert Assert.AreEqual(3, rowCount); @@ -270,10 +222,8 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - // Call - AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert AssertAssessmentSection(TestAssessmentSection1_2(false), assessmentSection); @@ -306,10 +256,8 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - // Call - AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert Assert.AreEqual(3, rowCount); @@ -341,12 +289,10 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - AssessmentSection assessmentSection = null; // Call - void Call() => assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + void Call() => assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert const string expectedMessage = "Er zijn geen instellingen gevonden voor het geselecteerde traject. Standaardinstellingen zullen gebruikt worden."; @@ -380,12 +326,10 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - AssessmentSection assessmentSection = null; // Call - void Call() => assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + void Call() => assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert const string expectedMessage = "Het importeren van de referentielijn is mislukt."; @@ -401,7 +345,7 @@ [Test] [SetCulture("nl-NL")] - public void GetAssessmentSectionFromFile_ShapeWithInvalidNorm_ThrowsCriticalFileValidationExceptionAndProjectNotUpdated() + public void GetAssessmentSectionFromFile_ShapeWithInvalidNorm_ThrowsCriticalFileValidationException() { // Setup var mockRepository = new MockRepository(); @@ -424,10 +368,8 @@ new ButtonTester("Ok", selectionDialog).Click(); }; - var project = new RiskeerProject(); - // Call - void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(project); + void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile(); // Assert const string expectedMessage = "Het traject kan niet aangemaakt worden met een ondergrens van 1/9.999.999 en een signaleringswaarde van 1/8.888.888. " + @@ -436,7 +378,6 @@ var exception = Assert.Throws(Call); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf(exception.InnerException); - CollectionAssert.IsEmpty(project.AssessmentSections); mockRepository.VerifyAll(); }