// Copyright (C) Stichting Deltares 2018. 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.Data;
using Core.Common.Base.Geometry;
using Core.Common.Geometry;
using Core.Common.Util;
using Core.Components.Gis.Data;
using Core.Components.Gis.Features;
using Core.Components.Gis.Geometries;
using NUnit.Framework;
using Ringtoets.AssemblyTool.Data;
using Ringtoets.AssemblyTool.Forms;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Forms.TypeConverters;
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 data of
/// hydraulic boundary locations and calculations in .
///
/// The assessment section that contains 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 general properties (such as id, name and location) 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 AssertHydraulicBoundaryLocationsMapData(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.Points.Any())
{
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 meta data that is representative for the .
///
/// The reference line that contains the original data.
/// The assessment section that contains the original data.
/// The that needs to be asserted.
/// Thrown when the meta data does not have the correct values.
public static void AssertReferenceLineMetaData(ReferenceLine referenceLine, IAssessmentSection assessmentSection, MapData mapData)
{
var referenceLineData = (MapLineData)mapData;
MapFeature feature = referenceLineData.Features.Single();
Assert.AreEqual(assessmentSection.Id, feature.MetaData["ID"]);
Assert.AreEqual(assessmentSection.Name, feature.MetaData["Naam"]);
Assert.AreEqual(new RoundedDouble(2, referenceLine.Length), feature.MetaData["Lengte*"]);
}
///
/// 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()));
}
///
/// Asserts whether the contains the data that is representative
/// for the and supplied .
///
/// The expected simple assembly.
/// The expected detailed assembly.
/// The expected tailor made assembly.
/// The expected combined assembly.
/// The that needs to be asserted.
/// The the map data collection belongs to.
/// Thrown when:
///
/// - there is an incorrect amount of items in ;
/// - one of the items in has incorrect properties.
///
///
public static void AssertAssemblyMapDataCollection(FailureMechanismSectionAssembly expectedSimpleAssembly,
FailureMechanismSectionAssembly expectedDetailedAssembly,
FailureMechanismSectionAssembly expectedTailorMadeAssembly,
FailureMechanismSectionAssembly expectedCombinedAssembly,
MapDataCollection assemblyMapData,
IFailureMechanism failureMechanism)
{
IEnumerable assemblyMapDataCollection = assemblyMapData.Collection;
Assert.AreEqual(4, assemblyMapDataCollection.Count());
AssertAssemblyMapData("Toetsoordeel toets op maat", failureMechanism, expectedTailorMadeAssembly, assemblyMapDataCollection.ElementAt(0));
AssertAssemblyMapData("Toetsoordeel gedetailleerde toets", failureMechanism, expectedDetailedAssembly, assemblyMapDataCollection.ElementAt(1));
AssertAssemblyMapData("Toetsoordeel eenvoudige toets", failureMechanism, expectedSimpleAssembly, assemblyMapDataCollection.ElementAt(2));
AssertAssemblyMapData("Gecombineerd toetsoordeel", failureMechanism, expectedCombinedAssembly, assemblyMapDataCollection.ElementAt(3));
}
///
/// Asserts whether the contains the data that is representative
/// for the and supplied .
///
/// The expected simple assembly category.
/// The expected detailed assembly category.
/// The expected tailor made assembly category.
/// The expected combined assembly category.
/// The that needs to be asserted.
/// The the map data collection belongs to.
/// Thrown when:
///
/// - there is an incorrect amount of items in ;
/// - one of the items in has incorrect properties.
///
///
public static void AssertAssemblyMapDataCollection(FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssemblyCategory,
FailureMechanismSectionAssemblyCategoryGroup expectedDetailedAssemblyCategory,
FailureMechanismSectionAssemblyCategoryGroup expectedTailorMadeAssemblyCategory,
FailureMechanismSectionAssemblyCategoryGroup expectedCombinedAssemblyCategory,
MapDataCollection assemblyMapData,
IFailureMechanism failureMechanism)
{
IEnumerable assemblyMapDataCollection = assemblyMapData.Collection;
Assert.AreEqual(4, assemblyMapDataCollection.Count());
AssertAssemblyMapData("Toetsoordeel toets op maat", failureMechanism, expectedTailorMadeAssemblyCategory, assemblyMapDataCollection.ElementAt(0));
AssertAssemblyMapData("Toetsoordeel gedetailleerde toets", failureMechanism, expectedDetailedAssemblyCategory, assemblyMapDataCollection.ElementAt(1));
AssertAssemblyMapData("Toetsoordeel eenvoudige toets", failureMechanism, expectedSimpleAssemblyCategory, assemblyMapDataCollection.ElementAt(2));
AssertAssemblyMapData("Gecombineerd toetsoordeel", failureMechanism, expectedCombinedAssemblyCategory, assemblyMapDataCollection.ElementAt(3));
}
private static void AssertAssemblyMapData(string expectedMapDataName,
IFailureMechanism failureMechanism,
FailureMechanismSectionAssembly expectedAssembly,
MapData mapData)
{
var assemblyMapLineData = (MapLineData) mapData;
Assert.AreEqual(expectedMapDataName, assemblyMapLineData.Name);
MapFeature[] features = assemblyMapLineData.Features.ToArray();
FailureMechanismSection[] sections = failureMechanism.Sections.ToArray();
Assert.AreEqual(sections.Length, features.Length);
for (var index = 0; index < sections.Length; index++)
{
MapFeature feature = features[index];
FailureMechanismSection failureMechanismSection = sections[index];
CollectionAssert.AreEqual(failureMechanismSection.Points, feature.MapGeometries.Single().PointCollections.Single());
Assert.AreEqual(2, feature.MetaData.Count);
Assert.AreEqual(new EnumDisplayWrapper(
DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(expectedAssembly.Group)).DisplayName,
feature.MetaData["Categorie"]);
Assert.AreEqual(new NoProbabilityValueDoubleConverter().ConvertToString(expectedAssembly.Probability),
feature.MetaData["Faalkans"]);
}
}
private static void AssertAssemblyMapData(string expectedMapDataName,
IFailureMechanism failureMechanism,
FailureMechanismSectionAssemblyCategoryGroup expectedCategory,
MapData mapData)
{
var assemblyMapLineData = (MapLineData) mapData;
Assert.AreEqual(expectedMapDataName, assemblyMapLineData.Name);
MapFeature[] features = assemblyMapLineData.Features.ToArray();
FailureMechanismSection[] sections = failureMechanism.Sections.ToArray();
Assert.AreEqual(sections.Length, features.Length);
for (var index = 0; index < sections.Length; index++)
{
MapFeature feature = features[index];
FailureMechanismSection failureMechanismSection = sections[index];
CollectionAssert.AreEqual(failureMechanismSection.Points, feature.MapGeometries.Single().PointCollections.Single());
Assert.AreEqual(1, feature.MetaData.Count);
Assert.AreEqual(new EnumDisplayWrapper(
DisplayFailureMechanismSectionAssemblyCategoryGroupConverter.Convert(expectedCategory)).DisplayName,
feature.MetaData["Categorie"]);
}
}
private static IEnumerable GetWorldPoints(ForeshoreProfile foreshoreProfile)
{
return AdvancedMath2D.FromXToXY(
foreshoreProfile.Geometry.Select(p => -p.X).ToArray(),
foreshoreProfile.WorldReferencePoint,
-foreshoreProfile.X0,
foreshoreProfile.Orientation);
}
}
}