Index: Core/Common/src/Core.Common.Base/Geometry/Math2D.cs =================================================================== diff -u -re65a7b987f40cd17a68b43e6a7f267e91588fc4b -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision e65a7b987f40cd17a68b43e6a7f267e91588fc4b) +++ Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -215,6 +215,29 @@ return intersectionPointY; } + /// + /// Creates an enumerator that converts a sequence of line points to a sequence of line segments. + /// + /// The points to convert. + /// A sequence of N elements, where N is the number of elements in + /// - 1, or 0 if only has one or no elements. + public static IEnumerable Convert3DPointsToLineSegments(IEnumerable linePoints) + { + var points = new Collection(); + + foreach (var point in linePoints) + { + points.Add(Convert3DPointTo2DPoint(point)); + } + + return ConvertLinePointsToLineSegments(points); + } + + private static Point2D Convert3DPointTo2DPoint(Point3D point) + { + return new Point2D(point.X, point.Y); + } + private static bool Intersects(Point2D point1, Point2D point2, Point2D point3, Point2D point4, out double result) { var aLine = (point1.Y - point3.Y)*(point4.X - point3.X) - (point1.X - point3.X)*(point4.Y - point3.Y); Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -152,6 +152,54 @@ } /// + /// Looks up a localized string similar to Profielmeting {0} komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd.. + /// + public static string PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__does_not_correspond_to_current_referenceline { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__doe" + + "s_not_correspond_to_current_referenceline", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Profielmeting {0} komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd. {1}. + /// + public static string PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__does_not_correspond_to_current_referenceline__1__ { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__doe" + + "s_not_correspond_to_current_referenceline__1__", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Dit kan komen doordat de profielmeting een lokaal coordinaat systeem heeft.. + /// + public static string PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_This_could_be_caused_coordinates_being_local_coordinate_system { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_This_could_be_cause" + + "d_coordinates_being_local_coordinate_system", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} Er zijn geen profielmetingen geïmporteerd.. + /// + public static string PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_No_sections_imported { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_No_sections_imported", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er is geen referentielijn beschikbaar om profielmetingen voor te definiëren.. + /// + public static string PipingSurfaceLinesCsvImporter_Import_Required_referenceline_missing { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_Import_Required_referenceline_missing", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Project. /// public static string Project_Constructor_Default_name { Index: Core/Common/src/Core.Common.Base/Properties/Resources.resx =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -165,4 +165,19 @@ De tekst is een getal dat te groot of te klein is om gerepresenteerd te worden. + + Profielmeting {0} komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd. + + + Profielmeting {0} komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd. {1} + + + Dit kan komen doordat de profielmeting een lokaal coordinaat systeem heeft. + + + {0} Er zijn geen profielmetingen geïmporteerd. + + + Er is geen referentielijn beschikbaar om profielmetingen voor te definiëren. + \ No newline at end of file Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs =================================================================== diff -u -rc0a3ced404197fd781c6fcbcfc21c6676592be57 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs (.../AddNewDemoDikeAssessmentSectionCommand.cs) (revision c0a3ced404197fd781c6fcbcfc21c6676592be57) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDikeAssessmentSectionCommand.cs (.../AddNewDemoDikeAssessmentSectionCommand.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -5,6 +5,7 @@ using Core.Common.Controls.Commands; using Core.Common.Gui; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.IO; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; @@ -65,10 +66,10 @@ private void InitializeDemoReferenceLine(DikeAssessmentSection demoAssessmentSection) { - using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_10-1.shp", "traject_10-1.dbf", "traject_10-1.prj", "traject_10-1.shx")) + using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_6-3.shp", "traject_6-3.dbf", "traject_6-3.prj", "traject_6-3.shx")) { var importer = new ReferenceLineImporter(); - importer.Import(new ReferenceLineContext(demoAssessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_10-1.shp")); + importer.Import(new ReferenceLineContext(demoAssessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3.shp")); } } @@ -86,13 +87,13 @@ private void InitializeDemoFailureMechanismSections(DikeAssessmentSection demoAssessmentSection) { - using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_10-1_vakken.shp", "traject_10-1_vakken.dbf", "traject_10-1_vakken.prj", "traject_10-1_vakken.shx")) + using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_6-3_vakken.shp", "traject_6-3_vakken.dbf", "traject_6-3_vakken.prj", "traject_6-3_vakken.shx")) { var importer = new FailureMechanismSectionsImporter(); foreach (var failureMechanism in demoAssessmentSection.GetFailureMechanisms()) { var context = new FailureMechanismSectionsContext(failureMechanism, demoAssessmentSection); - importer.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_10-1_vakken.shp")); + importer.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3_vakken.shp")); } } } Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDuneAssessmentSectionCommand.cs =================================================================== diff -u -r17d804ad06fdd113f028986d979450b016469a09 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDuneAssessmentSectionCommand.cs (.../AddNewDemoDuneAssessmentSectionCommand.cs) (revision 17d804ad06fdd113f028986d979450b016469a09) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoDuneAssessmentSectionCommand.cs (.../AddNewDemoDuneAssessmentSectionCommand.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -3,6 +3,7 @@ using Core.Common.Gui; using Ringtoets.Common.Data; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.IO; using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin.FileImporters; @@ -58,10 +59,10 @@ private void InitializeDemoReferenceLine(DuneAssessmentSection demoAssessmentSection) { - using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_10-1.shp", "traject_10-1.dbf", "traject_10-1.prj", "traject_10-1.shx")) + using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_6-3.shp", "traject_6-3.dbf", "traject_6-3.prj", "traject_6-3.shx")) { var importer = new ReferenceLineImporter(); - importer.Import(new ReferenceLineContext(demoAssessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_10-1.shp")); + importer.Import(new ReferenceLineContext(demoAssessmentSection), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3.shp")); } } @@ -79,13 +80,13 @@ private void InitializeDemoFailureMechanismSections(DuneAssessmentSection demoAssessmentSection) { - using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_10-1_vakken.shp", "traject_10-1_vakken.dbf", "traject_10-1_vakken.prj", "traject_10-1_vakken.shx")) + using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(true, "traject_6-3_vakken.shp", "traject_6-3_vakken.dbf", "traject_6-3_vakken.prj", "traject_6-3_vakken.shx")) { var importer = new FailureMechanismSectionsImporter(); foreach (IFailureMechanism failureMechanism in demoAssessmentSection.GetFailureMechanisms()) { var context = new FailureMechanismSectionsContext(failureMechanism, demoAssessmentSection); - importer.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_10-1_vakken.shp")); + importer.Import(context, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3_vakken.shp")); } } } Index: Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj =================================================================== diff -u -r17d804ad06fdd113f028986d979450b016469a09 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj (.../Demo.Ringtoets.csproj) (revision 17d804ad06fdd113f028986d979450b016469a09) +++ Demo/Ringtoets/src/Demo.Ringtoets/Demo.Ringtoets.csproj (.../Demo.Ringtoets.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -100,6 +100,7 @@ {318ba582-88c9-4816-a54a-a7e431461de3} Core.Components.Gis + False {d4200f43-3f72-4f42-af0a-8ced416a38ec} @@ -109,10 +110,17 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + False + + {52ba7627-cbab-4209-be77-3b5f31378277} + Ringtoets.Common.IO + False + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} Ringtoets.HydraRing.Data + False {11f1f874-45af-43e4-8ae5-15a5c9593e28} @@ -122,10 +130,12 @@ {ad0cdc89-0a00-4068-aeec-9838863c2fe8} Ringtoets.Integration.Forms + False {c8383b76-b3f1-4e6e-b56c-527b469fa20a} Ringtoets.Integration.Plugin + False {ce994cc9-6f6a-48ac-b4be-02c30a21f4db} @@ -135,6 +145,7 @@ {7cd038e1-e111-4969-aced-22c5bd2974e1} Ringtoets.Piping.Forms + False {1d3d58b6-ef7e-401e-92a0-104067d222ee} @@ -145,14 +156,14 @@ - - - - - - - - + + + + + + + + Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_10-1.dbf =================================================================== diff -u -rad2d65c5904706727b1e19341a8b1162645c845a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 Binary files differ Fisheye: Tag b79e419a1fcdf3d80760ea4bc35ac354525911d2 refers to a dead (removed) revision in file `Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_10-1.prj'. Fisheye: No comparison available. Pass `N' to diff? Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_10-1.shp =================================================================== diff -u -rad2d65c5904706727b1e19341a8b1162645c845a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_10-1.shx =================================================================== diff -u -rad2d65c5904706727b1e19341a8b1162645c845a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.dbf =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.prj =================================================================== diff -u --- Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.prj (revision 0) +++ Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.prj (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1 @@ +PROJCS["RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Double_Stereographic"],PARAMETER["False_Easting",155000.0],PARAMETER["False_Northing",463000.0],PARAMETER["Central_Meridian",5.38763888888889],PARAMETER["Scale_Factor",0.9999079],PARAMETER["Latitude_Of_Origin",52.15616055555555],UNIT["Meter",1.0]] \ No newline at end of file Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.shp =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3.shx =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.dbf =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.prj =================================================================== diff -u --- Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.prj (revision 0) +++ Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.prj (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1 @@ +PROJCS["RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Double_Stereographic"],PARAMETER["False_Easting",155000.0],PARAMETER["False_Northing",463000.0],PARAMETER["Central_Meridian",5.38763888888889],PARAMETER["Scale_Factor",0.9999079],PARAMETER["Latitude_Of_Origin",52.15616055555555],UNIT["Meter",1.0]] \ No newline at end of file Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.shp =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/src/Demo.Ringtoets/Resources/traject_6-3_vakken.shx =================================================================== diff -u Binary files differ Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs =================================================================== diff -u -rc0a3ced404197fd781c6fcbcfc21c6676592be57 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs (.../AddNewDemoDikeAssessmentSectionCommandTest.cs) (revision c0a3ced404197fd781c6fcbcfc21c6676592be57) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs (.../AddNewDemoDikeAssessmentSectionCommandTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -73,7 +73,7 @@ Assert.AreEqual(18, hydraulicBoundaryLocations.Length); AssertValuesOnHydraulicBoundaryLocations(hydraulicBoundaryLocations); - Assert.AreEqual(1669, demoAssessmentSection.ReferenceLine.Points.Count()); + Assert.AreEqual(2380, demoAssessmentSection.ReferenceLine.Points.Count()); var profiles = demoAssessmentSection.PipingFailureMechanism.SoilProfiles.ToArray(); Assert.AreEqual(4, profiles.Length); @@ -87,7 +87,7 @@ foreach (var failureMechanism in demoAssessmentSection.GetFailureMechanisms()) { - Assert.AreEqual(130, failureMechanism.Sections.Count()); + Assert.AreEqual(283, failureMechanism.Sections.Count()); } mocks.VerifyAll(); } Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDuneAssessmentSectionCommandTest.cs =================================================================== diff -u -rcc5634a5fa164bbb2f7ef4546c9a2e60f19e4b1a -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDuneAssessmentSectionCommandTest.cs (.../AddNewDemoDuneAssessmentSectionCommandTest.cs) (revision cc5634a5fa164bbb2f7ef4546c9a2e60f19e4b1a) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDuneAssessmentSectionCommandTest.cs (.../AddNewDemoDuneAssessmentSectionCommandTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -59,7 +59,7 @@ var demoAssessmentSection = (DuneAssessmentSection) project.Items[0]; Assert.AreEqual("Demo duintraject", demoAssessmentSection.Name); - Assert.AreEqual(1669, demoAssessmentSection.ReferenceLine.Points.Count()); + Assert.AreEqual(2380, demoAssessmentSection.ReferenceLine.Points.Count()); Assert.IsNotEmpty(demoAssessmentSection.HydraulicBoundaryDatabase.FilePath); Assert.IsTrue(File.Exists(demoAssessmentSection.HydraulicBoundaryDatabase.FilePath)); @@ -69,7 +69,7 @@ foreach (var failureMechanism in demoAssessmentSection.GetFailureMechanisms()) { - Assert.AreEqual(130, failureMechanism.Sections.Count()); + Assert.AreEqual(283, failureMechanism.Sections.Count()); } mocks.VerifyAll(); Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Demo.Ringtoets.Test.csproj =================================================================== diff -u -r98fc85d8cecf9edae9fe7c1f2f47b60ecda5e187 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Demo.Ringtoets.Test.csproj (.../Demo.Ringtoets.Test.csproj) (revision 98fc85d8cecf9edae9fe7c1f2f47b60ecda5e187) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Demo.Ringtoets.Test.csproj (.../Demo.Ringtoets.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -93,6 +93,10 @@ {11f1f874-45af-43e4-8ae5-15a5c9593e28} Ringtoets.Integration.Data + + {c8383b76-b3f1-4e6e-b56c-527b469fa20a} + Ringtoets.Integration.Plugin + {d64e4f0e-e341-496f-82b2-941ad202b4e3} Ringtoets.Piping.Calculation Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/ReferenceLineContext.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/ReferenceLineContext.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/ReferenceLineContext.cs (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1,103 @@ +// 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; +using Ringtoets.Common.Data; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.PresentationObjects +{ + /// + /// Presentation object for instances. + /// + public class ReferenceLineContext : Observable, IEquatable + { + /// + /// Initializes a new instance of the class. + /// + /// The parent owner of the data represented by the presentation object. + /// Thrown when is null. + public ReferenceLineContext(AssessmentSectionBase parent) + { + if (parent == null) + { + throw new ArgumentNullException("parent", Resources.ReferenceLineContext_Parent_assessment_section_cannot_be_null); + } + Parent = parent; + } + + /// + /// The reference line data wrapped by this presentation object. + /// + public ReferenceLine WrappedData + { + get + { + return Parent.ReferenceLine; + } + } + + /// + /// The assessment section owning . + /// + public AssessmentSectionBase Parent { get; private set; } + + #region Implementation: IEquatable + + public bool Equals(ReferenceLineContext other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + if (ReferenceEquals(this, other)) + { + return true; + } + return Parent.Equals(other.Parent); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((ReferenceLineContext)obj); + } + + public override int GetHashCode() + { + return Parent.GetHashCode(); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -ra10f78cf8ff03594c931cbcc227c6f7008a5154c -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a10f78cf8ff03594c931cbcc227c6f7008a5154c) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -258,6 +258,25 @@ } /// + /// Looks up a localized string similar to Kan geen presentatie object maken voor een referentielijn zonder een traject als eigenaar.. + /// + public static string ReferenceLineContext_Parent_assessment_section_cannot_be_null { + get { + return ResourceManager.GetString("ReferenceLineContext_Parent_assessment_section_cannot_be_null", resourceCulture); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap ReferenceLineIcon { + get { + object obj = ResourceManager.GetObject("ReferenceLineIcon", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// /// Looks up a localized string similar to Algemeen. /// public static string Ringtoets_Category { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -ra10f78cf8ff03594c931cbcc227c6f7008a5154c -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision a10f78cf8ff03594c931cbcc227c6f7008a5154c) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -205,4 +205,10 @@ Vakindeling + + Kan geen presentatie object maken voor een referentielijn zonder een traject als eigenaar. + + + ..\Resources\chart_single_line.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Resources/chart_single_line.png =================================================================== diff -u Binary files differ Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r76ace4042e4e8a92a0ba37e8e9a9373ed6cea951 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 76ace4042e4e8a92a0ba37e8e9a9373ed6cea951) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -48,6 +48,7 @@ Code + @@ -67,6 +68,7 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + False {1d27f91f-4e62-4eaf-a0a8-a32708b9a9b1} @@ -96,6 +98,7 @@ {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + False @@ -123,6 +126,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r5e80369138024933a45f3e4ae721509dfb17d8fb -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 5e80369138024933a45f3e4ae721509dfb17d8fb) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -88,6 +88,76 @@ } /// + /// Looks up a localized string similar to Als u de referentielijn vervangt zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_data_when_performed { + get { + return ResourceManager.GetString("ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_dat" + + "a_when_performed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} + ///Er is geen referentielijn geïmporteerd.. + /// + internal static string ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported { + get { + return ResourceManager.GetString("ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_import" + + "ed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Geïmporteerde data toevoegen aan het traject.. + /// + internal static string ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsection { + get { + return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsec" + + "tion", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Referentielijn importeren afgebroken. Geen data ingelezen.. + /// + internal static string ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read { + get { + return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inlezen referentielijn.. + /// + internal static string ReferenceLineImporter_ProgressText_Reading_referenceline { + get { + return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Reading_referenceline", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wissen rekenresultaten en vakindelingen van faalmechanismen.. + /// + internal static string ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechanism_sections { + get { + return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechan" + + "ism_sections", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Verwijderen uitvoer van hydraulische randvoorwaarden.. + /// + internal static string ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output { + get { + return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het bestand bevat 1 multi-polylijn, welke niet ondersteund is.. /// internal static string ReferenceLineReader_File_contains_unsupported_multi_polyline { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -rc96faf42eae37d9b6ad63d7ed0250b7fef11bef8 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision c96faf42eae37d9b6ad63d7ed0250b7fef11bef8) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -132,4 +132,28 @@ Het bestand heeft een of meerdere multi-polylijnen, welke niet ondersteund worden. + + Als u de referentielijn vervangt zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd. + +Weet u zeker dat u wilt doorgaan? + + + {0} +Er is geen referentielijn geïmporteerd. + + + Geïmporteerde data toevoegen aan het traject. + + + Referentielijn importeren afgebroken. Geen data ingelezen. + + + Inlezen referentielijn. + + + Wissen rekenresultaten en vakindelingen van faalmechanismen. + + + Verwijderen uitvoer van hydraulische randvoorwaarden. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineImporter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineImporter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineImporter.cs (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1,239 @@ +// 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.Drawing; +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; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.IO.Properties; +using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; +using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsDataResources = Ringtoets.Common.Data.Properties.Resources; + +namespace Ringtoets.Common.IO +{ + /// + /// 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(); + + public override string Name + { + get + { + return RingtoetsDataResources.ReferenceLine_DisplayName; + } + } + + public override string Category + { + get + { + return RingtoetsFormsResources.Ringtoets_Category; + } + } + + public override Bitmap Image + { + get + { + return RingtoetsFormsResources.ReferenceLineIcon; + } + } + + public override string FileFilter + { + get + { + return String.Format("{0} shapefile (*.shp)|*.shp", + RingtoetsDataResources.ReferenceLine_DisplayName); + } + } + + public override ProgressChangedDelegate ProgressChanged { protected get; set; } + + public override bool Import(object targetItem, string filePath) + { + ImportIsCancelled = false; + changedObservables.Clear(); + + bool clearReferenceLineDependentData = false; + + var importTarget = (ReferenceLineContext)targetItem; + if (importTarget.Parent.ReferenceLine != null) + { + clearReferenceLineDependentData = ConfirmImportOfReferenceLineToClearReferenceLineDependentData(importTarget.Parent); + } + + if (ImportIsCancelled) + { + HandleUserCancellingImport(); + return false; + } + + NotifyProgress(Resources.ReferenceLineImporter_ProgressText_Reading_referenceline, + 1, clearReferenceLineDependentData ? 4 : 2); + ReadResult readResult = ReadReferenceLine(filePath); + if (readResult.CriticalErrorOccurred) + { + return false; + } + + if (ImportIsCancelled) + { + HandleUserCancellingImport(); + return false; + } + + AddReferenceLineToDataModel(importTarget.Parent, readResult.ImportedItems.First(), clearReferenceLineDependentData); + return true; + } + + protected override IEnumerable GetAffectedNonTargetObservableInstances() + { + return changedObservables; + } + + private bool ConfirmImportOfReferenceLineToClearReferenceLineDependentData(AssessmentSectionBase assessmentSection) + { + var clearReferenceLineDependentData = false; + + DialogResult result = MessageBox.Show(Resources.ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_data_when_performed, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + if (result == DialogResult.Cancel) + { + ImportIsCancelled = true; + } + else + { + if (assessmentSection.GetFailureMechanisms() != null) + { + clearReferenceLineDependentData = true; + } + } + + return clearReferenceLineDependentData; + } + + private static void HandleUserCancellingImport() + { + log.Info(Resources.ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read); + } + + private ReadResult ReadReferenceLine(string filePath) + { + 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((string) Resources.ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported, + e.Message); + log.Error(errorMessage); + return new ReadResult(true); + } + + private void AddReferenceLineToDataModel(AssessmentSectionBase assessmentSection, ReferenceLine importedReferenceLine, bool clearReferenceLineDependentData) + { + NotifyProgress(Resources.ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsection, + 2, clearReferenceLineDependentData ? 4 : 2); + assessmentSection.ReferenceLine = importedReferenceLine; + + changedObservables.Add(assessmentSection); // Note: Add assessmentSection to the list of changed observables. Otherwise only the reference line context item will only be notified. + + if (clearReferenceLineDependentData && assessmentSection.GetFailureMechanisms() != null) + { + ClearReferenceLineDependentData(assessmentSection); + } + } + + private void ClearReferenceLineDependentData(AssessmentSectionBase assessmentSection) + { + NotifyProgress(Resources.ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechanism_sections, + 3, 4); + foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) + { + ClearCalculationOutput(failureMechanism); + ClearFailureMechanismSections(failureMechanism); + } + NotifyProgress(Resources.ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output, + 4, 4); + ClearHydraulicBoundaryOutput(assessmentSection); + } + + private void ClearCalculationOutput(IFailureMechanism failureMechanism) + { + foreach (var calculationItem in failureMechanism.CalculationItems) + { + calculationItem.ClearOutput(); + changedObservables.Add(calculationItem); + } + } + + private void ClearFailureMechanismSections(IFailureMechanism failureMechanism) + { + failureMechanism.ClearAllSections(); + + var observableFailureMechanism = failureMechanism as IObservable; + if (observableFailureMechanism != null) + { + changedObservables.Add(observableFailureMechanism); + } + } + + private void ClearHydraulicBoundaryOutput(AssessmentSectionBase assessmentSection) + { + // TODO: WTI-360 - Clear all 'Toetspeil' calculation output + //changedObservables.Add(clearedInstance); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r5e80369138024933a45f3e4ae721509dfb17d8fb -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 5e80369138024933a45f3e4ae721509dfb17d8fb) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -34,8 +34,14 @@ AllRules.ruleset + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + + + @@ -48,42 +54,56 @@ True Resources.resx + Copying.licenseheader + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + False {e344867e-9ac9-44c8-88a5-8185681679a9} Core.Common.IO + False {f49bd8b2-332a-4c91-a196-8cce0a2c7d98} Core.Common.Utils + False {c90b77da-e421-43cc-b82e-529651bc21ac} Core.Common.Version + False {fd264fad-e6f9-47cc-97cd-770199a8e629} Core.Components.Gis.IO + False {318ba582-88c9-4816-a54a-a7e431461de3} Core.Components.Gis + False {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + False + + {4d840673-3812-4338-a352-84854e32b8a0} + Ringtoets.Common.Forms + False + Index: Ringtoets/Common/src/Ringtoets.Common.IO/packages.config =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/packages.config (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/packages.config (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/ReferenceLineContextTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/ReferenceLineContextTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/ReferenceLineContextTest.cs (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1,127 @@ +using System; +using Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Forms.PresentationObjects; + +namespace Ringtoets.Common.Forms.Test.PresentationObjects +{ + [TestFixture] + public class ReferenceLineContextTest + { + [Test] + public void ParameteredConstructor_ExpectedValues() + { + // Setup + var referenceLine = new ReferenceLine(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = referenceLine; + mocks.ReplayAll(); + + // Call + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + // Assert + Assert.IsInstanceOf(referenceLineContext); + Assert.IsInstanceOf>(referenceLineContext); + Assert.AreSame(referenceLine, referenceLineContext.WrappedData); + Assert.AreSame(assessmentSection, referenceLineContext.Parent); + mocks.VerifyAll(); + } + + [Test] + public void ParameteredConstructor_AssessmentSectionIsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new ReferenceLineContext(null); + + // Assert + string expectedMessage = "Kan geen presentatie object maken voor een referentielijn zonder een traject als eigenaar."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void Equals_ContextObjectsHaveSameParent_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context1 = new ReferenceLineContext(assessmentSection); + var context2 = new ReferenceLineContext(assessmentSection); + + // Call + var contextsAreEqual1 = context1.Equals(context2); + var contextsAreEqual2 = context2.Equals(context1); + + // Assert + Assert.IsTrue(contextsAreEqual1); + Assert.IsTrue(contextsAreEqual2); + mocks.VerifyAll(); + } + + [Test] + public void Equals_TwoContextsWithDifferentParents_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection1 = mocks.Stub(); + var assessmentSection2 = mocks.Stub(); + mocks.ReplayAll(); + + var context1 = new ReferenceLineContext(assessmentSection1); + var context2 = new ReferenceLineContext(assessmentSection2); + + // Call + var contextsAreEqual1 = context1.Equals(context2); + var contextsAreEqual2 = context2.Equals(context1); + + // Assert + Assert.IsFalse(contextsAreEqual1); + Assert.IsFalse(contextsAreEqual2); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ComparingToItself_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new ReferenceLineContext(assessmentSection); + + // Call + var isEqual = context.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ComparingToNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new ReferenceLineContext(assessmentSection); + + // Call + var isEqual = context.Equals(null); + + // Assert + Assert.IsFalse(isEqual); + mocks.VerifyAll(); + } + } + +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r76ace4042e4e8a92a0ba37e8e9a9373ed6cea951 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 76ace4042e4e8a92a0ba37e8e9a9373ed6cea951) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -58,6 +58,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineImporterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineImporterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineImporterTest.cs (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -0,0 +1,710 @@ +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; +using Ringtoets.Common.Forms.PresentationObjects; +using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Common.IO.Test +{ + [TestFixture] + public class ReferenceLineImporterTest : NUnitFormsAssertTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Call + var importer = new ReferenceLineImporter(); + + // Assert + Assert.IsInstanceOf>(importer); + Assert.AreEqual("Referentielijn", importer.Name); + Assert.AreEqual("Algemeen", importer.Category); + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.ReferenceLineIcon, importer.Image); + Assert.AreEqual("Referentielijn shapefile (*.shp)|*.shp", importer.FileFilter); + } + + [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, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + // Call + bool importSuccesful = importer.Import(referenceLineContext, path); + + // Assert + Assert.IsTrue(importSuccesful); + Assert.IsInstanceOf(assessmentSection.ReferenceLine); + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + Point2D[] point2Ds = Enumerable.ToArray(assessmentSection.ReferenceLine.Points); + 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, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + 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 + { + 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(referenceLineContext, path); + + // 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 referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + // Call + bool importSuccesful = true; + Action call = () => importSuccesful = importer.Import(referenceLineContext, path); + + // Assert + var expectedMessage = string.Format(@"Fout bij het lezen van bestand '{0}': Bestandspad mag niet naar een map verwijzen. ", path) + Environment.NewLine + + "Er is geen referentielijn geïmporteerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsFalse(importSuccesful); + Assert.IsNull(assessmentSection.ReferenceLine); + Assert.IsNull(referenceLineContext.WrappedData); + 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 referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + // Call + bool importSuccesful = true; + Action call = () => importSuccesful = importer.Import(referenceLineContext, path); + + // 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); + Assert.IsNull(referenceLineContext.WrappedData); + 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.CalculationItems).Return(new[] + { + calculation1, + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Stub(fm => fm.CalculationItems).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 referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + 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(referenceLineContext, path); + + // Assert + Assert.IsFalse(importSuccesful); + Assert.AreSame(originalReferenceLine, assessmentSection.ReferenceLine); + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + + 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.CalculationItems).Return(new[] + { + calculation1, + calculation2 + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Expect(fm => fm.ClearAllSections()); + failureMechanism2.Stub(fm => fm.CalculationItems).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, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + 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(referenceLineContext, path); + + // Assert + Assert.IsTrue(importSuccesful); + Assert.AreNotSame(originalReferenceLine, assessmentSection.ReferenceLine); + Point2D[] point2Ds = Enumerable.ToArray(assessmentSection.ReferenceLine.Points); + 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.CalculationItems).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, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + 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 faalmechanismen.", CurrentStep = 3, MaxNrOfSteps = 4 }, + new ExpectedProgressNotification { Text = "Verwijderen uitvoer van hydraulische randvoorwaarden.", CurrentStep = 4, MaxNrOfSteps = 4 }, + }; + var progressChangedCallCount = 0; + var importer = new ReferenceLineImporter(); + importer.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(referenceLineContext, path); + + // 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 referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + DialogBoxHandler = (name, wnd) => + { + importer.Cancel(); + + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Call + bool importSuccesful = importer.Import(referenceLineContext, path); + + // 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 referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + + DialogBoxHandler = (name, wnd) => + { + importer.Cancel(); + + var messageBoxTester = new MessageBoxTester(wnd); + if (acceptRemovalOfReferenceLineDependentData) + { + messageBoxTester.ClickOk(); + } + else + { + messageBoxTester.ClickCancel(); + } + }; + + // Call + Action call = () => importer.Import(referenceLineContext, path); + + // 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, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var importer = new ReferenceLineImporter(); + importer.Cancel(); + + // Call + bool importSuccesful = importer.Import(referenceLineContext, path); + + // Assert + Assert.IsTrue(importSuccesful); + Assert.IsInstanceOf(assessmentSection.ReferenceLine); + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + Point2D[] point2Ds = Enumerable.ToArray(assessmentSection.ReferenceLine.Points); + 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.CalculationItems).Return(new[] + { + calculation1, + calculation2 + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Expect(fm => fm.ClearAllSections()); + failureMechanism2.Expect(fm => fm.NotifyObservers()); + failureMechanism2.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation3, + calculation4 + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1, + failureMechanism2 + }); + + var contextObserver = mocks.Stub(); + contextObserver.Expect(o => o.UpdateObserver()); + 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(); + + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Precondition + Assert.IsTrue(importer.Import(referenceLineContext, path)); + + // Call + importer.DoPostImportUpdates(referenceLineContext); + + // 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 assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + referenceLineContext.Parent.Attach(observer); + + var importer = new ReferenceLineImporter(); + + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Precondition + Assert.IsTrue(importer.Import(referenceLineContext, path)); + + // Call + importer.DoPostImportUpdates(referenceLineContext); + + // 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.CalculationItems).Return(new[] + { + calculation1 + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1 + }); + + var contextObserver = mocks.StrictMock(); + 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(); + + DialogBoxHandler = (name, wnd) => + { + importer.Cancel(); + + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Precondition + Assert.IsFalse(importer.Import(referenceLineContext, path)); + + // Call + importer.DoPostImportUpdates(referenceLineContext); + + // 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.CalculationItems).Return(new[] + { + calculation1, + calculation2 + }); + + var failureMechanism2 = mocks.Stub(); + failureMechanism2.Expect(fm => fm.ClearAllSections()).Repeat.Twice(); + failureMechanism2.Expect(fm => fm.NotifyObservers()); + failureMechanism2.Stub(fm => fm.CalculationItems).Return(new[] + { + calculation3, + calculation4 + }); + + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = originalReferenceLine; + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism1, + failureMechanism2 + }); + + var contextObserver = mocks.Stub(); + contextObserver.Expect(o => o.UpdateObserver()); + 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(); + + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + + // Precondition + Assert.IsTrue(importer.Import(referenceLineContext, path)); + importer.Cancel(); + DialogBoxHandler = (name, wnd) => + { + var messageBoxTester = new MessageBoxTester(wnd); + messageBoxTester.ClickOk(); + }; + Assert.IsTrue(importer.Import(referenceLineContext, path)); + + // Call + importer.DoPostImportUpdates(referenceLineContext); + + // 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/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r428f61c9f1c755c69ea1ff2745e38c1864dad558 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 428f61c9f1c755c69ea1ff2745e38c1864dad558) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -37,12 +37,21 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\lib\NUnitForms.dll + + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + True + + + @@ -62,6 +71,10 @@ {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + + {4d840673-3812-4338-a352-84854e32b8a0} + Ringtoets.Common.Forms + {52ba7627-cbab-4209-be77-3b5f31378277} Ringtoets.Common.IO Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/packages.config =================================================================== diff -u -ra96a27081bc12d581a196160abc92854a11ec1c6 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/packages.config (.../packages.config) (revision a96a27081bc12d581a196160abc92854a11ec1c6) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/packages.config (.../packages.config) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -1,4 +1,5 @@  + \ No newline at end of file Fisheye: Tag b79e419a1fcdf3d80760ea4bc35ac354525911d2 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/ReferenceLineContext.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r252605cde31dfde56c723feb0cf14b8597d12430 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 252605cde31dfde56c723feb0cf14b8597d12430) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -376,25 +376,6 @@ } /// - /// Looks up a localized string similar to Kan geen presentatie object maken voor een referentielijn zonder een traject als eigenaar.. - /// - public static string ReferenceLineContext_Parent_assessment_section_cannot_be_null { - get { - return ResourceManager.GetString("ReferenceLineContext_Parent_assessment_section_cannot_be_null", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - public static System.Drawing.Bitmap ReferenceLineIcon { - get { - object obj = ResourceManager.GetObject("ReferenceLineIcon", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// /// Looks up a localized string similar to Database op pad '{0}' gekoppeld.. /// public static string RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path_0_linked { Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx =================================================================== diff -u -r252605cde31dfde56c723feb0cf14b8597d12430 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 252605cde31dfde56c723feb0cf14b8597d12430) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -145,12 +145,6 @@ Duintraject - - ..\Resources\chart_single_line.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - Kan geen presentatie object maken voor een referentielijn zonder een traject als eigenaar. - Trajectkaart Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r86e717a5477d55d1c4351f2857a1d76e220a3ab4 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 86e717a5477d55d1c4351f2857a1d76e220a3ab4) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -45,7 +45,6 @@ - True Fisheye: Tag b79e419a1fcdf3d80760ea4bc35ac354525911d2 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r8a952205c0aa9c6bdc64a721f44a8d145758904b -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8a952205c0aa9c6bdc64a721f44a8d145758904b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -181,76 +181,6 @@ } /// - /// Looks up a localized string similar to Als u de referentielijn vervangt zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd. - /// - ///Weet u zeker dat u wilt doorgaan?. - /// - public static string ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_data_when_performed { - get { - return ResourceManager.GetString("ReferenceLineImporter_ConfirmImport_Confirm_referenceline_import_which_clears_dat" + - "a_when_performed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} - ///Er is geen referentielijn geïmporteerd.. - /// - public static string ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_imported { - get { - return ResourceManager.GetString("ReferenceLineImporter_HandleCriticalFileReadError_Error_0_no_referenceline_import" + - "ed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Geïmporteerde data toevoegen aan het traject.. - /// - public static string ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsection { - get { - return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Adding_imported_referenceline_to_assessmentsec" + - "tion", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Referentielijn importeren afgebroken. Geen data ingelezen.. - /// - public static string ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read { - get { - return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Inlezen referentielijn.. - /// - public static string ReferenceLineImporter_ProgressText_Reading_referenceline { - get { - return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Reading_referenceline", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Wissen rekenresultaten en vakindelingen van faalmechanismen.. - /// - public static string ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechanism_sections { - get { - return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Removing_calculation_output_and_failure_mechan" + - "ism_sections", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Verwijderen uitvoer van hydraulische randvoorwaarden.. - /// - public static string ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output { - get { - return ResourceManager.GetString("ReferenceLineImporter_ProgressText_Removing_hydraulic_boundary_output", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Toetspeil berekenen voor locatie '{0}'. /// public static string RingtoetsGuiPlugin_Calculate_assessment_level_for_location_0_ { Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -r8a952205c0aa9c6bdc64a721f44a8d145758904b -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 8a952205c0aa9c6bdc64a721f44a8d145758904b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -117,30 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - {0} -Er is geen referentielijn geïmporteerd. - - - Als u de referentielijn vervangt zullen alle vakindelingen, berekende hydraulische randvoorwaarden en berekeningsresultaten worden verwijderd. - -Weet u zeker dat u wilt doorgaan? - - - Referentielijn importeren afgebroken. Geen data ingelezen. - - - Inlezen referentielijn. - - - Geïmporteerde data toevoegen aan het traject. - - - Wissen rekenresultaten en vakindelingen van faalmechanismen. - - - Verwijderen uitvoer van hydraulische randvoorwaarden. - Er is nog geen bestand geopend. Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj =================================================================== diff -u -r3a78d46ff29f71c0de1e46381ea3aed557903eec -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 3a78d46ff29f71c0de1e46381ea3aed557903eec) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -57,7 +57,6 @@ - True Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs =================================================================== diff -u -rd066b31047707b6fb1453bd83a65fe773b5838cb -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision d066b31047707b6fb1453bd83a65fe773b5838cb) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -27,6 +27,7 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.IO; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.FileImporters; Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -rc78424bb1212d0cb8a4ce7a20aeeb05c370b0631 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision c78424bb1212d0cb8a4ce7a20aeeb05c370b0631) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -142,7 +142,7 @@ yield return new TreeNodeInfo { Text = context => RingtoetsCommonDataResources.ReferenceLine_DisplayName, - Image = context => RingtoetsFormsResources.ReferenceLineIcon, + Image = context => RingtoetsCommonFormsResources.ReferenceLineIcon, ForeColor = context => context.WrappedData == null ? Color.FromKnownColor(KnownColor.GrayText) : Color.FromKnownColor(KnownColor.ControlText), Fisheye: Tag b79e419a1fcdf3d80760ea4bc35ac354525911d2 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PresentationObjects/ReferenceLineContextTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r86e717a5477d55d1c4351f2857a1d76e220a3ab4 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 86e717a5477d55d1c4351f2857a1d76e220a3ab4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -61,7 +61,6 @@ - Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs =================================================================== diff -u -r7144ed9829e56a34e064267053216ffbcf6cff52 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs (.../AssessmentSectionBaseTreeNodeInfoTest.cs) (revision 7144ed9829e56a34e064267053216ffbcf6cff52) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs (.../AssessmentSectionBaseTreeNodeInfoTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -10,6 +10,7 @@ using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs =================================================================== diff -u -r249fd5e4604012895724a9d7df67201332c9e7dc -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs (.../ReferenceLineContextTreeNodeInfoTest.cs) (revision 249fd5e4604012895724a9d7df67201332c9e7dc) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs (.../ReferenceLineContextTreeNodeInfoTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -11,11 +11,11 @@ using Rhino.Mocks; using Ringtoets.Common.Data; -using Ringtoets.Integration.Data; -using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos { @@ -95,7 +95,7 @@ var image = info.Image(referenceLineContext); // Assert - TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.ReferenceLineIcon, image); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ReferenceLineIcon, image); mocks.VerifyAll(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs =================================================================== diff -u -r48e23a0db064d6796bce79b3cbc520c597f27441 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 48e23a0db064d6796bce79b3cbc520c597f27441) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -13,7 +13,7 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Forms.PresentationObjects; -using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Common.IO; using Ringtoets.Integration.Plugin.FileImporters; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; Fisheye: Tag b79e419a1fcdf3d80760ea4bc35ac354525911d2 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ReferenceLineImporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r86e717a5477d55d1c4351f2857a1d76e220a3ab4 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 86e717a5477d55d1c4351f2857a1d76e220a3ab4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -48,9 +48,6 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True - - ..\..\..\..\lib\NUnitForms.dll - @@ -67,7 +64,6 @@ - @@ -114,6 +110,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {52ba7627-cbab-4209-be77-3b5f31378277} + Ringtoets.Common.IO + {E38C11E0-4384-44DD-9F5B-EE73D79FD7F5} Ringtoets.Common.Placeholder Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs =================================================================== diff -u -rd066b31047707b6fb1453bd83a65fe773b5838cb -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision d066b31047707b6fb1453bd83a65fe773b5838cb) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -6,6 +6,7 @@ using NUnit.Framework; using Ringtoets.Common.Data; +using Ringtoets.Common.IO; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.FileImporters; Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r6a1df79cc36617a42d0016f9b7a9271020a2196e -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 6a1df79cc36617a42d0016f9b7a9271020a2196e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -27,11 +27,12 @@ using Core.Common.Base.Geometry; using Core.Common.Base.IO; +using Core.Common.Base.Properties; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using log4net; -using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Data; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.IO.SurfaceLines; @@ -89,10 +90,21 @@ public override ProgressChangedDelegate ProgressChanged { protected get; set; } + public override bool CanImportOn(object targetItem) + { + return base.CanImportOn(targetItem) && IsReferenceLineAvailable(targetItem); + } + public override bool Import(object targetItem, string filePath) { var targetObject = (RingtoetsPipingSurfaceLineContext) targetItem; + if (!IsReferenceLineAvailable(targetItem)) + { + LogCriticalFileReadError(Resources.PipingSurfaceLinesCsvImporter_Import_Required_referenceline_missing); + return false; + } + var importSurfaceLinesResult = ReadPipingSurfaceLines(filePath); if (importSurfaceLinesResult.CriticalErrorOccurred) { @@ -122,13 +134,25 @@ return true; } + private static bool IsReferenceLineAvailable(object targetItem) + { + return ((RingtoetsPipingSurfaceLineContext)targetItem).AssessmentSection.ReferenceLine != null; + } + private ReadResult HandleCriticalReadError(Exception e) { log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); return new ReadResult(true); } + private void LogCriticalFileReadError(string message) + { + var errorMessage = String.Format(Resources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_No_sections_imported, + message); + log.Error(errorMessage); + } + private void AddImportedDataToModel(RingtoetsPipingSurfaceLineContext target, ICollection readSurfaceLines, ICollection readCharacteristicPointsLocations) { NotifyProgress(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model, readSurfaceLines.Count, readSurfaceLines.Count); @@ -137,6 +161,11 @@ List readCharacteristicPointsLocationNames = readCharacteristicPointsLocations.Select(cpl => cpl.Name).ToList(); foreach (var readSurfaceLine in readSurfaceLines) { + if (!CheckReferenceLineInterSections(readSurfaceLine, target.AssessmentSection.ReferenceLine)) + { + continue; + } + CharacteristicPoints characteristicPoints = readCharacteristicPointsLocations.FirstOrDefault(cpl => cpl.Name == readSurfaceLine.Name); if (characteristicPoints != null) { @@ -157,6 +186,32 @@ } } + private bool CheckReferenceLineInterSections(RingtoetsPipingSurfaceLine readSurfaceLine, ReferenceLine referenceLine) + { + var surfaceLineSegments = Math2D.Convert3DPointsToLineSegments(readSurfaceLine.Points); + var referenceLineSegments = Math2D.ConvertLinePointsToLineSegments(referenceLine.Points); + + var intersections = Math2D.SegmentsIntersectionsWithSegments(referenceLineSegments, surfaceLineSegments).ToList(); + + if (intersections.Count == 1) + { + return true; + } + + if (intersections.Count == 0) + { + log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__does_not_correspond_to_current_referenceline__1__, + readSurfaceLine.Name, + Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_This_could_be_caused_coordinates_being_local_coordinate_system); + } + else if (intersections.Count > 1) + { + log.ErrorFormat(Resources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline__0__does_not_correspond_to_current_referenceline, readSurfaceLine.Name); + } + + return false; + } + private static void SetCharacteristicPointsOnSurfaceLine(RingtoetsPipingSurfaceLine readSurfaceLine, CharacteristicPoints characteristicPointsLocation) { readSurfaceLine.TrySetDitchPolderSide(characteristicPointsLocation.DitchPolderSide); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs =================================================================== diff -u -r6a1df79cc36617a42d0016f9b7a9271020a2196e -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 6a1df79cc36617a42d0016f9b7a9271020a2196e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -25,11 +25,18 @@ public class PipingSurfaceLinesCsvImporterTest { private readonly string ioTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "SurfaceLines"); - private readonly string pluginTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.Plugin, "SurfaceLines"); + private readonly string pluginSurfaceLinesTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.Plugin, "SurfaceLines"); private readonly string krpFormat = "{0}.krp.csv"; private readonly string surfaceLineFormat = "{0}.csv"; + private ReferenceLine GetReferenceLine() + { + var referenceLine = new ReferenceLine(); + + return referenceLine; + } + [Test] public void DefaultConstructor_ExpectedValues() { @@ -48,6 +55,78 @@ } [Test] + public void CanImportOn_ValidContextWithReferenceLine_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var targetContext = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Call + var canImport = importer.CanImportOn(targetContext); + + // Assert + Assert.IsTrue(canImport); + mocks.VerifyAll(); + } + + [Test] + public void CanImportOn_ValidContextWithoutReferenceLine_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = null; + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var targetContext = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Call + var canImport = importer.CanImportOn(targetContext); + + // Assert + Assert.IsFalse(canImport); + mocks.VerifyAll(); + } + + [Test] + public void Import_NoReferenceLine_CancelImportWithErrorMessage() + { + // Setup + var twovalidsurfacelinesCsv = "TwoValidSurfaceLines.csv"; + string validFilePath = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); + + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Call + bool importSuccessful = true; + Action call = () => importSuccessful = importer.Import(context, validFilePath); + + // Assert + var expectedMessage = "Er is geen referentielijn beschikbaar om profielmetingen voor te definiëren. Er zijn geen profielmetingen geïmporteerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsFalse(importSuccessful); + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); + mocks.VerifyAll(); + } + + [Test] public void Import_ImportingToValidTargetWithValidFile_ImportSurfaceLinesToCollection() { // Setup @@ -58,6 +137,15 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new [] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -100,12 +188,12 @@ // Sample some of the imported data: var firstSurfaceLine = importTargetArray[0]; Assert.AreEqual("Rotterdam1", firstSurfaceLine.Name); - Assert.AreEqual(8, firstSurfaceLine.Points.Count()); + Assert.AreEqual(8, firstSurfaceLine.Points.Length); Assert.AreEqual(427776.654093, firstSurfaceLine.StartingWorldPoint.Y); var secondSurfaceLine = importTargetArray[1]; Assert.AreEqual("ArtifcialLocal", secondSurfaceLine.Name); - Assert.AreEqual(3, secondSurfaceLine.Points.Count()); + Assert.AreEqual(3, secondSurfaceLine.Points.Length); Assert.AreEqual(5.7, secondSurfaceLine.EndingWorldPoint.X); Assert.AreEqual(4, callCount); @@ -125,7 +213,15 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(94270, 427700), + new Point2D(94270, 427850), + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); @@ -180,6 +276,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -217,6 +314,15 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -254,6 +360,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -288,6 +395,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -321,6 +429,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -356,6 +465,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -395,6 +505,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -438,12 +549,20 @@ { // Setup var fileName = "TwoValidSurfaceLines_DuplicateIdentifier"; - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string expectedCharacteristicPointsFile = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string expectedCharacteristicPointsFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new [] + { + new Point2D(94270, 427700), + new Point2D(94270, 427900) + }); + assessmentSection.ReferenceLine = referenceLine; + var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -484,6 +603,15 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(94270, 427700), + new Point2D(94270, 427900), + new Point2D(9.8, -1), + new Point2D(9.8, 1) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -534,6 +662,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -582,6 +711,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -629,6 +759,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -667,6 +798,15 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -698,12 +838,13 @@ { // Setup const string fileName = "TwoValidSurfaceLines_EmptyCharacteristicPoints"; - string surfaceLineFile = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLineFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -741,12 +882,13 @@ { // Setup const string fileName = "TwoValidSurfaceLines_InvalidHeaderCharacteristicPoints"; - string surfaceLineFile = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLineFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -789,8 +931,8 @@ var copyTargetPath = string.Format(surfaceLineFormat, target); var copyCharacteristicPointsTargetPath = string.Format(krpFormat, target); - string surfaceLines = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, source)); - string validFilePath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, source)); + string surfaceLines = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, source)); + string validFilePath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, source)); File.Copy(surfaceLines, copyTargetPath); File.Copy(validFilePath, copyCharacteristicPointsTargetPath); @@ -799,6 +941,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -856,12 +999,21 @@ { // Setup const string fileName = "TwoValidSurfaceLines_DuplicateIdentifiersCharacteristicPoints"; - string surfaceLineFile = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLineFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -899,12 +1051,21 @@ { // Setup const string fileName = "TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints"; - string surfaceLineFile = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLineFile = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -952,12 +1113,21 @@ { // Setup const string fileName = "TwoValidSurfaceLines_WithOneCharacteristicPointsLocation"; - string surfaceLines = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLines = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -999,12 +1169,21 @@ { // Setup const string fileName = "TwoValidSurfaceLines_WithThreeCharacteristicPointsLocations"; - string surfaceLines = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLines = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -1054,12 +1233,21 @@ public void Import_FileWithTwoValidLinesAndCharacteristicPointNotOnGeometry_LogInvalidPointDefinition(string fileName, string characteristicPointName) { // Setup - string surfaceLines = Path.Combine(pluginTestDataPath, string.Format(surfaceLineFormat, fileName)); - string corruptPath = Path.Combine(pluginTestDataPath, string.Format(krpFormat, fileName)); + string surfaceLines = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(surfaceLineFormat, fileName)); + string corruptPath = Path.Combine(pluginSurfaceLinesTestDataPath, string.Format(krpFormat, fileName)); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -1113,12 +1301,21 @@ string twovalidsurfacelinesCsv =string.Format(surfaceLineFormat, fileName); string twovalidsurfacelinesCharacteristicPointsCsv = string.Format(krpFormat, fileName); - string validSurfaceLinesFilePath = Path.Combine(pluginTestDataPath, twovalidsurfacelinesCsv); - string validCharacteristicPointsFilePath = Path.Combine(pluginTestDataPath, twovalidsurfacelinesCsv); + string validSurfaceLinesFilePath = Path.Combine(pluginSurfaceLinesTestDataPath, twovalidsurfacelinesCsv); + string validCharacteristicPointsFilePath = Path.Combine(pluginSurfaceLinesTestDataPath, twovalidsurfacelinesCsv); var mocks = new MockRepository(); var observer = mocks.StrictMock(); var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; var failureMechanism = new PipingFailureMechanism(); mocks.ReplayAll(); @@ -1166,7 +1363,7 @@ // Sample some of the imported data: var firstSurfaceLine = importTargetArray[0]; Assert.AreEqual("Rotterdam1", firstSurfaceLine.Name); - Assert.AreEqual(8, firstSurfaceLine.Points.Count()); + Assert.AreEqual(8, firstSurfaceLine.Points.Length); Assert.AreEqual(427776.654093, firstSurfaceLine.StartingWorldPoint.Y); Assert.AreEqual(new Point3D(94263.0026213, 427776.654093, -1.02), firstSurfaceLine.DitchPolderSide); Assert.AreEqual(new Point3D(94275.9126686, 427811.080886, -1.04), firstSurfaceLine.BottomDitchPolderSide); @@ -1177,7 +1374,7 @@ var secondSurfaceLine = importTargetArray[1]; Assert.AreEqual("ArtifcialLocal", secondSurfaceLine.Name); - Assert.AreEqual(3, secondSurfaceLine.Points.Count()); + Assert.AreEqual(3, secondSurfaceLine.Points.Length); Assert.AreEqual(5.7, secondSurfaceLine.EndingWorldPoint.X); Assert.AreEqual(new Point3D(2.3, 0, 1.0), secondSurfaceLine.DitchPolderSide); Assert.AreEqual(new Point3D(4.4, 0, 2.0), secondSurfaceLine.BottomDitchPolderSide); @@ -1193,5 +1390,115 @@ mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } + + [Test] + public void Import_DoesNotInterSectReferenceLine_SkipRowAndLog() + { + // Setup + const int expectedNumberOfSurfaceLines = 1; + var twovalidsurfacelinesCsv = "TwoValidSurfaceLines.csv"; + string validFilePath = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + assessmentSection.ReferenceLine = referenceLine; + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var mesagge = "Profielmeting ArtifcialLocal komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd. Dit kan komen doordat de profielmeting een lokaal coordinaat systeem heeft."; + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + context.Attach(observer); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Precondition + CollectionAssert.IsEmpty(context.FailureMechanism.SurfaceLines); + Assert.IsTrue(File.Exists(validFilePath)); + + // Call + var importResult = false; + Action call = () => importResult = importer.Import(context, validFilePath); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, mesagge); + var importTargetArray = context.FailureMechanism.SurfaceLines.ToArray(); + Assert.IsTrue(importResult); + Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); + + // Sample some of the imported data: + var firstSurfaceLine = importTargetArray[0]; + Assert.AreEqual("Rotterdam1", firstSurfaceLine.Name); + Assert.AreEqual(8, firstSurfaceLine.Points.Length); + Assert.AreEqual(427776.654093, firstSurfaceLine.StartingWorldPoint.Y); + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); + + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver + } + + [Test] + public void Import_DoesInterSectReferenceLineMultipleTimes_SkipRowAndLog() + { + // Setup + const int expectedNumberOfSurfaceLines = 1; + var twovalidsurfacelinesCsv = "TwoValidSurfaceLines.csv"; + string validFilePath = Path.Combine(ioTestDataPath, twovalidsurfacelinesCsv); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var assessmentSection = mocks.StrictMock(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775), + new Point2D(94270, 427812), + new Point2D(94271, 427776), + new Point2D(94271, 427813) + }); + assessmentSection.ReferenceLine = referenceLine; + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var mesagge = "Profielmeting Rotterdam1 komt niet overeen met de huidige referentielijn en kan niet worden geïmporteerd."; + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + context.Attach(observer); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Precondition + CollectionAssert.IsEmpty(context.FailureMechanism.SurfaceLines); + Assert.IsTrue(File.Exists(validFilePath)); + + // Call + var importResult = false; + Action call = () => importResult = importer.Import(context, validFilePath); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, mesagge); + var importTargetArray = context.FailureMechanism.SurfaceLines.ToArray(); + Assert.IsTrue(importResult); + Assert.AreEqual(expectedNumberOfSurfaceLines, importTargetArray.Length); + + // Sample some of the imported data: + var firstSurfaceLine = importTargetArray[0]; + Assert.AreEqual("ArtifcialLocal", firstSurfaceLine.Name); + Assert.AreEqual(3, firstSurfaceLine.Points.Length); + Assert.AreEqual(0.0, firstSurfaceLine.StartingWorldPoint.Y); + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); + + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -r86e717a5477d55d1c4351f2857a1d76e220a3ab4 -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 86e717a5477d55d1c4351f2857a1d76e220a3ab4) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) @@ -105,6 +105,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {52ba7627-cbab-4209-be77-3b5f31378277} + Ringtoets.Common.IO + {ce994cc9-6f6a-48ac-b4be-02c30a21f4db} Ringtoets.Piping.Data