// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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.Collections.Generic; using System.IO; using System.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.DataPlugins; using Deltares.Dam.Data.DataPlugins.Configuration; using Deltares.Geometry; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DataPluginImporterCsvTests { private const string location18_6Id = "dwp18_6"; private const string segment05_4Id = "segment_dijkring10_dwp05_4"; private const string surfaceline40_0Id = "dijkring10_dwp40_0"; private const string soilprofile10Y_149_STBI_pId = "10Y_149_STBI_p"; readonly string directoryWithCsvFiles = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\GrootSallandBinnenwaarts\"); List srcDataSources; DataPluginImporter dataPluginImporter; [SetUp] public void TestFixtureSetup() { srcDataSources = new List(); srcDataSources.Add(new DataSource { DataSourceType = DataSourceType.CsvFiles, DataLocation = directoryWithCsvFiles }); dataPluginImporter = new DataPluginImporter(); dataPluginImporter.SetDataSources("", srcDataSources); } [Test] [Category("Slow")] public void CanImportDikeData() { IEnumerable dikeList = dataPluginImporter.GetDikeRingIdList(); Assert.That(dikeList.Count(), Is.EqualTo(1)); string dikeRingId = dikeList.FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); Info dikeInfo = dataPluginImporter.GetDikeRingInfo(dikeRingId); Assert.That(dikeInfo.Name, Is.EqualTo("dijkring10")); } [Test] public void CanRetrieveLocationData() { string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); IEnumerable locationIdList = dataPluginImporter.GetLocationIdList(dikeRingId); Assert.That(locationIdList.Count(), Is.EqualTo(24)); Info locationInfo = dataPluginImporter.GetLocationInfo(dikeRingId, location18_6Id); Assert.That(locationInfo.Name, Is.EqualTo(location18_6Id)); IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, location18_6Id); Assert.That(locationDetails.Any(), Is.True); Assert.That(locationDetails.FirstOrDefault(x => x.ParameterName.Equals("SurfaceLineId")).ParameterValue, Is.EqualTo("dijkring10_dwp18_6")); Assert.That(locationDetails.FirstOrDefault(x => x.ParameterName.Equals("SegmentId")).ParameterValue, Is.EqualTo("segment_dijkring10_dwp18_6")); Assert.That(locationDetails.FirstOrDefault(x => x.ParameterName.Equals("XRd")).ParameterValue, Is.EqualTo("192584.1")); Assert.That(locationDetails.FirstOrDefault(x => x.ParameterName.Equals("YRd")).ParameterValue, Is.EqualTo("511740.3")); } [Test] public void CanRetrieveSegmentData() { string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); IEnumerable segmentIdList = dataPluginImporter.GetSegmentIdList(dikeRingId); Assert.That(segmentIdList.Count(), Is.EqualTo(24)); IEnumerable segmentProfile1DIdList = dataPluginImporter.GetProfile1DIdListForSegment(dikeRingId, segment05_4Id, FailureMechanismSystemType.StabilityInside); Assert.That(segmentProfile1DIdList.Count(), Is.EqualTo(0)); IEnumerable segmentProfile2DIdList = dataPluginImporter.GetProfile2DIdListForSegment(dikeRingId, segment05_4Id, FailureMechanismSystemType.StabilityInside); Assert.That(segmentProfile2DIdList.Count(), Is.EqualTo(1)); string soilProfile2DId = segmentProfile2DIdList.FirstOrDefault(); Assert.That(soilProfile2DId, Is.EqualTo("10Y_054_STBI.sti")); IEnumerable profileDetails = dataPluginImporter.GetSegmentProfile2DDetails(dikeRingId, segment05_4Id, soilProfile2DId, FailureMechanismSystemType.StabilityInside); Assert.That(profileDetails.FirstOrDefault(x => x.ParameterName.Equals("Probability")).ParameterValue, Is.EqualTo("100")); Assert.That(profileDetails.FirstOrDefault(x => x.ParameterName.Equals("FailureMechanismType")).ParameterValue, Is.EqualTo("StabilityInside")); } [Test] public void CanRetrieveSurfaceLines() { const double cToleranceCoordinate = 0.001; // Check if surfacelines available string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); IEnumerable surfaceLineIdList = dataPluginImporter.GetSurfaceLineIdList(dikeRingId); Assert.That(surfaceLineIdList.Count(), Is.EqualTo(13)); // Check begin- and endpoint of 1 surfaceline IList surfaceLinePoints = dataPluginImporter.GetSurfaceLinePoints(dikeRingId, surfaceline40_0Id); Assert.That(surfaceLinePoints.Count(), Is.GreaterThan(0)); Assert.That(surfaceLinePoints[0].X, Is.EqualTo(0.0).Within(cToleranceCoordinate)); Assert.That(surfaceLinePoints[0].Y, Is.EqualTo(0.0).Within(cToleranceCoordinate)); Assert.That(surfaceLinePoints[0].Z, Is.EqualTo(-0.48).Within(cToleranceCoordinate)); int lastPointIndex = surfaceLinePoints.Count() - 1; Assert.That(surfaceLinePoints[lastPointIndex].X, Is.EqualTo(71.25).Within(cToleranceCoordinate)); Assert.That(surfaceLinePoints[lastPointIndex].Y, Is.EqualTo(0.0).Within(cToleranceCoordinate)); Assert.That(surfaceLinePoints[lastPointIndex].Z, Is.EqualTo(-0.36).Within(cToleranceCoordinate)); // Check specific characteristic points of 1 surfaceline IEnumerable surfaceLineCharacteristicPoints = dataPluginImporter.GetSurfaceLineCharacteristicPoints(dikeRingId, surfaceline40_0Id); Assert.That(surfaceLineIdList.Count(), Is.EqualTo(13)); Assert.That(surfaceLineCharacteristicPoints.Count(), Is.GreaterThan(0)); DpCharacteristicPoint pointSurfaceLevelOutside = surfaceLineCharacteristicPoints.Where(x => x.Id.Equals("SurfaceLevelInside")).FirstOrDefault(); Assert.That(pointSurfaceLevelOutside.X, Is.EqualTo(71.25).Within(cToleranceCoordinate)); Assert.That(pointSurfaceLevelOutside.Y, Is.EqualTo(0.0).Within(cToleranceCoordinate)); Assert.That(pointSurfaceLevelOutside.Z, Is.EqualTo(-0.36).Within(cToleranceCoordinate)); DpCharacteristicPoint pointDitchPolderSide = surfaceLineCharacteristicPoints.Where(x => x.Id.Equals("DitchPolderSide")).FirstOrDefault(); Assert.That(pointDitchPolderSide.Id, Is.Null); } [Test] public void CanRetrieveSoilProfile1Ds() { const double cToleranceCoordinate = 0.001; // Check if soilprofiles available string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); IEnumerable soilProfile1DIdList = dataPluginImporter.GetSoilProfile1DIdList(dikeRingId); Assert.That(soilProfile1DIdList.Count(), Is.EqualTo(26)); DpSoilProfile soilProfile = dataPluginImporter.GetSoilProfile1DDetails(dikeRingId, soilprofile10Y_149_STBI_pId); Assert.That(soilProfile.Layers.Count(), Is.EqualTo(4)); Assert.That(soilProfile.Layers[0].TopLevel, Is.EqualTo(60.0).Within(cToleranceCoordinate)); Assert.That(soilProfile.Layers[0].SoilName, Is.EqualTo("klei")); Assert.That(soilProfile.Layers[1].TopLevel, Is.EqualTo(-3.2).Within(cToleranceCoordinate)); Assert.That(soilProfile.Layers[1].SoilName, Is.EqualTo("veen")); Assert.That(soilProfile.Layers[2].TopLevel, Is.EqualTo(-5.0).Within(cToleranceCoordinate)); Assert.That(soilProfile.Layers[2].SoilName, Is.EqualTo("WL_zand")); Assert.That(soilProfile.Layers[3].TopLevel, Is.EqualTo(-25.0).Within(cToleranceCoordinate)); Assert.That(soilProfile.Layers[3].SoilName, Is.EqualTo("DummyForBottomLevel")); } [Test] public void CanRetrieveScenarios() { const double cToleranceDimension = 0.001; string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault(); dataPluginImporter.ImportDataForDikeRings(null); List scenarioList = dataPluginImporter.GetScenarioList(dikeRingId, location18_6Id).ToList(); Assert.That(scenarioList.Count(), Is.EqualTo(1)); IEnumerable scenarioDetails = dataPluginImporter.GetScenarioDetails(dikeRingId, location18_6Id, "1"); foreach (NameValueParameter nameValue in scenarioDetails) { switch (nameValue.ParameterName) { case "WaterLevel": Assert.That(Convert.ToDouble(nameValue.ParameterValue), Is.EqualTo(1.5).Within(cToleranceDimension)); break; case "DikeTableHeight": Assert.That(Convert.ToDouble(nameValue.ParameterValue), Is.EqualTo(2).Within(cToleranceDimension)); break; } } } } }