Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismViewTest.cs =================================================================== diff -u -r3ea86a3d4d3c20e47943ba4966abf61c7d3d9f4a -ra16becf5d0a010bc9d38ccb06dc330732fcbbee4 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismViewTest.cs (.../ClosingStructuresFailureMechanismViewTest.cs) (revision 3ea86a3d4d3c20e47943ba4966abf61c7d3d9f4a) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismViewTest.cs (.../ClosingStructuresFailureMechanismViewTest.cs) (revision a16becf5d0a010bc9d38ccb06dc330732fcbbee4) @@ -400,21 +400,17 @@ MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); // Precondition - object designWaterLevel = ((MapPointData) hydraulicBoundaryLocationsMapData).Features.Select(ft => ft.MetaData["Toetspeil"]).Single(); - object waveHeights = ((MapPointData) hydraulicBoundaryLocationsMapData).Features.Select(ft => ft.MetaData["Golfhoogte"]).Single(); - Assert.IsNaN((RoundedDouble) designWaterLevel); - Assert.IsNaN((RoundedDouble) waveHeights); + MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(assessmentSection.HydraulicBoundaryDatabase.Locations, + hydraulicBoundaryLocationsMapData); // When hydraulicBoundaryLocation.DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()); hydraulicBoundaryLocation.WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()); hydraulicBoundaryLocation.NotifyObservers(); // Then - designWaterLevel = ((MapPointData) hydraulicBoundaryLocationsMapData).Features.Select(ft => ft.MetaData["Toetspeil"]).Single(); - waveHeights = ((MapPointData) hydraulicBoundaryLocationsMapData).Features.Select(ft => ft.MetaData["Golfhoogte"]).Single(); - Assert.AreEqual(hydraulicBoundaryLocation.DesignWaterLevel, (RoundedDouble) designWaterLevel); - Assert.AreEqual(hydraulicBoundaryLocation.WaveHeight, (RoundedDouble) waveHeights); + MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(assessmentSection.HydraulicBoundaryDatabase.Locations, + hydraulicBoundaryLocationsMapData); } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/MapDataTestHelperTest.cs =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -ra16becf5d0a010bc9d38ccb06dc330732fcbbee4 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/MapDataTestHelperTest.cs (.../MapDataTestHelperTest.cs) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/MapDataTestHelperTest.cs (.../MapDataTestHelperTest.cs) (revision a16becf5d0a010bc9d38ccb06dc330732fcbbee4) @@ -19,10 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Core.Components.Gis.Geometries; @@ -211,68 +213,64 @@ } [Test] - public void AssertHydraulicBoundaryLocationsMapData_DatabaseNullMapDataHasFeatures_ThrowAssertionException() + public void AssertHydraulicBoundaryLocationsMapData_FeaturesNotSameAsLocations_ThrowAssertionException() { // Setup - var mapData = new MapPointData("Hydraulische randvoorwaarden") + IEnumerable hydraulicBoundaryLocations = new[] { - Features = new[] - { - new MapFeature(new[] - { - new MapGeometry(new[] - { - Enumerable.Empty() - }) - }), - new MapFeature(new[] - { - new MapGeometry(new[] - { - Enumerable.Empty() - }) - }) - } + new HydraulicBoundaryLocation(1, "test1", 1, 0) }; + var mapData = new MapPointData("Hydraulische randvoorwaarden"); + // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(null, mapData); + TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryLocations, mapData); // Assert Assert.Throws(test); } [Test] - public void AssertHydraulicBoundaryLocationsMapData_FeaturesNotSameAsLocations_ThrowAssertionException() + public void AssertHydraulicBoundaryLocationsMapData_FeatureGeometryNotSameAsLocations_ThrowAssertionException() { // Setup - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + IEnumerable hydraulicBoundaryLocations = new[] { - Locations = + new HydraulicBoundaryLocation(1, "test1", 1, 0) + }; + + var mapData = new MapPointData("Hydraulische randvoorwaarden") + { + Features = new[] { - new HydraulicBoundaryLocation(1, "test1", 0, 0) + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(0, 0) + } + }) + }) } }; - var mapData = new MapPointData("Hydraulische randvoorwaarden"); - // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, mapData); + TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryLocations, mapData); // Assert Assert.Throws(test); } [Test] - public void AssertHydraulicBoundaryLocationsMapData_FeatureGeometryNotSameAsLocations_ThrowAssertionException() + public void AssertHydraulicBoundaryLocationsMapData_WithHydraulicBoundaryLocationsMapDataCorrect_DoesNotThrow() { // Setup - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1, 0); + IEnumerable hydraulicBoundaryLocations = new[] { - Locations = - { - new HydraulicBoundaryLocation(1, "test1", 1, 0) - } + hydraulicBoundaryLocation }; var mapData = new MapPointData("Hydraulische randvoorwaarden") @@ -285,80 +283,159 @@ { new[] { - new Point2D(0, 0) + new Point2D(1, 0) } }) }) } }; // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, mapData); + TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryLocations, mapData); // Assert - Assert.Throws(test); + Assert.DoesNotThrow(test); } [Test] - public void AssertHydraulicBoundaryLocationsMapData_MapDataNameNotCorrect_ThrowAssertionException() + [TestCaseSource(nameof(GetHydraulicBoundaryLocationUnequalOutputMapFeatures))] + public void AssertHydraulicBoundaryLocationOutputsMapData_MapDataOutputFeaturesNotSameAsLocations_ThrowAssertionException( + IEnumerable mapFeatures) { // Setup - var mapData = new MapPointData("test"); + IEnumerable hydraulicBoundaryLocations = new[] + { + new HydraulicBoundaryLocation(1, "test1", 1, 0) + }; + var mapData = new MapPointData("Hydraulische randvoorwaarden") + { + Features = mapFeatures + }; + // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(null, mapData); + TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(hydraulicBoundaryLocations, mapData); // Assert Assert.Throws(test); } [Test] - public void AssertHydraulicBoundaryLocationsMapData_WithoutDatabaseMapDataCorrect_DoesNotThrow() + [TestCaseSource(nameof(GetHydraulicBoundaryLocationEqualOutputMapFeatures))] + public void AssertHydraulicBoundaryLocationOutputsMapData_MapDataOutputFeaturesSameAsLocations_DoesNotThrowAssertionException( + HydraulicBoundaryLocation location, + MapFeature mapFeature) { - // Setup - var mapData = new MapPointData("Hydraulische randvoorwaarden"); + IEnumerable hydraulicBoundaryLocations = new[] + { + location + }; + var mapData = new MapPointData("Hydraulische randvoorwaarden") + { + Features = new[] + { + mapFeature + } + }; + // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(null, mapData); + TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(hydraulicBoundaryLocations, mapData); // Assert Assert.DoesNotThrow(test); } - [Test] - public void AssertHydraulicBoundaryLocationsMapData_WithDatabaseMapDataCorrect_DoesNotThrow() + private static IEnumerable GetHydraulicBoundaryLocationUnequalOutputMapFeatures() { - // Setup - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + var random = new Random(21); + var mapGeometry = new MapGeometry(new[] { - Locations = + new[] { - new HydraulicBoundaryLocation(1, "test1", 1, 0) + new Point2D(1, 0) } + }); + + var differentWaveHeightMapFeature = new MapFeature(new[] + { + mapGeometry + }); + differentWaveHeightMapFeature.MetaData["Golfhoogte"] = random.NextRoundedDouble(); + differentWaveHeightMapFeature.MetaData["Toetspeil"] = RoundedDouble.NaN; + var mapFeatures = new List + { + differentWaveHeightMapFeature }; + yield return new TestCaseData(mapFeatures) + .SetName("Different WaveHeight"); - var mapData = new MapPointData("Hydraulische randvoorwaarden") + var differentDesignWaterLevelMapFeature = new MapFeature(new[] { - Features = new[] + mapGeometry + }); + differentDesignWaterLevelMapFeature.MetaData["Golfhoogte"] = RoundedDouble.NaN; + differentDesignWaterLevelMapFeature.MetaData["Toetspeil"] = random.NextRoundedDouble(); + mapFeatures = new List + { + differentDesignWaterLevelMapFeature + }; + yield return new TestCaseData(mapFeatures) + .SetName("Different DesignWaterLevel"); + + var mapFeatureOne = new MapFeature(new[] + { + mapGeometry + }); + mapFeatureOne.MetaData["Golfhoogte"] = RoundedDouble.NaN; + mapFeatureOne.MetaData["Toetspeil"] = RoundedDouble.NaN; + var mapFeatureTwo = new MapFeature(new[] + { + mapGeometry + }); + mapFeatureTwo.MetaData["Golfhoogte"] = RoundedDouble.NaN; + mapFeatureTwo.MetaData["Toetspeil"] = RoundedDouble.NaN; + mapFeatures = new List + { + mapFeatureOne, + mapFeatureTwo + }; + yield return new TestCaseData(mapFeatures) + .SetName("Different MapFeaturesCount"); + } + + private static IEnumerable GetHydraulicBoundaryLocationEqualOutputMapFeatures() + { + var location = new HydraulicBoundaryLocation(1, "test1", 1, 0); + var mapGeometry = new MapGeometry(new[] + { + new[] { - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(1, 0) - } - }) - }) + new Point2D(1, 0) } - }; + }); - // Call - TestDelegate test = () => MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase.Locations, mapData); + var mapFeatureNoOutput = new MapFeature(new[] + { + mapGeometry + }); + mapFeatureNoOutput.MetaData["Golfhoogte"] = RoundedDouble.NaN; + mapFeatureNoOutput.MetaData["Toetspeil"] = RoundedDouble.NaN; + yield return new TestCaseData(location, mapFeatureNoOutput) + .SetName("LocationWithoutOutput"); - // Assert - Assert.DoesNotThrow(test); + var random = new Random(21); + location = new HydraulicBoundaryLocation(1, "test1", 1, 0); + location.DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()); + location.WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()); + var mapFeatureWithOutput = new MapFeature(new[] + { + mapGeometry + }); + mapFeatureWithOutput.MetaData["Golfhoogte"] = location.WaveHeight; + mapFeatureWithOutput.MetaData["Toetspeil"] = location.DesignWaterLevel; + yield return new TestCaseData(location, mapFeatureWithOutput) + .SetName("LocationWithOutput"); } #endregion Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/MapDataTestHelper.cs =================================================================== diff -u -r9b2bb9a809f4b42bd06b910dde1f6eb8e546356f -ra16becf5d0a010bc9d38ccb06dc330732fcbbee4 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/MapDataTestHelper.cs (.../MapDataTestHelper.cs) (revision 9b2bb9a809f4b42bd06b910dde1f6eb8e546356f) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/MapDataTestHelper.cs (.../MapDataTestHelper.cs) (revision a16becf5d0a010bc9d38ccb06dc330732fcbbee4) @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Geometry; using Core.Components.Gis.Data; @@ -80,7 +81,6 @@ /// /// is not ; /// the name of the is not "Hydraulische randvoorwaarden"; - /// has features when is null; /// the number of hydraulic boundary locations and features in are not the same; /// the point of a hydraulic boundary location and the geometry of a corresponding feature are not the same. /// @@ -91,21 +91,42 @@ Assert.AreEqual("Hydraulische randvoorwaarden", mapData.Name); var hydraulicLocationsMapData = (MapPointData) mapData; - if (hydraulicBoundaryLocations == null) - { - CollectionAssert.IsEmpty(hydraulicLocationsMapData.Features); - } - else - { - HydraulicBoundaryLocation[] hydraulicBoundaryLocationsArray = hydraulicBoundaryLocations.ToArray(); - Assert.AreEqual(hydraulicBoundaryLocationsArray.Length, hydraulicLocationsMapData.Features.Count()); - CollectionAssert.AreEqual(hydraulicBoundaryLocationsArray.Select(hrp => hrp.Location), - hydraulicLocationsMapData.Features.SelectMany(f => f.MapGeometries.First().PointCollections.First())); - } + HydraulicBoundaryLocation[] hydraulicBoundaryLocationsArray = hydraulicBoundaryLocations.ToArray(); + + Assert.AreEqual(hydraulicBoundaryLocationsArray.Length, hydraulicLocationsMapData.Features.Count()); + CollectionAssert.AreEqual(hydraulicBoundaryLocationsArray.Select(hrp => hrp.Location), + hydraulicLocationsMapData.Features.SelectMany(f => f.MapGeometries.First().PointCollections.First())); } /// + /// Asserts whether the contains the data that is representative for the output of + /// . + /// + /// The hydraulic boundary locations that contain the original data. + /// The that needs to be asserted. + /// Thrown when: + /// + /// is not ; + /// the number of hydraulic boundary locations and features in are not the same; + /// the wave height or the design water level of a hydraulic boundary location and the + /// respective outputs of a corresponding feature are not the same. + /// + /// + public static void AssertHydraulicBoundaryLocationOutputsMapData(IEnumerable hydraulicBoundaryLocations, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var hydraulicLocationsMapData = (MapPointData) mapData; + + HydraulicBoundaryLocation[] hydraulicBoundaryLocationsArray = hydraulicBoundaryLocations.ToArray(); + + CollectionAssert.AreEqual(hydraulicBoundaryLocationsArray.Select(hbl => hbl.DesignWaterLevel), + hydraulicLocationsMapData.Features.Select(ft => (RoundedDouble) ft.MetaData["Toetspeil"])); + CollectionAssert.AreEqual(hydraulicBoundaryLocationsArray.Select(hbl => hbl.WaveHeight), + hydraulicLocationsMapData.Features.Select(ft => (RoundedDouble) ft.MetaData["Golfhoogte"])); + } + + /// /// Asserts whether the contains the data that is representative for the . /// /// The reference line that contains the original data.