// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic;
using System.Linq;
using Core.Common.Base.Geometry;
using Core.Common.Geometry;
using Core.Components.Gis.Data;
using Core.Components.Gis.Features;
using Core.Components.Gis.Geometries;
using NUnit.Framework;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
namespace Ringtoets.Common.Forms.TestUtil
{
///
/// Class that can be used to test properties of a .
///
public static class MapDataTestHelper
{
///
/// Asserts whether the contains the data that is representative for the .
///
/// The sections that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not "Vakindeling";
/// - the number of sections and features in are not the same;
/// - the points of a section and the geometry of a corresponding feature are not the same.
///
///
public static void AssertFailureMechanismSectionsMapData(IEnumerable sections, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Vakindeling", mapData.Name);
var sectionsMapLinesData = (MapLineData) mapData;
MapFeature[] sectionMapLinesFeatures = sectionsMapLinesData.Features.ToArray();
FailureMechanismSection[] sectionsArray = sections.ToArray();
Assert.AreEqual(sectionsArray.Length, sectionMapLinesFeatures.Length);
for (var index = 0; index < sectionsArray.Length; index++)
{
MapGeometry geometry = sectionMapLinesFeatures[index].MapGeometries.First();
FailureMechanismSection failureMechanismSection = sectionsArray[index];
CollectionAssert.AreEquivalent(failureMechanismSection.Points, geometry.PointCollections.First());
}
}
///
/// Asserts whether the contains the data that is representative for the .
///
/// The hydraulic boundary locations that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not "Hydraulische randvoorwaarden";
/// - 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.
///
///
public static void AssertHydraulicBoundaryLocationsMapData(IEnumerable hydraulicBoundaryLocations, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Hydraulische randvoorwaarden", mapData.Name);
var hydraulicLocationsMapData = (MapPointData) mapData;
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 calculation results 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();
int expectedNrOfFeatures = hydraulicBoundaryLocationsArray.Length;
Assert.AreEqual(expectedNrOfFeatures, hydraulicLocationsMapData.Features.Count());
for (var i = 0; i < expectedNrOfFeatures; i++)
{
HydraulicBoundaryLocation hydraulicBoundaryLocation = hydraulicBoundaryLocationsArray[i];
MapFeature mapFeature = hydraulicLocationsMapData.Features.ElementAt(i);
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.DesignWaterLevelCalculation1,
mapFeature,
"h(A+->A)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.DesignWaterLevelCalculation2,
mapFeature,
"h(A->B)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.DesignWaterLevelCalculation3,
mapFeature,
"h(B->C)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.DesignWaterLevelCalculation4,
mapFeature,
"h(C->D)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.WaveHeightCalculation1,
mapFeature,
"Hs(A+->A)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.WaveHeightCalculation2,
mapFeature,
"Hs(A->B)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.WaveHeightCalculation3,
mapFeature,
"Hs(B->C)");
MapFeaturesTestHelper.AssertHydraulicBoundaryLocationOutputMetaData(hydraulicBoundaryLocation.WaveHeightCalculation4,
mapFeature,
"Hs(C->D)");
}
}
///
/// Asserts whether the contains the data that is representative for the data of
/// hydraulic boundary locations and calculations in .
///
/// The assessment section 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 calculation results of a hydraulic boundary location and the
/// respective outputs of a corresponding feature are not the same.
///
///
public static void AssertHydraulicBoundaryLocationOutputsMapData(IAssessmentSection assessmentSection, MapData mapData)
{
Assert.IsInstanceOf(mapData);
var hydraulicLocationsMapData = (MapPointData) mapData;
MapFeaturesTestHelper.AssertHydraulicBoundaryFeaturesData(assessmentSection, hydraulicLocationsMapData.Features);
}
///
/// Asserts whether the contains the data that is representative for the .
///
/// The reference line that contains the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not "Referentielijn";
/// - has features when is null;
/// - has more than one feature;
/// - the points of the reference line and the geometry of the first feature are not the same.
///
///
public static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Referentielijn", mapData.Name);
var referenceLineData = (MapLineData) mapData;
if (referenceLine == null)
{
CollectionAssert.IsEmpty(referenceLineData.Features);
}
else
{
Assert.AreEqual(1, referenceLineData.Features.Count());
CollectionAssert.AreEqual(referenceLine.Points, referenceLineData.Features.First().MapGeometries.First().PointCollections.First());
}
}
///
/// Asserts whether the contains the data that is representative for the start points of the .
///
/// The sections that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not "Vakindeling (startpunten)";
/// - has more than one feature;
/// - the start points of the sections and the geometry of the first feature are not the same.
///
///
public static void AssertFailureMechanismSectionsStartPointMapData(IEnumerable sections, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Vakindeling (startpunten)", mapData.Name);
var sectionsStartPointData = (MapPointData) mapData;
Assert.AreEqual(1, sectionsStartPointData.Features.Count());
CollectionAssert.AreEqual(sections.Select(s => s.StartPoint), sectionsStartPointData.Features.First().MapGeometries.First().PointCollections.First());
}
///
/// Asserts whether the contains the data that is representative for the end points of the .
///
/// The sections that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not "Vakindeling (eindpunten)";
/// - has more than one feature;
/// - the end points of the sections and the geometry of the first feature are not the same.
///
///
public static void AssertFailureMechanismSectionsEndPointMapData(IEnumerable sections, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Vakindeling (eindpunten)", mapData.Name);
var sectionsEndPointData = (MapPointData) mapData;
Assert.AreEqual(1, sectionsEndPointData.Features.Count());
CollectionAssert.AreEqual(sections.Select(s => s.EndPoint), sectionsEndPointData.Features.First().MapGeometries.First().PointCollections.First());
}
///
/// Asserts whether the contains the data that is representative for the .
///
/// The foreshore profiles that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not ;
/// - the name of the is not Voorlandprofielen;
/// - the amount of features in is not equal to the length of the ;
/// - the geometries of the features in are not equal to the expected geometry of the .
///
///
public static void AssertForeshoreProfilesMapData(IEnumerable foreshoreProfiles, MapData mapData)
{
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Voorlandprofielen", mapData.Name);
var foreshoreProfilesData = (MapLineData) mapData;
ForeshoreProfile[] foreshoreProfileArray = foreshoreProfiles.ToArray();
Assert.AreEqual(foreshoreProfileArray.Length, foreshoreProfilesData.Features.Count());
for (var i = 0; i < foreshoreProfileArray.Length; i++)
{
IEnumerable expectedGeometry = GetWorldPoints(foreshoreProfileArray[i]);
MapGeometry profileDataA = foreshoreProfilesData.Features.ElementAt(i).MapGeometries.First();
CollectionAssert.AreEquivalent(expectedGeometry, profileDataA.PointCollections.First());
}
}
///
/// Asserts whether the contains the data that is representative for the .
///
/// The that contains the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not of the expected type;
/// - one of the properties of is not equal to .
///
///
public static void AssertImageBasedMapData(BackgroundData backgroundData, ImageBasedMapData imageBasedMapData)
{
Assert.AreEqual(backgroundData.Name, imageBasedMapData.Name);
Assert.AreEqual(backgroundData.IsVisible, imageBasedMapData.IsVisible);
Assert.AreEqual(backgroundData.Transparency, imageBasedMapData.Transparency);
var wmtsBackgroundDataConfiguration = backgroundData.Configuration as WmtsBackgroundDataConfiguration;
if (wmtsBackgroundDataConfiguration != null)
{
Assert.IsInstanceOf(imageBasedMapData);
var wmtsMapData = (WmtsMapData) imageBasedMapData;
Assert.AreEqual(wmtsBackgroundDataConfiguration.PreferredFormat, wmtsMapData.PreferredFormat);
Assert.AreEqual(wmtsBackgroundDataConfiguration.SelectedCapabilityIdentifier, wmtsMapData.SelectedCapabilityIdentifier);
Assert.AreEqual(wmtsBackgroundDataConfiguration.SourceCapabilitiesUrl, wmtsMapData.SourceCapabilitiesUrl);
Assert.AreEqual(wmtsBackgroundDataConfiguration.IsConfigured, wmtsMapData.IsConfigured);
return;
}
var wellKnownBackgroundDataConfiguration = backgroundData.Configuration as WellKnownBackgroundDataConfiguration;
if (wellKnownBackgroundDataConfiguration != null)
{
Assert.IsInstanceOf(imageBasedMapData);
var wellKnownTileSourceMapData = (WellKnownTileSourceMapData) imageBasedMapData;
Assert.AreEqual(wellKnownBackgroundDataConfiguration.WellKnownTileSource, (RingtoetsWellKnownTileSource) wellKnownTileSourceMapData.TileSource);
Assert.IsTrue(wellKnownTileSourceMapData.IsConfigured);
return;
}
Assert.Fail("Unsupported background configuration.");
}
///
/// Asserts whether the contains the data that is representative
/// for the .
///
/// The structures that contain the original data.
/// The that needs to be asserted.
/// Thrown when:
///
/// - is not an instance of ;
/// - is null.
/// - the name of the is not Kunstwerken;
/// - the amount of features in is not equal to the
/// amount of the ;
/// - the geometries of the features in are not equal to
/// the expected geometry of the .
///
///
public static void AssertStructuresMapData(IEnumerable structures, MapData mapData)
{
Assert.NotNull(structures);
Assert.IsInstanceOf(mapData);
Assert.AreEqual("Kunstwerken", mapData.Name);
var structuresData = (MapPointData) mapData;
StructureBase[] structuresArray = structures.ToArray();
Assert.AreEqual(structuresArray.Length, structuresData.Features.Count());
CollectionAssert.AreEqual(structuresArray.Select(hrp => hrp.Location),
structuresData.Features.SelectMany(f => f.MapGeometries.First().PointCollections.First()));
}
private static IEnumerable GetWorldPoints(ForeshoreProfile foreshoreProfile)
{
return AdvancedMath2D.FromXToXY(
foreshoreProfile.Geometry.Select(p => -p.X).ToArray(),
foreshoreProfile.WorldReferencePoint,
-foreshoreProfile.X0,
foreshoreProfile.Orientation);
}
}
}