Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -31,11 +31,9 @@
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Probabilistics;
-using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Data;
-using Ringtoets.GrassCoverErosionOutwards.Plugin;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HydraRing.Data;
using Ringtoets.Integration.Data;
Index: Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj
===================================================================
diff -u -r50731952f4ed66c06d672328387d581277b1d970 -r4e578730273a943bb02a2861c694a2707c8ef852
--- Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj (.../Demo.Ringtoets.csproj) (revision 50731952f4ed66c06d672328387d581277b1d970)
+++ Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj (.../Demo.Ringtoets.csproj) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -137,11 +137,6 @@
Ringtoets.Common.Data
False
-
- {4d840673-3812-4338-a352-84854e32b8a0}
- Ringtoets.Common.Forms
- False
-
{52ba7627-cbab-4209-be77-3b5f31378277}
Ringtoets.Common.IO
@@ -157,11 +152,6 @@
Ringtoets.GrassCoverErosionOutwards.Data
False
-
- {9b3ed064-e29f-4d38-85e0-3a82b77ba702}
- Ringtoets.GrassCoverErosionOutwards.Plugin
- False
-
{1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99}
Ringtoets.HeightStructures.Data
@@ -187,11 +177,6 @@
Ringtoets.Piping.Data
False
-
- {7cd038e1-e111-4969-aced-22c5bd2974e1}
- Ringtoets.Piping.Forms
- False
-
{1d3d58b6-ef7e-401e-92a0-104067d222ee}
Ringtoets.Piping.Plugin
Index: Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/DikeProfileDataReader.cs
===================================================================
diff -u -rd2b9feaf8aceaa9a96d0e6e19fd6fbbee8987ca6 -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/DikeProfileDataReader.cs (.../DikeProfileDataReader.cs) (revision d2b9feaf8aceaa9a96d0e6e19fd6fbbee8987ca6)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/DikeProfileDataReader.cs (.../DikeProfileDataReader.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -64,12 +64,12 @@
///
/// The file path.
/// The read .
- /// When is invalid.
- /// When an error occurs like:
+ /// Thrown when is invalid.
+ /// Thrown when:
///
/// - refers to a file that doesn't exist.
/// - A piece of text from the file cannot be converted into the expected variable type.
- /// - An critical I/O exception occurred while attempting to read a line in the file.
+ /// - A critical I/O exception occurred while attempting to read a line in the file.
/// - A converted value is invalid.
/// - The file is incomplete.
/// - A keyword is defined more then once.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocation.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocation.cs (.../ProfileLocation.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocation.cs (.../ProfileLocation.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -38,7 +38,7 @@
/// The name of this .
/// The coordinate offset in the local coordinate system for this .
/// The coordinates of the location as a .
- ///
+ /// Thrown when:
/// - The Id parameter is null.
/// - The Id parameter contains illegal characters.
/// - The Point parameter is null.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocationReader.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocationReader.cs (.../ProfileLocationReader.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/DikeProfiles/ProfileLocationReader.cs (.../ProfileLocationReader.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -48,8 +48,8 @@
/// Initializes a new instance of the class.
///
/// The shape file path.
- /// is invalid.
- ///
+ /// Thrown when is invalid.
+ /// Thrown when:
/// - points to a file that does not exist.
/// - does not only contain point features.
/// - does not contain all of the required attributes.
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLineExporter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLineImporter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLineMetaImporter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLineReader.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLineWriter.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLine/ReferenceLinesMetaReader.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineExporter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineExporter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineExporter.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,76 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Common.Base.IO;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils;
+using log4net;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.Properties;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Exports a associated to an and stores it as a shapefile.
+ ///
+ public class ReferenceLineExporter : IFileExporter
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineExporter));
+
+ private readonly ReferenceLine referenceLine;
+ private readonly string filePath;
+ private readonly string id;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The reference line to export.
+ /// The id of the assessment section to which this reference line is associated.
+ /// The path of the file to export to.
+ /// Thrown when is invalid.
+ public ReferenceLineExporter(ReferenceLine referenceLine, string id, string filePath)
+ {
+ FileUtils.ValidateFilePath(filePath);
+
+ this.referenceLine = referenceLine;
+ this.filePath = filePath;
+ this.id = id;
+ }
+
+ public bool Export()
+ {
+ var referenceLineWriter = new ReferenceLineWriter();
+
+ try
+ {
+ referenceLineWriter.WriteReferenceLine(referenceLine, id, filePath);
+ }
+ catch (CriticalFileWriteException e)
+ {
+ log.Error(string.Format(Resources.ReferenceLineExporter_Error_0_no_ReferenceLine_exported, e.Message));
+ return false;
+ }
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,202 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Base.IO;
+using Core.Common.IO.Exceptions;
+using Core.Common.IO.Readers;
+using log4net;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.FailureMechanism;
+using CoreCommonBaseResources = Core.Common.Base.Properties.Resources;
+using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Imports a and stores in on a ,
+ /// taking data from a shapefile containing a single polyline.
+ ///
+ public class ReferenceLineImporter : FileImporterBase
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineImporter));
+
+ private readonly IList changedObservables = new List();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The assessment section to update.
+ /// The path to the file to import from.
+ /// When is null.
+ public ReferenceLineImporter(IAssessmentSection importTarget, string filePath) : base(filePath, importTarget) {}
+
+ public override bool Import()
+ {
+ Canceled = false;
+ changedObservables.Clear();
+
+ bool clearReferenceLineDependentData = false;
+
+ if (ImportTarget.ReferenceLine != null)
+ {
+ clearReferenceLineDependentData = ConfirmImportOfReferenceLineToClearReferenceLineDependentData();
+ }
+
+ if (Canceled)
+ {
+ HandleUserCancellingImport();
+ return false;
+ }
+
+ NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Reading_referenceline,
+ 1, clearReferenceLineDependentData ? 4 : 2);
+ ReadResult readResult = ReadReferenceLine();
+ if (readResult.CriticalErrorOccurred)
+ {
+ return false;
+ }
+
+ if (Canceled)
+ {
+ HandleUserCancellingImport();
+ return false;
+ }
+
+ AddReferenceLineToDataModel(readResult.ImportedItems.First(), clearReferenceLineDependentData);
+ return true;
+ }
+
+ protected override IEnumerable AffectedNonTargetObservableInstances
+ {
+ get
+ {
+ return changedObservables;
+ }
+ }
+
+ private bool ConfirmImportOfReferenceLineToClearReferenceLineDependentData()
+ {
+ DialogResult result = MessageBox.Show(RingtoetsCommonIOResources.ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_data_when_performed,
+ CoreCommonBaseResources.Confirm,
+ MessageBoxButtons.OKCancel);
+ if (result == DialogResult.Cancel)
+ {
+ Canceled = true;
+ }
+ else
+ {
+ if (ImportTarget.GetFailureMechanisms() != null)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static void HandleUserCancellingImport()
+ {
+ log.Info(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read);
+ }
+
+ private ReadResult ReadReferenceLine()
+ {
+ try
+ {
+ return new ReadResult(false)
+ {
+ ImportedItems = new[]
+ {
+ new ReferenceLineReader().ReadReferenceLine(FilePath)
+ }
+ };
+ }
+ catch (ArgumentException e)
+ {
+ return HandleCriticalFileReadError(e);
+ }
+ catch (CriticalFileReadException e)
+ {
+ return HandleCriticalFileReadError(e);
+ }
+ }
+
+ private static ReadResult HandleCriticalFileReadError(Exception e)
+ {
+ var errorMessage = string.Format(RingtoetsCommonIOResources.ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported,
+ e.Message);
+ log.Error(errorMessage);
+ return new ReadResult(true);
+ }
+
+ private void AddReferenceLineToDataModel(ReferenceLine importedReferenceLine, bool clearReferenceLineDependentData)
+ {
+ NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsection,
+ 2, clearReferenceLineDependentData ? 4 : 2);
+ ImportTarget.ReferenceLine = importedReferenceLine;
+
+ if (clearReferenceLineDependentData && ImportTarget.GetFailureMechanisms() != null)
+ {
+ ClearReferenceLineDependentData();
+ }
+ }
+
+ private void ClearReferenceLineDependentData()
+ {
+ NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechanism_sections,
+ 3, 4);
+ foreach (var failureMechanism in ImportTarget.GetFailureMechanisms())
+ {
+ ClearCalculationOutput(failureMechanism);
+ ClearFailureMechanismSections(failureMechanism);
+ }
+ NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output,
+ 4, 4);
+ ClearHydraulicBoundaryOutput();
+ }
+
+ private void ClearCalculationOutput(IFailureMechanism failureMechanism)
+ {
+ foreach (var calculationItem in failureMechanism.Calculations)
+ {
+ calculationItem.ClearOutput();
+ changedObservables.Add(calculationItem);
+ }
+ }
+
+ private void ClearFailureMechanismSections(IFailureMechanism failureMechanism)
+ {
+ failureMechanism.ClearAllSections();
+
+ changedObservables.Add(failureMechanism);
+ }
+
+ private void ClearHydraulicBoundaryOutput()
+ {
+ // TODO: WTI-440 - Clear all 'Toetspeil' calculation output
+ //changedObservables.Add(clearedInstance);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineMetaImporter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineMetaImporter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineMetaImporter.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,150 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils.Builders;
+using Core.Common.Utils.Properties;
+using log4net;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.Exceptions;
+using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Imports a and stores in on a ,
+ /// taking data from a shape file containing a poly lines.
+ ///
+ public class ReferenceLineMetaImporter
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineMetaImporter));
+ private string shapeFilePath;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The path to the folder where a shape file should be read.
+ ///
+ /// The is typically
+ /// Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "WTI", "NBPW");.
+ ///
+ /// Thrown when:
+ ///
+ /// - points to an invalid directory.
+ /// - The path does not contain any shape files.
+ ///
+ public ReferenceLineMetaImporter(string folderpath)
+ {
+ ValidateAndConnectTo(folderpath);
+ }
+
+ ///
+ /// Reads and validates the objects from the shape file.
+ ///
+ /// The read objects.
+ /// 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.
+ ///
+ public IEnumerable GetReferenceLineMetas()
+ {
+ ICollection referenceLineMetas = ReferenceLinesMetaReader.ReadReferenceLinesMetas(shapeFilePath);
+
+ ValidateReferenceLineMetas(referenceLineMetas);
+
+ return referenceLineMetas;
+ }
+
+ private void ValidateAndConnectTo(string folderpath)
+ {
+ var files = GetShapeFilesInFolder(folderpath);
+ if (files.Length == 0)
+ {
+ var message = string.Format(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateAndConnectTo_No_shape_file_found_in_folder_0, folderpath);
+ throw new CriticalFileReadException(message);
+ }
+
+ shapeFilePath = files.First();
+ if (files.Length > 1)
+ {
+ log.Warn(string.Format(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateAndConnectTo_Multiple_shape_files_found_FilePath_0_SelectedFilePath_1,
+ Path.GetDirectoryName(shapeFilePath), Path.GetFileName(shapeFilePath)));
+ }
+ }
+
+ private static string[] GetShapeFilesInFolder(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path))
+ {
+ var message = new FileReaderErrorMessageBuilder(path).Build(Resources.Error_Path_must_be_specified);
+ throw new ArgumentException(message);
+ }
+
+ try
+ {
+ return Directory.GetFiles(path, "*.shp");
+ }
+ catch (ArgumentException e)
+ {
+ var message = new FileReaderErrorMessageBuilder(path)
+ .Build(string.Format(Resources.Error_Path_cannot_contain_Characters_0_,
+ string.Join(", ", Path.GetInvalidFileNameChars())));
+ throw new ArgumentException(message, e);
+ }
+ catch (Exception e)
+ {
+ if (e is IOException || e is SecurityException)
+ {
+ var message = string.Format(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateDirectory_Directory_Invalid,
+ path);
+ throw new CriticalFileReadException(message, e);
+ }
+ throw;
+ }
+ }
+
+ private void ValidateReferenceLineMetas(ICollection referenceLineMetas)
+ {
+ if (referenceLineMetas.Any(rlm => string.IsNullOrEmpty(rlm.AssessmentSectionId)))
+ {
+ var message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateReferenceLineMetas_Missing_AssessmentSection_Ids);
+ throw new CriticalFileValidationException(message);
+ }
+
+ var referenceLineMetasCount = referenceLineMetas.Count;
+ var referenceLineMetasDistinctCount = referenceLineMetas.Select(rlm => rlm.AssessmentSectionId).Distinct().Count();
+ if (referenceLineMetasCount != referenceLineMetasDistinctCount)
+ {
+ var message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateReferenceLineMetas_AssessmentSection_Ids_Not_Unique);
+ throw new CriticalFileValidationException(message);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineReader.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineReader.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineReader.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,127 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils;
+using Core.Common.Utils.Builders;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Geometries;
+using Core.Components.Gis.IO.Readers;
+using Ringtoets.Common.Data.AssessmentSection;
+using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources;
+using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
+using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Shapefile reader that reads a based on the line feature in the file.
+ ///
+ public class ReferenceLineReader
+ {
+ ///
+ /// Reads an instance of from a shapefile containing one polyline.
+ ///
+ /// The file path to the shapefile.
+ /// The reference line created from the data in the shapefile.
+ /// When is invalid.
+ /// When either:
+ ///
+ /// - points to a file that does not exist.
+ /// - There isn't exactly 1 polyline in the shapefile.
+ /// - Shapefile contains a multi-polyline.
+ /// - An unexpected error occurred when reading the shapefile.
+ ///
+ ///
+ public ReferenceLine ReadReferenceLine(string shapeFilePath)
+ {
+ FileUtils.ValidateFilePath(shapeFilePath);
+ if (!File.Exists(shapeFilePath))
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(CoreCommonUtilsResources.Error_File_does_not_exist);
+ throw new CriticalFileReadException(message);
+ }
+
+ using (PolylineShapeFileReader lineShapeReader = new PolylineShapeFileReader(shapeFilePath))
+ {
+ MapLineData lineMapData = GetReferenceLineMapData(lineShapeReader, shapeFilePath);
+ return CreateReferenceLine(lineMapData, shapeFilePath);
+ }
+ }
+
+ ///
+ /// Gets the reference line map data.
+ ///
+ /// The line shape reader.
+ /// The shapefile path.
+ /// The map data representing the reference line.
+ ///
+ /// When either:
+ ///
+ /// - There isn't exactly 1 polyline in the shapefile.
+ /// - The shapefile doesn't contains lines.
+ ///
+ ///
+ private static MapLineData GetReferenceLineMapData(PolylineShapeFileReader lineShapeReader, string shapeFilePath)
+ {
+ if (lineShapeReader.GetNumberOfFeatures() != 1)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(RingtoetsCommonIOResources.ReferenceLineReader_File_must_contain_1_polyline);
+ throw new CriticalFileReadException(message);
+ }
+
+ return (MapLineData) lineShapeReader.ReadFeature(RingtoetsCommonDataResources.ReferenceLine_DisplayName);
+ }
+
+ private static ReferenceLine CreateReferenceLine(MapLineData lineMapData, string shapeFilePath)
+ {
+ var lineFeatures = lineMapData.Features.ToArray();
+
+ if (lineFeatures.Length > 1)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(RingtoetsCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
+ throw new CriticalFileReadException(message);
+ }
+
+ var referenceLine = new ReferenceLine();
+ var referenceLineFeature = lineMapData.Features.First();
+ var referenceGeometries = referenceLineFeature.MapGeometries.ToArray();
+
+ if (referenceGeometries.Length > 1)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(RingtoetsCommonIOResources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
+ throw new CriticalFileReadException(message);
+ }
+
+ MapGeometry referenceGeometry = referenceGeometries[0];
+ referenceLine.SetGeometry(referenceGeometry.PointCollections.First().Select(t => new Point2D(t.X, t.Y)));
+ return referenceLine;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineWriter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineWriter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineWriter.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,119 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Features;
+using Core.Components.Gis.Geometries;
+using Core.Components.Gis.IO.Writers;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.Properties;
+using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Shapefile writer that writes a as a line feature.
+ ///
+ public class ReferenceLineWriter
+ {
+ ///
+ /// Writes a as a line feature in a shapefile.
+ ///
+ /// The reference line which is to be written to file.
+ /// The id of the assessment section to which this reference line is associated.
+ /// The path to the shapefile.
+ /// Thrown when ,
+ /// or is null.
+ /// Thrown when
+ /// - is invalid, or
+ /// - is empty or consists of whitespace.
+ ///
+ /// Thrown when the shapefile cannot be written.
+ public void WriteReferenceLine(ReferenceLine referenceLine, string id, string filePath)
+ {
+ if (filePath == null)
+ {
+ throw new ArgumentNullException("filePath");
+ }
+
+ var polyLineShapeFileWriter = new PolylineShapeFileWriter();
+
+ MapLineData mapLineData = CreateMapLineData(referenceLine, id);
+
+ polyLineShapeFileWriter.CopyToFeature(mapLineData);
+
+ polyLineShapeFileWriter.SaveAs(filePath);
+ }
+
+ ///
+ /// Create a new instance of from a reference line and a traject id.
+ ///
+ /// The supplying the geometry information
+ /// for the new object.
+ /// The id of the assessment section to which the reference line is associated.
+ /// A new instance of .
+ /// Thrown when or
+ /// is null.
+ /// Thrown when is empty or consists only of whitespace.
+ private static MapLineData CreateMapLineData(ReferenceLine referenceLine, string id)
+ {
+ if (referenceLine == null)
+ {
+ throw new ArgumentNullException("referenceLine");
+ }
+
+ if (id == null)
+ {
+ throw new ArgumentNullException("id");
+ }
+
+ if (string.IsNullOrWhiteSpace(id))
+ {
+ throw new ArgumentException(Resources.ReferenceLineWriter_CreateMapLineData_Traject_cannot_be_empty, "id");
+ }
+
+ MapGeometry referenceLineGeometry = new MapGeometry(
+ new List>
+ {
+ referenceLine.Points
+ });
+
+ MapFeature mapFeature = new MapFeature(new[]
+ {
+ referenceLineGeometry
+ });
+
+ mapFeature.MetaData.Add(Resources.ReferenceLineWriter_CreateMapLineData_Traject_id, id);
+
+ return new MapLineData(RingtoetsCommonDataResources.ReferenceLine_DisplayName)
+ {
+ Features = new[]
+ {
+ mapFeature
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLinesMetaReader.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLinesMetaReader.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLinesMetaReader.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,237 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils;
+using Core.Common.Utils.Builders;
+using Core.Common.Utils.Properties;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Features;
+using Core.Components.Gis.IO.Readers;
+using Ringtoets.Common.Data.AssessmentSection;
+using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
+
+namespace Ringtoets.Common.IO.ReferenceLines
+{
+ ///
+ /// Shape file reader that reads objects based on the line feature in the file.
+ ///
+ public static class ReferenceLinesMetaReader
+ {
+ private const string assessmentsectionIdAttributeKey = "TRAJECT_ID";
+ private const string signalingValueAttributeKey = "NORM_SW";
+ private const string lowerLimitValueAttributeKey = "NORM_OG";
+
+ ///
+ /// Reads the current features in the shape file into a collection of objects.
+ ///
+ /// The file path to the shape file.
+ /// The created collection of objects.
+ /// Thrown when is invalid.
+ /// Thrown when current feature in the shape file:
+ ///
+ /// - points to a file that does not exist.
+ /// - The shape file does not contain the mandatory attributes.
+ /// - Has an empty attribute.
+ /// - The shape file has non-line geometries in it.
+ ///
+ public static List ReadReferenceLinesMetas(string shapeFilePath)
+ {
+ ValidateFilePath(shapeFilePath);
+
+ using (var reader = OpenPolyLineShapeFile(shapeFilePath))
+ {
+ ValidateExistenceOfRequiredAttributes(reader, shapeFilePath);
+
+ return ReadReferenceLinesMetas(reader);
+ }
+ }
+
+ private static List ReadReferenceLinesMetas(PolylineShapeFileReader reader)
+ {
+ var referenceLinesMetas = new List();
+ ReferenceLineMeta referenceLinesMeta;
+ do
+ {
+ referenceLinesMeta = ReadReferenceLinesMeta(reader);
+ if (referenceLinesMeta != null)
+ {
+ referenceLinesMetas.Add(referenceLinesMeta);
+ }
+ } while (referenceLinesMeta != null);
+
+ return referenceLinesMetas;
+ }
+
+ private static ReferenceLineMeta ReadReferenceLinesMeta(PolylineShapeFileReader reader)
+ {
+ var lineData = ReadMapLineData(reader);
+ return lineData == null ? null : CreateReferenceLineMeta(lineData);
+ }
+
+ ///
+ /// Validates the .
+ ///
+ /// The file path to the shape file.
+ /// Thrown when is invalid.
+ /// Thrown when does not exist.
+ private static void ValidateFilePath(string shapeFilePath)
+ {
+ FileUtils.ValidateFilePath(shapeFilePath);
+ if (!File.Exists(shapeFilePath))
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(Resources.Error_File_does_not_exist);
+ throw new CriticalFileReadException(message);
+ }
+ }
+
+ ///
+ /// Validates the file by checking if all mandatory attributes are present in the shape file.
+ ///
+ /// The opened shape file reader.
+ /// The file path to the shape file.
+ /// Thrown when the shape file lacks one of the mandatory attributes.
+ private static void ValidateExistenceOfRequiredAttributes(PolylineShapeFileReader polylineShapeFileReader, string shapeFilePath)
+ {
+ var missingAttributes = GetMissingAttributes(polylineShapeFileReader);
+ if (missingAttributes.Any())
+ {
+ var message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_0_lacks_required_Attribute_1_,
+ shapeFilePath, string.Join("', '", missingAttributes));
+ throw new CriticalFileReadException(message);
+ }
+ }
+
+ private static IList GetMissingAttributes(PolylineShapeFileReader polylineShapeFileReader)
+ {
+ var list = new List(3);
+ if (!polylineShapeFileReader.HasAttribute(assessmentsectionIdAttributeKey))
+ {
+ list.Add(assessmentsectionIdAttributeKey);
+ }
+ if (!polylineShapeFileReader.HasAttribute(signalingValueAttributeKey))
+ {
+ list.Add(signalingValueAttributeKey);
+ }
+ if (!polylineShapeFileReader.HasAttribute(lowerLimitValueAttributeKey))
+ {
+ list.Add(lowerLimitValueAttributeKey);
+ }
+ return list;
+ }
+
+ ///
+ /// Opens a new to .
+ ///
+ /// Path to the shape file to read.
+ /// A new instance of the class.
+ /// Thrown when is invalid.
+ /// Thrown when:
+ ///
+ /// - points to a file that does not exist.
+ /// - The shape file has non-line geometries in it.
+ ///
+ ///
+ private static PolylineShapeFileReader OpenPolyLineShapeFile(string shapeFilePath)
+ {
+ return new PolylineShapeFileReader(shapeFilePath);
+ }
+
+ private static MapLineData ReadMapLineData(PolylineShapeFileReader polylineShapeFileReader)
+ {
+ return (MapLineData) polylineShapeFileReader.ReadFeature();
+ }
+
+ ///
+ /// Creates a new from the .
+ ///
+ /// The to create a from.
+ /// The newly created .
+ private static ReferenceLineMeta CreateReferenceLineMeta(MapLineData lineData)
+ {
+ var feature = lineData.Features.First();
+
+ string assessmentSectionId = GetAssessmentSectionId(feature);
+ int? signalingValue = ParseNormValue(feature.MetaData[signalingValueAttributeKey]);
+ int? lowerLimitValue = ParseNormValue(feature.MetaData[lowerLimitValueAttributeKey]);
+ IEnumerable geometryPoints = GetSectionGeometry(feature);
+
+ var referenceLineMeta = new ReferenceLineMeta
+ {
+ AssessmentSectionId = assessmentSectionId
+ };
+ if (lowerLimitValue != null)
+ {
+ referenceLineMeta.LowerLimitValue = lowerLimitValue.Value;
+ }
+ if (signalingValue != null)
+ {
+ referenceLineMeta.SignalingValue = signalingValue.Value;
+ }
+ referenceLineMeta.ReferenceLine.SetGeometry(geometryPoints);
+
+ return referenceLineMeta;
+ }
+
+ ///
+ /// Gets the geometry from the .
+ ///
+ /// The to get the geometry from.
+ /// A collection that represents the 's geometry.
+ private static IEnumerable GetSectionGeometry(MapFeature lineFeature)
+ {
+ var mapGeometries = lineFeature.MapGeometries.ToArray();
+ if (mapGeometries.Length != 1)
+ {
+ return Enumerable.Empty();
+ }
+
+ return mapGeometries[0].PointCollections.First().Select(p => new Point2D(p.X, p.Y));
+ }
+
+ private static string GetAssessmentSectionId(MapFeature lineFeature)
+ {
+ return Convert.ToString(lineFeature.MetaData[assessmentsectionIdAttributeKey]);
+ }
+
+ private static int? ParseNormValue(object readObject)
+ {
+ try
+ {
+ return Convert.ToInt32(readObject);
+ }
+ catch (Exception exception)
+ {
+ if (exception is InvalidCastException || exception is FormatException || exception is OverflowException)
+ {
+ return null;
+ }
+ throw;
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -57,19 +57,19 @@
-
-
-
+
+
+
True
True
Resources.resx
-
-
-
+
+
+
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructuresReader.cs
===================================================================
diff -u -r2b46bfdee29662c93c0c7280bb8ed1b523d47ebf -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructuresReader.cs (.../StructuresReader.cs) (revision 2b46bfdee29662c93c0c7280bb8ed1b523d47ebf)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructuresReader.cs (.../StructuresReader.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -47,8 +47,8 @@
/// Initializes a new instance of the class.
///
/// The shape file path.
- /// is invalid.
- ///
+ /// Thrown when is invalid.
+ /// Thrown when:
/// - points to a file that does not exist.
/// - does not only contain point features.
/// - does not contain all of the required attributes.
@@ -69,6 +69,17 @@
}
///
+ /// Gets the number of structures present in the shapefile.
+ ///
+ public int GetStructureCount
+ {
+ get
+ {
+ return pointsShapeFileReader.GetNumberOfFeatures();
+ }
+ }
+
+ ///
/// Retrieve a based on the next point feature in the shapefile.
///
/// Thrown when either:
@@ -79,7 +90,7 @@
/// A based on the next point feature in the shapefile.
public Structure GetNextStructure()
{
- MapPointData mapPointData = (MapPointData)pointsShapeFileReader.ReadFeature();
+ MapPointData mapPointData = (MapPointData) pointsShapeFileReader.ReadFeature();
IDictionary attributes = mapPointData.Features.First().MetaData;
@@ -97,6 +108,11 @@
}
}
+ public void Dispose()
+ {
+ pointsShapeFileReader.Dispose();
+ }
+
private static string GetIdAttributeValue(IDictionary attributes)
{
var attributeIdValue = attributes[idAttributeName] as string;
@@ -114,22 +130,6 @@
}
///
- /// Gets the number of structures present in the shapefile.
- ///
- public int GetStructureCount
- {
- get
- {
- return pointsShapeFileReader.GetNumberOfFeatures();
- }
- }
-
- public void Dispose()
- {
- pointsShapeFileReader.Dispose();
- }
-
- ///
/// Open a shapefile containing structures as point features.
///
/// Shape file path.
@@ -149,7 +149,7 @@
}
catch (CriticalFileReadException e)
{
- if (e.InnerException.GetType() == typeof(ApplicationException))
+ if (e.InnerException is ApplicationException)
{
string message = new FileReaderErrorMessageBuilder(shapeFilePath)
.Build(Resources.PointShapefileReader_File_can_only_contain_points);
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLineExporterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLineImporterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLineMetaImporterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLineReaderTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLineWriterTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4e578730273a943bb02a2861c694a2707c8ef852 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLine/ReferenceLinesMetaReaderTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineExporterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineExporterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineExporterTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,135 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Security.AccessControl;
+using Core.Common.Base.Geometry;
+using Core.Common.Base.IO;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLineExporterTest
+ {
+ [Test]
+ public void ParameteredConstructor_ValidParameters_ExpectedValues()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "test.shp");
+
+ // Call
+ var referenceLineExporter = new ReferenceLineExporter(referenceLine, "anId", filePath);
+
+ // Assert
+ Assert.IsInstanceOf(referenceLineExporter);
+ }
+
+ [Test]
+ public void ParameteredConstructor_NullFilePath_ThrowArgumentException()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+
+ // Call
+ TestDelegate call = () => new ReferenceLineExporter(referenceLine, "anId", null);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void Export_ValidData_ReturnTrue()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "Export_ValidData_ReturnTrue");
+ Directory.CreateDirectory(directoryPath);
+ string filePath = Path.Combine(directoryPath, "test.shp");
+
+ var exporter = new ReferenceLineExporter(referenceLine, "anId", filePath);
+
+ bool isExported;
+ try
+ {
+ // Call
+ isExported = exporter.Export();
+ }
+ finally
+ {
+ Directory.Delete(directoryPath, true);
+ }
+
+ // Assert
+ Assert.IsTrue(isExported);
+ }
+
+ [Test]
+ public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "Export_InvalidDirectoryRights_LogErrorAndReturnFalse");
+ Directory.CreateDirectory(directoryPath);
+ string filePath = Path.Combine(directoryPath, "test.shp");
+
+ var exporter = new ReferenceLineExporter(referenceLine, "anId", filePath);
+
+ try
+ {
+ using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write))
+ {
+ // Call
+ bool isExported = true;
+ Action call = () => isExported = exporter.Export();
+
+ // Assert
+ string expectedMessage = string.Format("Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{0}'.\r\nEr is geen referentielijn geëxporteerd.", filePath);
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
+ Assert.IsFalse(isExported);
+ }
+ }
+ finally
+ {
+ Directory.Delete(directoryPath, true);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,757 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Linq;
+using Core.Common.Base;
+using Core.Common.Base.Geometry;
+using Core.Common.Base.IO;
+using Core.Common.TestUtil;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Forms.PresentationObjects;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLineImporterTest : NUnitFormsAssertTest
+ {
+ [Test]
+ public void Constructor_AssessmentSectionNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new ReferenceLineImporter(null, "");
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("importTarget", paramName);
+ }
+
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var importer = new ReferenceLineImporter(assessmentSection, "");
+
+ // Assert
+ Assert.IsInstanceOf>(importer);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_ContextWithoutReferenceLine_ImportReferenceLineToAssessmentSection()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ // Call
+ bool importSuccesful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(importSuccesful);
+ Assert.IsNotNull(assessmentSection.ReferenceLine);
+ Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray();
+ Assert.AreEqual(803, point2Ds.Length);
+ Assert.AreEqual(193515.719, point2Ds[467].X, 1e-6);
+ Assert.AreEqual(511444.750, point2Ds[467].Y, 1e-6);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_ContextWithoutReferenceLine_GeneratedExpectedProgressMessages()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var expectedProgressMessages = new[]
+ {
+ new ExpectedProgressNotification
+ {
+ Text = "Inlezen referentielijn.", CurrentStep = 1, MaxNrOfSteps = 2
+ },
+ new ExpectedProgressNotification
+ {
+ Text = "Geïmporteerde data toevoegen aan het traject.", CurrentStep = 2, MaxNrOfSteps = 2
+ }
+ };
+ var progressChangedCallCount = 0;
+ var importer = new ReferenceLineImporter(assessmentSection, path)
+ {
+ ProgressChanged = (description, step, steps) =>
+ {
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].Text, description);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].CurrentStep, step);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].MaxNrOfSteps, steps);
+ progressChangedCallCount++;
+ }
+ };
+
+ // Call
+ importer.Import();
+
+ // Assert
+ Assert.AreEqual(expectedProgressMessages.Length, progressChangedCallCount);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_FilePathIsDirectory_CancelImportWithErrorMessage()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.DirectorySeparatorChar.ToString());
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ // Call
+ bool importSuccesful = true;
+ Action call = () => importSuccesful = importer.Import();
+
+ // Assert
+ var expectedMessage = string.Format(@"Fout bij het lezen van bestand '{0}': Bestandspad mag niet verwijzen naar een lege bestandsnaam. ", path) + Environment.NewLine +
+ "Er is geen referentielijn geïmporteerd.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsFalse(importSuccesful);
+ Assert.IsNull(assessmentSection.ReferenceLine);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_ShapefileDoesNotExist_CancelImportWithErrorMessage()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "I_dont_exist");
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ // Call
+ bool importSuccesful = true;
+ Action call = () => importSuccesful = importer.Import();
+
+ // Assert
+ var expectedMessage = string.Format(@"Fout bij het lezen van bestand '{0}': Het bestand bestaat niet. ", path) + Environment.NewLine +
+ "Er is geen referentielijn geïmporteerd.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsFalse(importSuccesful);
+ Assert.IsNull(assessmentSection.ReferenceLine);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToCancel_NoChanges()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.StrictMock();
+ var calculation3 = mocks.StrictMock();
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1
+ });
+
+ var failureMechanism2 = mocks.Stub();
+ failureMechanism2.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation3
+ });
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1,
+ failureMechanism2
+ });
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp");
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+ string messageBoxTitle = null, messageBoxText = null;
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+
+ messageBoxTitle = messageBoxTester.Title;
+ messageBoxText = messageBoxTester.Text;
+
+ messageBoxTester.ClickCancel();
+ };
+
+ // Call
+ bool importSuccesful = importer.Import();
+
+ // Assert
+ Assert.IsFalse(importSuccesful);
+ Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine);
+
+ Assert.AreEqual("Bevestigen", messageBoxTitle);
+ var expectedText = "Als u de referentielijn vervangt, zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd." + Environment.NewLine +
+ Environment.NewLine + "Weet u zeker dat u wilt doorgaan?";
+ Assert.AreEqual(expectedText, messageBoxText);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_ClearDataDependentOnReferenceLine()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.Stub();
+ calculation1.Expect(c => c.ClearOutput());
+ var calculation2 = mocks.Stub();
+ calculation2.Expect(c => c.ClearOutput());
+ var calculation3 = mocks.Stub();
+ calculation3.Expect(c => c.ClearOutput());
+ var calculation4 = mocks.Stub();
+ calculation4.Expect(c => c.ClearOutput());
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Expect(fm => fm.ClearAllSections());
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1,
+ calculation2
+ });
+
+ var failureMechanism2 = mocks.Stub();
+ failureMechanism2.Expect(fm => fm.ClearAllSections());
+ failureMechanism2.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation3,
+ calculation4
+ });
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1,
+ failureMechanism2
+ });
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ string messageBoxTitle = null, messageBoxText = null;
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+
+ messageBoxTitle = messageBoxTester.Title;
+ messageBoxText = messageBoxTester.Text;
+
+ messageBoxTester.ClickOk();
+ };
+
+ // Call
+ bool importSuccesful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(importSuccesful);
+ Assert.AreNotSame(originalReferenceLine, assessmentSection.ReferenceLine);
+ Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray();
+ Assert.AreEqual(803, point2Ds.Length);
+ Assert.AreEqual(198237.375, point2Ds[123].X, 1e-6);
+ Assert.AreEqual(514879.781, point2Ds[123].Y, 1e-6);
+
+ Assert.AreEqual("Bevestigen", messageBoxTitle);
+ var expectedText = "Als u de referentielijn vervangt, zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd." + Environment.NewLine +
+ Environment.NewLine + "Weet u zeker dat u wilt doorgaan?";
+ Assert.AreEqual(expectedText, messageBoxText);
+
+ // TODO: Clear calculated HR
+ mocks.VerifyAll(); // Expect calculation output cleared
+ }
+
+ [Test]
+ public void Import_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_GenerateExpectedProgressMessages()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.Stub();
+ var calculation2 = mocks.Stub();
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Expect(fm => fm.ClearAllSections());
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1,
+ calculation2
+ });
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1
+ });
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var expectedProgressMessages = new[]
+ {
+ new ExpectedProgressNotification
+ {
+ Text = "Inlezen referentielijn.", CurrentStep = 1, MaxNrOfSteps = 4
+ },
+ new ExpectedProgressNotification
+ {
+ Text = "Geïmporteerde data toevoegen aan het traject.", CurrentStep = 2, MaxNrOfSteps = 4
+ },
+ new ExpectedProgressNotification
+ {
+ Text = "Wissen rekenresultaten en vakindelingen van toetsspoor.", CurrentStep = 3, MaxNrOfSteps = 4
+ },
+ new ExpectedProgressNotification
+ {
+ Text = "Verwijderen uitvoer van hydraulische randvoorwaarden.", CurrentStep = 4, MaxNrOfSteps = 4
+ }
+ };
+ var progressChangedCallCount = 0;
+ var importer = new ReferenceLineImporter(assessmentSection, path)
+ {
+ ProgressChanged = (description, step, steps) =>
+ {
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].Text, description);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].CurrentStep, step);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].MaxNrOfSteps, steps);
+ progressChangedCallCount++;
+ }
+ };
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Call
+ importer.Import();
+
+ // Assert
+ Assert.AreEqual(expectedProgressMessages.Length, progressChangedCallCount);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_CancellingImport_ReturnFalseAndNoChanges()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp");
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ importer.Cancel();
+
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Call
+ bool importSuccesful = importer.Import();
+
+ // Assert
+ Assert.IsFalse(importSuccesful);
+ Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Import_CancelImportDuringDialogInteraction_GenerateCancelledLogMessage(bool acceptRemovalOfReferenceLineDependentData)
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp");
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ importer.Cancel();
+
+ var messageBoxTester = new MessageBoxTester(wnd);
+ if (acceptRemovalOfReferenceLineDependentData)
+ {
+ messageBoxTester.ClickOk();
+ }
+ else
+ {
+ messageBoxTester.ClickCancel();
+ }
+ };
+
+ // Call
+ Action call = () => importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Referentielijn importeren afgebroken. Geen data ingelezen.", 1);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_ReusingCancelledImporterForContextWithoutReferenceLine_ImportReferenceLineToAssessmentSection()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+ importer.Cancel();
+
+ // Call
+ bool importSuccesful = importer.Import();
+
+ // Assert
+ Assert.IsTrue(importSuccesful);
+ Assert.IsNotNull(assessmentSection.ReferenceLine);
+ Point2D[] point2Ds = assessmentSection.ReferenceLine.Points.ToArray();
+ Assert.AreEqual(803, point2Ds.Length);
+ Assert.AreEqual(195203.563, point2Ds[321].X, 1e-6);
+ Assert.AreEqual(512826.406, point2Ds[321].Y, 1e-6);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void DoPostImportUpdates_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetContextAndClearedObjects()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.Stub();
+ calculation1.Stub(c => c.ClearOutput());
+ calculation1.Expect(c => c.NotifyObservers());
+ var calculation2 = mocks.Stub();
+ calculation2.Stub(c => c.ClearOutput());
+ calculation2.Expect(c => c.NotifyObservers());
+ var calculation3 = mocks.Stub();
+ calculation3.Stub(c => c.ClearOutput());
+ calculation3.Expect(c => c.NotifyObservers());
+ var calculation4 = mocks.Stub();
+ calculation4.Stub(c => c.ClearOutput());
+ calculation4.Expect(c => c.NotifyObservers());
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Expect(fm => fm.ClearAllSections());
+ failureMechanism1.Expect(fm => fm.NotifyObservers());
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1,
+ calculation2
+ });
+
+ var failureMechanism2 = mocks.Stub();
+ failureMechanism2.Expect(fm => fm.ClearAllSections());
+ failureMechanism2.Expect(fm => fm.NotifyObservers());
+ failureMechanism2.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation3,
+ calculation4
+ });
+
+ var contextObserver = mocks.Stub();
+ contextObserver.Expect(o => o.UpdateObserver());
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1,
+ failureMechanism2
+ });
+ assessmentSection.Expect(section => section.Attach(contextObserver));
+ assessmentSection.Expect(section => section.NotifyObservers()).Do((Action) (() => contextObserver.UpdateObserver()));
+
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var referenceLineContext = new ReferenceLineContext(assessmentSection);
+ referenceLineContext.Attach(contextObserver);
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Precondition
+ Assert.IsTrue(importer.Import());
+
+ // Call
+ importer.DoPostImportUpdates();
+
+ // Assert
+ mocks.VerifyAll(); // Expect NotifyObservers on cleared calculations and context
+ }
+
+ [Test]
+ public void DoPostImportUpdates_AssessmentSectionAlreadyHasReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetContextParent()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var observer = mocks.Stub();
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(Enumerable.Empty());
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Expect(section => section.Attach(observer));
+ assessmentSection.Expect(section => section.NotifyObservers());
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var referenceLineContext = new ReferenceLineContext(assessmentSection);
+ referenceLineContext.WrappedData.Attach(observer);
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Precondition
+ Assert.IsTrue(importer.Import());
+
+ // Call
+ importer.DoPostImportUpdates();
+
+ // Assert
+ mocks.VerifyAll(); // Expect NotifyObservers on context parent
+ }
+
+ [Test]
+ public void DoPostImportUpdates_CancellingImport_DoNotNotifyObservers()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.StrictMock();
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1
+ });
+
+ var contextObserver = mocks.StrictMock();
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1
+ });
+ assessmentSection.Expect(section => section.Attach(contextObserver));
+
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp");
+
+ var referenceLineContext = new ReferenceLineContext(assessmentSection);
+ referenceLineContext.Attach(contextObserver);
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ importer.Cancel();
+
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Precondition
+ Assert.IsFalse(importer.Import());
+
+ // Call
+ importer.DoPostImportUpdates();
+
+ // Assert
+ mocks.VerifyAll(); // Expect no NotifyObserver calls
+ }
+
+ [Test]
+ public void DoPostImportUpdates_ReuseImporterWithAssessmentSectionWithReferenceLineAndAnswerDialogToContinue_NotifyObserversOfTargetContextAndClearedObjects()
+ {
+ // Setup
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var calculation1 = mocks.Stub();
+ calculation1.Stub(c => c.ClearOutput());
+ calculation1.Expect(c => c.NotifyObservers());
+ var calculation2 = mocks.Stub();
+ calculation2.Stub(c => c.ClearOutput());
+ calculation2.Expect(c => c.NotifyObservers());
+ var calculation3 = mocks.Stub();
+ calculation3.Stub(c => c.ClearOutput());
+ calculation3.Expect(c => c.NotifyObservers());
+ var calculation4 = mocks.Stub();
+ calculation4.Stub(c => c.ClearOutput());
+ calculation4.Expect(c => c.NotifyObservers());
+
+ var failureMechanism1 = mocks.Stub();
+ failureMechanism1.Expect(fm => fm.ClearAllSections()).Repeat.Twice();
+ failureMechanism1.Expect(fm => fm.NotifyObservers());
+ failureMechanism1.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation1,
+ calculation2
+ });
+
+ var failureMechanism2 = mocks.Stub();
+ failureMechanism2.Expect(fm => fm.ClearAllSections()).Repeat.Twice();
+ failureMechanism2.Expect(fm => fm.NotifyObservers());
+ failureMechanism2.Stub(fm => fm.Calculations).Return(new[]
+ {
+ calculation3,
+ calculation4
+ });
+
+ var contextObserver = mocks.Stub();
+ contextObserver.Expect(o => o.UpdateObserver());
+
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
+ {
+ failureMechanism1,
+ failureMechanism2
+ });
+ assessmentSection.Expect(section => section.Attach(contextObserver));
+ assessmentSection.Expect(section => section.NotifyObservers()).Do((Action) (() => contextObserver.UpdateObserver()));
+
+ mocks.ReplayAll();
+
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+
+ var referenceLineContext = new ReferenceLineContext(assessmentSection);
+ referenceLineContext.Attach(contextObserver);
+
+ var importer = new ReferenceLineImporter(assessmentSection, path);
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+
+ // Precondition
+ Assert.IsTrue(importer.Import());
+ importer.Cancel();
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var messageBoxTester = new MessageBoxTester(wnd);
+ messageBoxTester.ClickOk();
+ };
+ Assert.IsTrue(importer.Import());
+
+ // Call
+ importer.DoPostImportUpdates();
+
+ // Assert
+ mocks.VerifyAll(); // Expect NotifyObservers on cleared calculations and context
+ }
+
+ private class ExpectedProgressNotification
+ {
+ public string Text { get; set; }
+ public int CurrentStep { get; set; }
+ public int MaxNrOfSteps { get; set; }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineMetaImporterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineMetaImporterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineMetaImporterTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,272 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.Exceptions;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLineMetaImporterTest
+ {
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "ReferenceLineMetaImporter");
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void Constructor_NoFilePath_ThrowsArgumentException(string invalidFilePath)
+ {
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet leeg of ongedefinieerd zijn.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathHasInvalidPathCharacter_ThrowsArgumentException()
+ {
+ // Setup
+ char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+ string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "SomeFolder");
+ string invalidFilePath = validFilePath.Replace("F", invalidFileNameChars[1].ToString());
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet de volgende tekens bevatten: {1}",
+ invalidFilePath, string.Join(", ", invalidFileNameChars));
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathTooLong_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathTooLong = Path.Combine(testDataPath, new string('A', 260));
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(pathTooLong);
+
+ // Assert
+ var expectedExceptionMessage = string.Format("De map met specificaties voor trajecten '{0}' is niet gevonden.",
+ pathTooLong);
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void Constructor_FilePathDoesNotExist_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathToNonExistingFolder = Path.Combine(testDataPath, "I do not exist");
+
+ // Precondition
+ Assert.IsFalse(Directory.Exists(pathToNonExistingFolder));
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(pathToNonExistingFolder);
+
+ // Assert
+ var expectedExceptionMessage = string.Format("De map met specificaties voor trajecten '{0}' is niet gevonden.",
+ pathToNonExistingFolder);
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void Constructor_EmptyFolder_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathToEmptyFolder = Path.Combine(testDataPath, "EmptyFolder");
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(pathToEmptyFolder);
+
+ // Assert
+ var expectedExceptionMessage = string.Format(@"Geen shapebestand om trajecten te specificeren gevonden in de map '{0}'.",
+ pathToEmptyFolder);
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void Constructor_FolderWithTwoShapeFiles_LogsWarningAndTakesFirstShapeFile()
+ {
+ // Setup
+ string pathToFolder = Path.Combine(testDataPath, "TwoShapeFiles");
+
+ // Call
+ Action call = () => new ReferenceLineMetaImporter(pathToFolder);
+
+ // Assert
+ var expectedMessage = string.Format(@"Meerdere shapebestanden gevonden in '{0}'. Het bestand 'NBPW_A.shp' is gebruikt.", pathToFolder);
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
+ }
+
+ [Test]
+ public void GetReferenceLineMetas_InvalidShapeFile_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathToInvalid = Path.Combine(testDataPath, "InvalidShapeFile");
+ ReferenceLineMetaImporter importer = new ReferenceLineMetaImporter(pathToInvalid);
+
+ // Call
+ TestDelegate call = () => importer.GetReferenceLineMetas();
+
+ // Assert
+ var expectedExceptionMessage = string.Format("Het shapebestand '{0}' om trajecten te specificeren moet de attributen 'TRAJECT_ID', 'NORM_SW', en 'NORM_OG' bevatten: {1} niet gevonden.",
+ Path.Combine(pathToInvalid, "InvalidShapeFile.shp"), "'TRAJECT_ID', 'NORM_SW', 'NORM_OG'");
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void GetReferenceLineMetas_FileWithNonUniqueTrajectIds_ThrowsCriticalFileValidationException()
+ {
+ // Setup
+ string pathToFolder = Path.Combine(testDataPath, "NonUniqueTrajectIds");
+ ReferenceLineMetaImporter importer = new ReferenceLineMetaImporter(pathToFolder);
+
+ // Call
+ TestDelegate call = () => importer.GetReferenceLineMetas();
+
+ // Assert
+ var shapeFile = Path.Combine(pathToFolder, "NonUniqueTrajectIds.shp");
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Meerdere trajecten met dezelfde identificatiecode (attribuut 'TRAJECT_ID') gevonden.",
+ shapeFile);
+ CriticalFileValidationException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ [Test]
+ public void GetReferenceLineMetas_FileWithEmptyTrajectIds_ThrowsCriticalFileValidationException()
+ {
+ // Setup
+ string pathToFolder = Path.Combine(testDataPath, "EmptyTrackId");
+ ReferenceLineMetaImporter importer = new ReferenceLineMetaImporter(pathToFolder);
+
+ // Call
+ TestDelegate call = () => importer.GetReferenceLineMetas();
+
+ // Assert
+ var shapeFile = Path.Combine(pathToFolder, "EmptyTrackId.shp");
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Trajecten gevonden zonder een geldige identificatiecode (attribuut 'TRAJECT_ID').", shapeFile);
+ CriticalFileValidationException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ [Test]
+ public void GetReferenceLineMetas_ValidDirectoryWithOneShapeFile_ReturnsReadReadGetReferenceLineMetas()
+ {
+ // Setup
+ string pathValidFolder = Path.Combine(testDataPath, "ValidShapeFile");
+ var importer = new ReferenceLineMetaImporter(pathValidFolder);
+
+ // Call
+ var referenceLineMetas = importer.GetReferenceLineMetas().ToArray();
+
+ // Assert
+ Assert.AreEqual(3, referenceLineMetas.Length);
+
+ var expectedReferenceLineMeta1 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "1-2",
+ LowerLimitValue = 1000,
+ SignalingValue = 3000
+ };
+ expectedReferenceLineMeta1.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(160679.9250, 475072.583),
+ new Point2D(160892.0751, 474315.4917)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta1, referenceLineMetas[0]);
+
+ var expectedReferenceLineMeta2 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "2-1",
+ LowerLimitValue = 100,
+ SignalingValue = 300
+ };
+ expectedReferenceLineMeta2.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(155556.9191, 464341.1281),
+ new Point2D(155521.4761, 464360.7401)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta2, referenceLineMetas[1]);
+
+ var expectedReferenceLineMeta3 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "3-3",
+ LowerLimitValue = 100,
+ SignalingValue = 300
+ };
+ expectedReferenceLineMeta3.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(147367.321899, 476902.9157103),
+ new Point2D(147410.0515, 476938.9447)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta3, referenceLineMetas[2]);
+ }
+
+ [Test]
+ public void GetReferenceLineMetas_EmptyShapeFile_ReturnsEmptyList()
+ {
+ // Setup
+ string pathValidFolder = Path.Combine(testDataPath, "EmptyShapeFile");
+ var importer = new ReferenceLineMetaImporter(pathValidFolder);
+
+ // Call
+ IEnumerable referenceLineMetas = importer.GetReferenceLineMetas();
+
+ // Assert
+ Assert.AreEqual(0, referenceLineMetas.Count());
+ }
+
+ private static void AssertReferenceLineMetas(ReferenceLineMeta expectedReferenceLineMeta, ReferenceLineMeta actualReferenceLineMeta)
+ {
+ Assert.AreEqual(expectedReferenceLineMeta.AssessmentSectionId, actualReferenceLineMeta.AssessmentSectionId);
+ Assert.AreEqual(expectedReferenceLineMeta.SignalingValue, actualReferenceLineMeta.SignalingValue);
+ Assert.AreEqual(expectedReferenceLineMeta.LowerLimitValue, actualReferenceLineMeta.LowerLimitValue);
+
+ Point2D[] expectedPoints = expectedReferenceLineMeta.ReferenceLine.Points.ToArray();
+ Point2D[] actualPoints = actualReferenceLineMeta.ReferenceLine.Points.ToArray();
+ CollectionAssert.AreEqual(expectedPoints, actualPoints,
+ new Point2DComparerWithTolerance(1e-6),
+ string.Format("Unexpected geometry found in ReferenceLineMeta with id '{0}'", actualReferenceLineMeta.AssessmentSectionId));
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineReaderTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineReaderTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineReaderTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,219 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLineReaderTest
+ {
+ [Test]
+ public void ReadReferenceLine_FileHasOneValidLineInShape_ReturnReferenceLine()
+ {
+ // Setup
+ var validReferenceLineShapeFile = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+ var reader = new ReferenceLineReader();
+
+ // Call
+ ReferenceLine referenceLine = reader.ReadReferenceLine(validReferenceLineShapeFile);
+
+ // Assert
+ Point2D[] point2Ds = referenceLine.Points.ToArray();
+ Assert.AreEqual(803, point2Ds.Length);
+ Assert.AreEqual(193527.156, point2Ds[465].X, 1e-6);
+ Assert.AreEqual(511438.281, point2Ds[465].Y, 1e-6);
+ Assert.AreEqual(191144.375, point2Ds[800].X, 1e-6);
+ Assert.AreEqual(508840.469, point2Ds[800].Y, 1e-6);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void ReadReferenceLine_NoFilePath_ThrowArgumentException(string invalidFilePath)
+ {
+ // Setup
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet leeg of ongedefinieerd zijn.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLine_FilePathHasInvalidPathCharacter_ThrowArgumentException()
+ {
+ // Setup
+ char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+ string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "traject_10-1.shp");
+ string invalidFilePath = validFilePath.Replace("_", invalidFileNameChars[3].ToString());
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet de volgende tekens bevatten: {1}",
+ invalidFilePath, string.Join(", ", invalidFileNameChars));
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLine_FilePathIsActuallyDirectoryPath_ThrowArgumentException()
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.DirectorySeparatorChar.ToString());
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet verwijzen naar een lege bestandsnaam.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLine_ShapefileDoesntExist_ThrowCriticalFileReadException()
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "I_do_not_exist.shp");
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ [TestCase("Multiple_Point_with_ID.shp")]
+ [TestCase("Multiple_Polygon_with_ID.shp")]
+ [TestCase("Single_Multi-Polygon_with_ID.shp")]
+ [TestCase("Single_Point_with_ID.shp")]
+ [TestCase("Single_Polygon_with_ID.shp")]
+ public void ReadReferenceLine_ShapefileContainsOtherThanPolyline_ThrowCriticalFileReadException(string shapeFileName)
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
+ shapeFileName);
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Kon geen lijnen vinden in dit bestand.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ [TestCase("Empty_PolyLine_with_ID.shp")]
+ [TestCase("Multiple_PolyLine_with_ID.shp")]
+ public void ReadReferenceLine_ShapefileDoesNotHaveSinglePolyline_ThrowCriticalFileReadException(string shapeFileName)
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
+ shapeFileName);
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand moet exact 1 gehele polylijn bevatten.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ public void ReadReferenceLine_ShapefileHasSingleMultiPolyline_ThrowCriticalFileReadException()
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
+ "Single_Multi-PolyLine_with_ID.shp");
+
+ var reader = new ReferenceLineReader();
+
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bevat een multi-polylijn. Multi-polylijnen worden niet ondersteund.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ public void ReadReferenceLine_FileInUse_ThrowCriticalFileReadException()
+ {
+ // Setup
+ var validReferenceLineShapeFile = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_10-2.shp"));
+ var reader = new ReferenceLineReader();
+
+ using (new FileStream(validReferenceLineShapeFile, FileMode.Open))
+ {
+ // Call
+ TestDelegate call = () => reader.ReadReferenceLine(validReferenceLineShapeFile);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie.",
+ validReferenceLineShapeFile);
+ var exception = Assert.Throws(call);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineWriterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineWriterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineWriterTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,188 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLineWriterTest
+ {
+ [Test]
+ public void WriteReferenceLine_NullReferenceLine_ThrowArgumentNullException()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("WriteReferenceLine_NullReferenceLine_ThrowArgumentNullException",
+ "test.shp"));
+
+ var writer = new ReferenceLineWriter();
+
+ // Call
+ TestDelegate call = () => writer.WriteReferenceLine(null, "anId", filePath);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void WriteReferenceLine_NullId_ThrowArgumentNullException()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("WriteReferenceLine_NullId_ThrowArgumentNullException",
+ "test.shp"));
+
+ var writer = new ReferenceLineWriter();
+
+ // Call
+ TestDelegate call = () => writer.WriteReferenceLine(referenceLine, null, filePath);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(" ")]
+ public void WriteReferenceLine_InvalidId_ThrowArgumentException(string id)
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("WriteReferenceLine_InvalidId_ThrowArgumentException",
+ "test.shp"));
+
+ var writer = new ReferenceLineWriter();
+
+ // Call
+ TestDelegate call = () => writer.WriteReferenceLine(referenceLine, id, filePath);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void WriteReferenceLine_NullFilePath_ThrowArgumentNullException()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ var writer = new ReferenceLineWriter();
+
+ // Call
+ TestDelegate call = () => writer.WriteReferenceLine(referenceLine, "anId", null);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void WriteReferenceLine_ValidData_WritesShapeFile()
+ {
+ // Setup
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(1.1, 2.2),
+ new Point2D(11.11, 22.22)
+ });
+
+ string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "WriteReferenceLine_ValidData_WritesShapeFile");
+ Directory.CreateDirectory(directoryPath);
+ string filePath = Path.Combine(directoryPath, "test.shp");
+ var baseName = "test";
+
+ var writer = new ReferenceLineWriter();
+
+ // Precondition
+ AssertEssentialShapefileExists(directoryPath, baseName, false);
+
+ // Call
+ try
+ {
+ writer.WriteReferenceLine(referenceLine, "anId", filePath);
+
+ // Assert
+ AssertEssentialShapefileExists(directoryPath, baseName, true);
+ AssertEssentialShapefileMd5Hashes(directoryPath, baseName);
+ }
+ finally
+ {
+ Directory.Delete(directoryPath, true);
+ }
+ }
+
+ private static void AssertEssentialShapefileExists(string directoryPath, string baseName, bool shouldExist)
+ {
+ string pathName = Path.Combine(directoryPath, baseName);
+ Assert.AreEqual(shouldExist, File.Exists(pathName + ".shp"));
+ Assert.AreEqual(shouldExist, File.Exists(pathName + ".shx"));
+ Assert.AreEqual(shouldExist, File.Exists(pathName + ".dbf"));
+ }
+
+ private void AssertEssentialShapefileMd5Hashes(string directoryPath, string baseName)
+ {
+ string refPathName = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO), "LineShapefileMd5");
+ string pathName = Path.Combine(directoryPath, baseName);
+
+ AssertBinaryFileContent(refPathName, pathName, ".shp", 100, 88);
+ AssertBinaryFileContent(refPathName, pathName, ".shx", 100, 8);
+ AssertBinaryFileContent(refPathName, pathName, ".dbf", 32, 289);
+ }
+
+ private static void AssertBinaryFileContent(string refPathName, string pathName, string extension, int headerLength, int bodyLength)
+ {
+ var refContent = File.ReadAllBytes(refPathName + extension);
+ var content = File.ReadAllBytes(pathName + extension);
+ Assert.AreEqual(headerLength + bodyLength, content.Length);
+ Assert.AreEqual(refContent.Skip(headerLength).Take(bodyLength),
+ content.Skip(headerLength).Take(bodyLength));
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLinesMetaReaderTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLinesMetaReaderTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLinesMetaReaderTest.cs (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -0,0 +1,275 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Core.Common.Base.Geometry;
+using Core.Common.IO.Exceptions;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.IO.ReferenceLines;
+
+namespace Ringtoets.Common.IO.Test.ReferenceLines
+{
+ [TestFixture]
+ public class ReferenceLinesMetaReaderTest
+ {
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "NBPW");
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void ReadReferenceLinesMetas_NoFilePath_ThrowArgumentException(string invalidFilePath)
+ {
+ // Call
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet leeg of ongedefinieerd zijn.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMetas_FilePathHasInvalidPathCharacter_ThrowArgumentException()
+ {
+ // Setup
+ char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+ string validFilePath = Path.Combine(testDataPath, "NBPW.shp");
+ string invalidFilePath = validFilePath.Replace("P", invalidFileNameChars[1].ToString());
+
+ // Call
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet de volgende tekens bevatten: {1}",
+ invalidFilePath, string.Join(", ", invalidFileNameChars));
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMetas_FilePathIsActuallyDirectoryPath_ThrowArgumentException()
+ {
+ // Setup
+ string invalidFilePath = Path.Combine(testDataPath, Path.DirectorySeparatorChar.ToString());
+
+ // Call
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet verwijzen naar een lege bestandsnaam.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMetas_ShapefileDoesntExist_ThrowCriticalFileReadException()
+ {
+ // Setup
+ string invalidFilePath = Path.Combine(testDataPath, "I_do_not_exist.shp");
+
+ // Call
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ [TestCase("Multiple_Point_with_ID.shp")]
+ [TestCase("Multiple_Polygon_with_ID.shp")]
+ [TestCase("Single_Multi-Polygon_with_ID.shp")]
+ [TestCase("Single_Point_with_ID.shp")]
+ [TestCase("Single_Polygon_with_ID.shp")]
+ public void ReadReferenceLinesMetas_ShapefileDoesNotHaveSinglePolyline_ThrowCriticalFileReadException(string shapeFileName)
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, shapeFileName);
+
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert .
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Kon geen lijnen vinden in dit bestand.",
+ invalidFilePath);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ [TestCase("NBPW_MultiPolyLines.shp")]
+ public void ReadReferenceLinesMeta_ShapefileHasMultiplePolylines_ReturnsEmptyReferenceLines(string shapeFileName)
+ {
+ // Setup
+ string invalidFilePath = Path.Combine(testDataPath, shapeFileName);
+
+ // Call
+ var referenceLineMetas = ReferenceLinesMetaReader.ReadReferenceLinesMetas(invalidFilePath);
+
+ // Assert
+ Assert.AreEqual(2, referenceLineMetas.Count);
+ CollectionAssert.IsEmpty(referenceLineMetas[0].ReferenceLine.Points);
+ CollectionAssert.IsEmpty(referenceLineMetas[1].ReferenceLine.Points);
+ }
+
+ [Test]
+ [TestCase("NBPW_missingTrajectId.shp", "TRAJECT_ID")]
+ [TestCase("NBPW_missingNORM_SW.shp", "NORM_SW")]
+ [TestCase("NBPW_missingNORM_OG.shp", "NORM_OG")]
+ public void ReadReferenceLinesMetas_FileLacksAttribute_ThrowCriticalFileReadException(string shapeFileName, string missingAttribute)
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, shapeFileName);
+
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(validFilePath);
+
+ // Assert
+ var message = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Het shapebestand '{0}' om trajecten te specificeren moet de attributen 'TRAJECT_ID', 'NORM_SW', en 'NORM_OG' bevatten: '{1}' niet gevonden.", validFilePath,
+ missingAttribute);
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ [TestCase("NBPW_missingAllAttributes.shp", "TRAJECT_ID', 'NORM_SW', 'NORM_OG")]
+ [TestCase("NBPW_missingTrajectIdAndNORM_SW.shp", "TRAJECT_ID', 'NORM_SW")]
+ [TestCase("NBPW_missingTrajectIdAndNORM_OG.shp", "TRAJECT_ID', 'NORM_OG")]
+ [TestCase("NBPW_missingNORM_SWAndNORM_OG.shp", "NORM_SW', 'NORM_OG")]
+ public void ReadReferenceLinesMetas_FileLacksAttributes_ThrowCriticalFileReadException(string shapeFileName, string missingAttributes)
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, shapeFileName);
+
+ TestDelegate call = () => ReferenceLinesMetaReader.ReadReferenceLinesMetas(validFilePath);
+
+ // Assert
+ var message = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Het shapebestand '{0}' om trajecten te specificeren moet de attributen 'TRAJECT_ID', 'NORM_SW', en 'NORM_OG' bevatten: '{1}' niet gevonden.", validFilePath,
+ missingAttributes);
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMeta_ValidFilePath_ReturnsElement()
+ {
+ // Setup
+ var validFilePath = Path.Combine(testDataPath, "NBPW.shp");
+
+ // Call
+ List referenceLineMetas = ReferenceLinesMetaReader.ReadReferenceLinesMetas(validFilePath);
+
+ // Assert
+ Assert.AreEqual(3, referenceLineMetas.Count);
+
+ var expectedReferenceLineMeta1 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "1-1",
+ LowerLimitValue = 1000,
+ SignalingValue = 3000
+ };
+ expectedReferenceLineMeta1.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(160679.9250, 475072.583),
+ new Point2D(160892.0751, 474315.4917)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta1, referenceLineMetas[0]);
+
+ var expectedReferenceLineMeta2 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "2-2",
+ LowerLimitValue = 100,
+ SignalingValue = 300
+ };
+ expectedReferenceLineMeta2.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(155556.9191, 464341.1281),
+ new Point2D(155521.4761, 464360.7401)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta2, referenceLineMetas[1]);
+
+ var expectedReferenceLineMeta3 = new ReferenceLineMeta
+ {
+ AssessmentSectionId = "3-3",
+ LowerLimitValue = 100,
+ SignalingValue = 300
+ };
+ expectedReferenceLineMeta3.ReferenceLine.SetGeometry(new[]
+ {
+ new Point2D(147367.321899, 476902.9157103),
+ new Point2D(147410.0515, 476938.9447)
+ });
+ AssertReferenceLineMetas(expectedReferenceLineMeta3, referenceLineMetas[2]);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMeta_EmptyNormOgAndNormSw_ReturnsElement()
+ {
+ // Setup
+ var validFilePath = Path.Combine(testDataPath, "NBPW_EmptyNormOGAndNormSW.shp");
+
+ // Call
+ List referenceLineMetas = ReferenceLinesMetaReader.ReadReferenceLinesMetas(validFilePath);
+
+ // Assert
+ Assert.AreEqual(1, referenceLineMetas.Count);
+
+ var referenceLineMeta = referenceLineMetas.First();
+ Assert.AreEqual("46-1", referenceLineMeta.AssessmentSectionId);
+ Assert.IsNull(referenceLineMeta.SignalingValue);
+ Assert.IsNull(referenceLineMeta.LowerLimitValue);
+ }
+
+ [Test]
+ public void ReadReferenceLinesMeta_EmptyTrackId_ReturnsElement()
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, "NBPW_EmptyTrackId.shp");
+
+ // Call
+ List referenceLineMetas = ReferenceLinesMetaReader.ReadReferenceLinesMetas(validFilePath);
+
+ // Assert
+ Assert.AreEqual(1, referenceLineMetas.Count);
+ var referenceLineMeta = referenceLineMetas.First();
+ Assert.AreEqual(string.Empty, referenceLineMeta.AssessmentSectionId);
+ }
+
+ private static void AssertReferenceLineMetas(ReferenceLineMeta expectedReferenceLineMeta, ReferenceLineMeta actualReferenceLineMeta)
+ {
+ Assert.AreEqual(expectedReferenceLineMeta.AssessmentSectionId, actualReferenceLineMeta.AssessmentSectionId);
+ Assert.AreEqual(expectedReferenceLineMeta.SignalingValue, actualReferenceLineMeta.SignalingValue);
+ Assert.AreEqual(expectedReferenceLineMeta.LowerLimitValue, actualReferenceLineMeta.LowerLimitValue);
+
+ Point2D[] expectedPoints = expectedReferenceLineMeta.ReferenceLine.Points.ToArray();
+ Point2D[] actualPoints = actualReferenceLineMeta.ReferenceLine.Points.ToArray();
+ CollectionAssert.AreEqual(expectedPoints, actualPoints,
+ new Point2DComparerWithTolerance(1e-6),
+ string.Format("Unexpected geometry found in ReferenceLineMeta with id '{0}'", actualReferenceLineMeta.AssessmentSectionId));
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -60,14 +60,14 @@
-
-
-
+
+
+
-
-
-
+
+
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructuresReaderTest.cs
===================================================================
diff -u -ref2f43d435fcb82be2c0724db07178b401adf0fc -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructuresReaderTest.cs (.../StructuresReaderTest.cs) (revision ef2f43d435fcb82be2c0724db07178b401adf0fc)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructuresReaderTest.cs (.../StructuresReaderTest.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -147,7 +147,7 @@
TestDelegate call = () => new StructuresReader(invalidFilePath);
// Assert
- var expectedMessage = string.Format("Het bestand heeft geen attribuut '{0}'. Dit attribuut is vereist.",
+ var expectedMessage = string.Format("Het bestand heeft geen attribuut '{0}'. Dit attribuut is vereist.",
"KWKIDENT");
string message = Assert.Throws(call).Message;
Assert.AreEqual(expectedMessage, message);
@@ -191,7 +191,6 @@
}
}
-
[Test]
public void GetNextStructure_ShapefileWithoutAttributeKWKNAAM_NamesEqualAttributeKWKIDENT()
{
@@ -254,7 +253,6 @@
// Setup
string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
Path.Combine("Structures", "StructuresWithNullKWKIDENT", "Kunstwerken.shp"));
-
using (var reader = new StructuresReader(validFilePath))
{
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/IntegrationTestHelper.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -24,7 +24,7 @@
using Core.Common.Utils.IO;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Plugin.FileImporters;
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Commands/AssessmentSectionFromFileCommandHandler.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Commands/AssessmentSectionFromFileCommandHandler.cs (.../AssessmentSectionFromFileCommandHandler.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Commands/AssessmentSectionFromFileCommandHandler.cs (.../AssessmentSectionFromFileCommandHandler.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -31,7 +31,7 @@
using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.IO;
using Ringtoets.Common.IO.Exceptions;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Forms.Properties;
using IntegrationResources = Ringtoets.Integration.Data.Properties.Resources;
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs
===================================================================
diff -u -rae14c5d4e4624fa87390e6d63bb419c648e12dda -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision ae14c5d4e4624fa87390e6d63bb419c648e12dda)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -50,7 +50,7 @@
using Ringtoets.Common.Forms.TreeNodeInfos;
using Ringtoets.Common.Forms.Views;
using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionOutwards.Data;
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ExportInfos/ReferenceLineContextExportInfoTest.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ExportInfos/ReferenceLineContextExportInfoTest.cs (.../ReferenceLineContextExportInfoTest.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ExportInfos/ReferenceLineContextExportInfoTest.cs (.../ReferenceLineContextExportInfoTest.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -25,8 +25,7 @@
using NUnit.Framework;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Forms.PresentationObjects;
-using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Plugin;
using RingtoetsCommonIoResources = Ringtoets.Common.IO.Properties.Resources;
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -31,8 +31,7 @@
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
-using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Integration.Plugin.FileImporters;
using RingtoetsCommonIoResources = Ringtoets.Common.IO.Properties.Resources;
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/FailureMechanismSectionsContextImportInfoTest.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/FailureMechanismSectionsContextImportInfoTest.cs (.../FailureMechanismSectionsContextImportInfoTest.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/FailureMechanismSectionsContextImportInfoTest.cs (.../FailureMechanismSectionsContextImportInfoTest.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -33,8 +33,7 @@
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Forms.PresentationObjects;
-using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.Integration.Plugin.Test.ImportInfos
Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs
===================================================================
diff -u -rc4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec -r4e578730273a943bb02a2861c694a2707c8ef852
--- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision c4712d739e9e7bcb62b21cdf1592b3ed0a74a7ec)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/IntegrationTestHelper.cs (.../IntegrationTestHelper.cs) (revision 4e578730273a943bb02a2861c694a2707c8ef852)
@@ -23,8 +23,7 @@
using Core.Common.Base.Service;
using Core.Common.Utils.IO;
using Ringtoets.Common.Data.FailureMechanism;
-using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.ReferenceLine;
+using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Plugin.FileImporters;
using Ringtoets.Piping.Plugin.FileImporter;