Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r988794432302c63a2ecbe29c024c7d69edfe7cd3 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 988794432302c63a2ecbe29c024c7d69edfe7cd3) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -197,5 +197,59 @@ return ResourceManager.GetString("DuneLocation_WavePeriod_DisplayName", resourceCulture); } } + + /// + /// Looks up a localized string similar to Kustvaknummer. + /// + internal static string MetaData_CoastalAreaId { + get { + return ResourceManager.GetString("MetaData_CoastalAreaId", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rekenwaarde D50. + /// + internal static string MetaData_D50 { + get { + return ResourceManager.GetString("MetaData_D50", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Metrering. + /// + internal static string MetaData_Offset { + get { + return ResourceManager.GetString("MetaData_Offset", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rekenwaarde waterstand. + /// + internal static string MetaData_WaterLevel { + get { + return ResourceManager.GetString("MetaData_WaterLevel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rekenwaarde Hs. + /// + internal static string MetaData_WaveHeight { + get { + return ResourceManager.GetString("MetaData_WaveHeight", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rekenwaarde Tp. + /// + internal static string MetaData_WavePeriod { + get { + return ResourceManager.GetString("MetaData_WavePeriod", resourceCulture); + } + } } } Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx =================================================================== diff -u -r988794432302c63a2ecbe29c024c7d69edfe7cd3 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx (.../Resources.resx) (revision 988794432302c63a2ecbe29c024c7d69edfe7cd3) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx (.../Resources.resx) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -156,4 +156,22 @@ Tp [s] + + Kustvaknummer + + + Rekenwaarde D50 + + + Metrering + + + Rekenwaarde waterstand + + + Rekenwaarde Hs + + + Rekenwaarde Tp + \ No newline at end of file Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj =================================================================== diff -u -r9696877b8e90de7c28ac96e336d3f9db28b02118 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 9696877b8e90de7c28ac96e336d3f9db28b02118) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -61,6 +61,7 @@ DuneErosionFailureMechanismView.cs + Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionFailureMechanismView.cs =================================================================== diff -u -rb9a59dd5f30c8de46d0cabb4e1609c09176a4246 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionFailureMechanismView.cs (.../DuneErosionFailureMechanismView.cs) (revision b9a59dd5f30c8de46d0cabb4e1609c09176a4246) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionFailureMechanismView.cs (.../DuneErosionFailureMechanismView.cs) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -26,8 +26,8 @@ using Core.Components.Gis.Forms; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Forms.Views; +using Ringtoets.DuneErosion.Data; using Ringtoets.DuneErosion.Forms.PresentationObjects; using DuneErosionDataResources = Ringtoets.DuneErosion.Data.Properties.Resources; @@ -40,14 +40,14 @@ { private readonly Observer failureMechanismObserver; private readonly Observer assessmentSectionObserver; - private readonly Observer hydraulicBoundaryDatabaseObserver; + private readonly Observer duneLocationsObserver; private readonly MapDataCollection mapDataCollection; private readonly MapLineData referenceLineMapData; private readonly MapLineData sectionsMapData; private readonly MapPointData sectionsStartPointMapData; private readonly MapPointData sectionsEndPointMapData; - private readonly MapPointData hydraulicBoundaryLocationsMapData; + private readonly MapPointData duneLocationsMapData; private DuneErosionFailureMechanismContext data; @@ -59,20 +59,12 @@ InitializeComponent(); failureMechanismObserver = new Observer(UpdateMapData); - assessmentSectionObserver = new Observer(() => - { - if (!ReferenceEquals(hydraulicBoundaryDatabaseObserver.Observable, data.Parent.HydraulicBoundaryDatabase)) - { - hydraulicBoundaryDatabaseObserver.Observable = data.Parent.HydraulicBoundaryDatabase; - } + assessmentSectionObserver = new Observer(UpdateMapData); + duneLocationsObserver = new Observer(UpdateMapData); - UpdateMapData(); - }); - hydraulicBoundaryDatabaseObserver = new Observer(UpdateMapData); - mapDataCollection = new MapDataCollection(DuneErosionDataResources.DuneErosionFailureMechanism_DisplayName); referenceLineMapData = RingtoetsMapDataFactory.CreateReferenceLineMapData(); - hydraulicBoundaryLocationsMapData = RingtoetsMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); + duneLocationsMapData = RingtoetsMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); sectionsMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsMapData(); sectionsStartPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); sectionsEndPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); @@ -81,7 +73,7 @@ mapDataCollection.Add(sectionsMapData); mapDataCollection.Add(sectionsStartPointMapData); mapDataCollection.Add(sectionsEndPointMapData); - mapDataCollection.Add(hydraulicBoundaryLocationsMapData); + mapDataCollection.Add(duneLocationsMapData); } public object Data @@ -98,7 +90,7 @@ { failureMechanismObserver.Observable = null; assessmentSectionObserver.Observable = null; - hydraulicBoundaryDatabaseObserver.Observable = null; + duneLocationsObserver.Observable = null; Map.Data = null; } @@ -108,7 +100,7 @@ assessmentSectionObserver.Observable = data.Parent; mapDataCollection.Name = data.WrappedData.Name; - hydraulicBoundaryDatabaseObserver.Observable = data.Parent.HydraulicBoundaryDatabase; + duneLocationsObserver.Observable = data.WrappedData.DuneLocations; SetMapDataFeatures(); @@ -129,11 +121,11 @@ { failureMechanismObserver.Dispose(); assessmentSectionObserver.Dispose(); - hydraulicBoundaryDatabaseObserver.Dispose(); + duneLocationsObserver.Dispose(); - if (disposing && (components != null)) + if (disposing) { - components.Dispose(); + components?.Dispose(); } base.Dispose(disposing); } @@ -146,20 +138,20 @@ sectionsMapData.NotifyObservers(); sectionsStartPointMapData.NotifyObservers(); sectionsEndPointMapData.NotifyObservers(); - hydraulicBoundaryLocationsMapData.NotifyObservers(); + duneLocationsMapData.NotifyObservers(); } private void SetMapDataFeatures() { ReferenceLine referenceLine = data.Parent.ReferenceLine; - HydraulicBoundaryDatabase hydraulicBoundaryDatabase = data.Parent.HydraulicBoundaryDatabase; + DuneLocation[] duneLocations = data.WrappedData.DuneLocations.ToArray(); IEnumerable failureMechanismSections = data.WrappedData.Sections; referenceLineMapData.Features = RingtoetsMapDataFeaturesFactory.CreateReferenceLineFeatures(referenceLine, data.Parent.Id, data.Parent.Name); sectionsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(failureMechanismSections); sectionsStartPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionStartPointFeatures(failureMechanismSections); sectionsEndPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionEndPointFeatures(failureMechanismSections); - hydraulicBoundaryLocationsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateHydraulicBoundaryDatabaseFeatures(hydraulicBoundaryDatabase); + duneLocationsMapData.Features = DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(duneLocations); } } } \ No newline at end of file Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionMapDataFeaturesFactory.cs =================================================================== diff -u --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionMapDataFeaturesFactory.cs (revision 0) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneErosionMapDataFeaturesFactory.cs (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -0,0 +1,92 @@ +// 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.Globalization; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Features; +using Core.Components.Gis.Geometries; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Forms.Properties; +using RingtoetsDuneErosionDataResources = Ringtoets.DuneErosion.Data.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.DuneErosion.Forms.Views +{ + /// + /// Factory for creating arrays of for the + /// to use in (created via ). + /// + public static class DuneErosionMapDataFeaturesFactory + { + /// + /// Create dune location features based on the provided . + /// + /// The array of + /// to create the location features for. + /// An array of features or an empty array when + /// is empty. + /// Thrown when is null. + public static MapFeature[] CreateDuneLocationFeatures(DuneLocation[] duneLocations) + { + if (duneLocations == null) + { + throw new ArgumentNullException(nameof(duneLocations)); + } + + var features = new MapFeature[duneLocations.Length]; + + for (var i = 0; i < duneLocations.Length; i++) + { + DuneLocation location = duneLocations[i]; + + var feature = CreateSinglePointMapFeature(location.Location); + feature.MetaData[RingtoetsCommonFormsResources.MetaData_ID] = location.Id; + feature.MetaData[RingtoetsCommonFormsResources.MetaData_Name] = location.Name; + feature.MetaData[Resources.MetaData_CoastalAreaId] = location.CoastalAreaId; + feature.MetaData[Resources.MetaData_Offset] = location.Offset.ToString(RingtoetsDuneErosionDataResources.DuneLocation_Offset_format, + CultureInfo.InvariantCulture); + feature.MetaData[Resources.MetaData_WaterLevel] = location.Output?.WaterLevel ?? double.NaN; + feature.MetaData[Resources.MetaData_WaveHeight] = location.Output?.WaveHeight ?? double.NaN; + feature.MetaData[Resources.MetaData_WavePeriod] = location.Output?.WavePeriod ?? double.NaN; + feature.MetaData[Resources.MetaData_D50] = location.D50; + + features[i] = feature; + } + + return features; + } + + private static MapFeature CreateSinglePointMapFeature(Point2D point) + { + return new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + point + } + }) + }); + } + } +} \ No newline at end of file Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj =================================================================== diff -u -r71238843b638b6f9d0df07ebecbf633ea5da6af1 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision 71238843b638b6f9d0df07ebecbf633ea5da6af1) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -65,6 +65,7 @@ + Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionFailureMechanismViewTest.cs =================================================================== diff -u -rb9a59dd5f30c8de46d0cabb4e1609c09176a4246 -rbc0f3d7ae18c5a240f05fd29b62238ca978b40e4 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionFailureMechanismViewTest.cs (.../DuneErosionFailureMechanismViewTest.cs) (revision b9a59dd5f30c8de46d0cabb4e1609c09176a4246) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionFailureMechanismViewTest.cs (.../DuneErosionFailureMechanismViewTest.cs) (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -34,9 +34,9 @@ using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; -using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; using Ringtoets.DuneErosion.Forms.PresentationObjects; using Ringtoets.DuneErosion.Forms.Views; @@ -49,7 +49,7 @@ private const int sectionsIndex = 1; private const int sectionsStartPointIndex = 2; private const int sectionsEndPointIndex = 3; - private const int hydraulicBoundaryLocationsIndex = 4; + private const int duneLocationsIndex = 4; [Test] public void DefaultConstructor_DefaultValues() @@ -168,28 +168,25 @@ new Point2D(6.0, 4.0) }; - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - Locations = - { - new TestHydraulicBoundaryLocation() - } - }; - var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(new[] - { - new Point2D(1.0, 2.0), - new Point2D(2.0, 1.0) - }); + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); var assessmentSection = new TestAssessmentSection { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase, ReferenceLine = referenceLine }; - var failureMechanism = new DuneErosionFailureMechanism(); + var failureMechanism = new DuneErosionFailureMechanism + { + DuneLocations = + { + new TestDuneLocation() + } + }; failureMechanism.AddSection(new FailureMechanismSection("A", geometryPoints.Take(2))); failureMechanism.AddSection(new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2))); failureMechanism.AddSection(new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2))); @@ -211,7 +208,7 @@ MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, mapDataList[sectionsIndex]); MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, mapDataList[sectionsStartPointIndex]); MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, mapDataList[sectionsEndPointIndex]); - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, mapDataList[hydraulicBoundaryLocationsIndex]); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, mapDataList[duneLocationsIndex]); } } @@ -223,126 +220,100 @@ { var map = (MapControl) view.Controls[0]; - var hydraulicBoundaryDatabase1 = new HydraulicBoundaryDatabase + var assessmentSection = new TestAssessmentSection(); + var duneLocation1 = new TestDuneLocation(); + + var failureMechanism = new DuneErosionFailureMechanism { - Locations = + DuneLocations = { - new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + duneLocation1 } }; - var hydraulicBoundaryDatabase2 = new HydraulicBoundaryDatabase - { - Locations = - { - new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) - } - }; + var failureMechanismContext = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); - var assessmentSection = new TestAssessmentSection - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase1 - }; - - var failureMechanismContext = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), assessmentSection); - view.Data = failureMechanismContext; - var hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var duneLocationsMapData = map.Data.Collection.ElementAt(duneLocationsIndex); // Precondition - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase1.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); // Call - assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase2; + failureMechanism.DuneLocations.Add(new TestDuneLocation()); assessmentSection.NotifyObservers(); // Assert - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase2.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); } } [Test] - public void UpdateObserver_HydraulicBoundaryDatabaseUpdated_MapDataUpdated() + public void UpdateObserver_DuneLocationsUpdated_MapDataUpdated() { // Setup using (var view = new DuneErosionFailureMechanismView()) { var map = (MapControl) view.Controls[0]; - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + var assessmentSection = new TestAssessmentSection(); + var duneLocation1 = new TestDuneLocation(); + + var failureMechanism = new DuneErosionFailureMechanism { - Locations = + DuneLocations = { - new TestHydraulicBoundaryLocation() + duneLocation1 } }; + var failureMechanismContext = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); - var assessmentSection = new TestAssessmentSection - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase - }; - - var failureMechanismContext = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), assessmentSection); - view.Data = failureMechanismContext; - var hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var duneLocationsMapData = map.Data.Collection.ElementAt(duneLocationsIndex); // Precondition - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); // Call - hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 3.0, 4.0)); - hydraulicBoundaryDatabase.NotifyObservers(); + failureMechanism.DuneLocations.Add(new TestDuneLocation()); + failureMechanism.DuneLocations.NotifyObservers(); // Assert - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); } } [Test] - public void GivenAssessmentSectionWithHydraulicBoundaryDatabase_WhenNewDatabaseIsSetAndNotified_ThenMapDataUpdated() + public void GivenAssessmentSectionWithDuneLocations_WhenNewDuneLocationsAreSetAndNotified_ThenMapDataUpdated() { // Given using (var view = new DuneErosionFailureMechanismView()) { var map = (MapControl) view.Controls[0]; - var currentHydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + var assessmentSection = new TestAssessmentSection(); + var failureMechanism = new DuneErosionFailureMechanism { - Locations = + DuneLocations = { - new HydraulicBoundaryLocation(1, "old 1", 1, 2) + new TestDuneLocation() } }; - var newHydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - Locations = - { - new HydraulicBoundaryLocation(1, "new 1", 1, 2) - } - }; + view.Data = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); - var assessmentSection = new TestAssessmentSection - { - HydraulicBoundaryDatabase = currentHydraulicBoundaryDatabase - }; + var duneLocationsMapData = map.Data.Collection.ElementAt(duneLocationsIndex); - view.Data = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), assessmentSection); - - var hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); - // Precondition - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(currentHydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); // When - assessmentSection.HydraulicBoundaryDatabase = newHydraulicBoundaryDatabase; - assessmentSection.NotifyObservers(); - newHydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(2, "new 2", 2, 3)); - newHydraulicBoundaryDatabase.NotifyObservers(); + failureMechanism.DuneLocations.Clear(); + failureMechanism.DuneLocations.Add(new TestDuneLocation()); + failureMechanism.DuneLocations.NotifyObservers(); // Then - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(newHydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); + AssertDuneLocationsMapData(failureMechanism.DuneLocations, duneLocationsMapData); } } @@ -409,10 +380,10 @@ // Call failureMechanism.AddSection(new FailureMechanismSection(string.Empty, new[] - { - new Point2D(1, 2), - new Point2D(1, 2) - })); + { + new Point2D(1, 2), + new Point2D(1, 2) + })); failureMechanism.NotifyObservers(); // Assert @@ -430,7 +401,7 @@ const int updatedSectionsLayerIndex = sectionsIndex - 1; const int updateSectionStartLayerIndex = sectionsStartPointIndex - 1; const int updatedSectionEndLayerIndex = sectionsEndPointIndex - 1; - const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedDuneLocationsLayerIndex = duneLocationsIndex - 1; using (var view = new DuneErosionFailureMechanismView()) { @@ -463,8 +434,8 @@ var sectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex]; Assert.AreEqual("Vakindeling (eindpunten)", sectionEndsData.Name); - var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; - Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicLocationsData.Name); + var duneLocationsData = (MapPointData) mapDataList[updatedDuneLocationsLayerIndex]; + Assert.AreEqual("Hydraulische randvoorwaarden", duneLocationsData.Name); var points = new List { @@ -491,8 +462,8 @@ var actualSectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex]; Assert.AreEqual("Vakindeling (eindpunten)", actualSectionEndsData.Name); - var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; - Assert.AreEqual("Hydraulische randvoorwaarden", actualHydraulicLocationsData.Name); + var actualDuneLocationsData = (MapPointData) mapDataList[updatedDuneLocationsLayerIndex]; + Assert.AreEqual("Hydraulische randvoorwaarden", actualDuneLocationsData.Name); } } @@ -505,10 +476,10 @@ newAssessmentSection.ReferenceLine = new ReferenceLine(); newAssessmentSection.ReferenceLine.SetGeometry(new[] - { - new Point2D(2, 4), - new Point2D(3, 4) - }); + { + new Point2D(2, 4), + new Point2D(3, 4) + }); var oldFailureMechanismContext = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), oldAssessmentSection); var newFailureMechanismContext = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), newAssessmentSection); @@ -542,21 +513,40 @@ var sectionsMapData = (MapLineData) mapDataList[sectionsIndex]; var sectionsStartPointMapData = (MapPointData) mapDataList[sectionsStartPointIndex]; var sectionsEndPointMapData = (MapPointData) mapDataList[sectionsEndPointIndex]; - var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var duneLocationsMapData = (MapPointData) mapDataList[duneLocationsIndex]; CollectionAssert.IsEmpty(referenceLineMapData.Features); CollectionAssert.IsEmpty(sectionsMapData.Features); CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); - CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + CollectionAssert.IsEmpty(duneLocationsMapData.Features); Assert.AreEqual("Referentielijn", referenceLineMapData.Name); Assert.AreEqual("Vakindeling", sectionsMapData.Name); Assert.AreEqual("Vakindeling (startpunten)", sectionsStartPointMapData.Name); Assert.AreEqual("Vakindeling (eindpunten)", sectionsEndPointMapData.Name); - Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicBoundaryLocationsMapData.Name); + Assert.AreEqual("Hydraulische randvoorwaarden", duneLocationsMapData.Name); } + private static void AssertDuneLocationsMapData(IEnumerable duneLocations, MapData mapData) + { + Assert.IsInstanceOf(mapData); + MapPointData duneLocationsMapData = (MapPointData) mapData; + if (duneLocations == null) + { + CollectionAssert.IsEmpty(duneLocationsMapData.Features); + } + else + { + var duneLocationsArray = duneLocations.ToArray(); + + Assert.AreEqual(duneLocationsArray.Length, duneLocationsMapData.Features.Length); + CollectionAssert.AreEqual(duneLocationsArray.Select(hrp => hrp.Location), + duneLocationsMapData.Features.SelectMany(f => f.MapGeometries.First().PointCollections.First())); + } + Assert.AreEqual("Hydraulische randvoorwaarden", mapData.Name); + } + private class TestAssessmentSection : Observable, IAssessmentSection { public string Id { get; set; } Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionMapDataFeaturesFactoryTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionMapDataFeaturesFactoryTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneErosionMapDataFeaturesFactoryTest.cs (revision bc0f3d7ae18c5a240f05fd29b62238ca978b40e4) @@ -0,0 +1,149 @@ +// 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.Globalization; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Features; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; +using Ringtoets.DuneErosion.Forms.Views; + +namespace Ringtoets.DuneErosion.Forms.Test.Views +{ + [TestFixture] + public class DuneErosionMapDataFeaturesFactoryTest + { + [Test] + public void CreateDuneLocationFeatures_DuneLocationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("duneLocations", paramName); + } + + [Test] + public void CreateDuneLocationFeatures_DuneLocationsArrayEmpty_ReturnsEmptyFeaturesArray() + { + // Call + MapFeature[] features = DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(new DuneLocation[0]); + + // Assert + CollectionAssert.IsEmpty(features); + } + + [Test] + public void CreateDuneLocationFeatures_DuneLocationsWithOutput_ReturnsLocationFeaturesArray() + { + // Setup + var points = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + DuneLocation[] locations = points.Select(p => new ValidDuneLocation(p) + { + Output = new TestDuneLocationOutput() + }).Cast().ToArray(); + + // Call + MapFeature[] features = DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(locations); + + // Assert + Assert.AreEqual(locations.Length, features.Length); + for (var i = 0; i < locations.Length; i++) + { + Assert.AreEqual(locations[i].Id, features[i].MetaData["ID"]); + Assert.AreEqual(locations[i].Name, features[i].MetaData["Naam"]); + Assert.AreEqual(locations[i].CoastalAreaId, features[i].MetaData["Kustvaknummer"]); + Assert.AreEqual(locations[i].Offset.ToString("0.#", CultureInfo.InvariantCulture), features[i].MetaData["Metrering"]); + Assert.AreEqual(locations[i].Output.WaterLevel, (double) features[i].MetaData["Rekenwaarde waterstand"], + locations[i].Output.WaterLevel.GetAccuracy()); + Assert.AreEqual(locations[i].Output.WaveHeight, (double) features[i].MetaData["Rekenwaarde Hs"], + locations[i].Output.WaveHeight.GetAccuracy()); + Assert.AreEqual(locations[i].Output.WavePeriod, (double) features[i].MetaData["Rekenwaarde Tp"], + locations[i].Output.WavePeriod.GetAccuracy()); + Assert.AreEqual(locations[i].D50, (RoundedDouble) features[i].MetaData["Rekenwaarde D50"], + locations[i].D50.GetAccuracy()); + Assert.AreEqual(8, features[i].MetaData.Keys.Count); + } + + AssertEqualFeatureCollections(points, features); + } + + [Test] + public void CreateDuneLocationFeatures_DuneLocationsWithoutOutput_ReturnsLocationFeaturesArray() + { + // Setup + var points = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + DuneLocation[] locations = points.Select(p => new ValidDuneLocation(p)).Cast().ToArray(); + + // Call + MapFeature[] features = DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(locations); + + // Assert + Assert.AreEqual(locations.Length, features.Length); + for (var i = 0; i < locations.Length; i++) + { + Assert.AreEqual(locations[i].Id, features[i].MetaData["ID"]); + Assert.AreEqual(locations[i].Name, features[i].MetaData["Naam"]); + Assert.AreEqual(locations[i].CoastalAreaId, features[i].MetaData["Kustvaknummer"]); + Assert.AreEqual(locations[i].Offset.ToString("0.#", CultureInfo.InvariantCulture), features[i].MetaData["Metrering"]); + Assert.AreEqual(double.NaN, features[i].MetaData["Rekenwaarde waterstand"]); + Assert.AreEqual(double.NaN, features[i].MetaData["Rekenwaarde Hs"]); + Assert.AreEqual(double.NaN, features[i].MetaData["Rekenwaarde Tp"]); + Assert.AreEqual(locations[i].D50, (RoundedDouble) features[i].MetaData["Rekenwaarde D50"], + locations[i].D50.GetAccuracy()); + Assert.AreEqual(8, features[i].MetaData.Keys.Count); + } + + AssertEqualFeatureCollections(points, features); + } + + private class ValidDuneLocation : DuneLocation + { + public ValidDuneLocation(Point2D location) : base(0, "", location, new ConstructionProperties()) {} + } + + private static void AssertEqualFeatureCollections(Point2D[] points, MapFeature[] features) + { + Assert.AreEqual(points.Length, features.Length); + for (int i = 0; i < points.Length; i++) + { + CollectionAssert.AreEqual(new[] + { + points[i] + }, features[i].MapGeometries.First().PointCollections.First()); + } + } + } +} \ No newline at end of file