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