// Copyright (C) Stichting Deltares 2025. 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.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.Dam.Data.Importers;
using NUnit.Framework;
using DataAttribute = Deltares.Dam.Data.DataPlugins.Configuration.DataAttribute;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class DataPluginImporterDataShapeFileTests
{
private const string Location275Id = "dwp27_5";
private const string Location475Id = "dwp47_5";
//Project HHNK_WILMEBREEK does use a cross section shapefile
const string HHNK_WILMEBREEKDirectoryWithCsvFiles = @"TestData\HHNK_WILMEBREEK\CSV Bestanden\";
const string HHNK_WILMEBREEKDirectoryWithDataShapeFiles = @"TestData\HHNK_WILMEBREEK\Shapes\";
private const string Location1Id = "WILM_1";
private const string Location22Id = "WILM_22";
//Project Groot Salland does NOT use a cross section shapefile.
//The values in the data shapefiles are found by coordinates of the locations that are defined in the locations.csv
readonly string DirectoryWithCsvFiles = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\GrootSallandBinnenwaarts\");
readonly string DirectoryWithDataShapeFiles = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\GrootSallandBinnenwaarts\Shapes");
List srcDataSources;
DataPluginImporter dataPluginImporter;
[Test]
public void CanRetrieveTrafficLoadFromDataShapeFile()
{
SetupGrootSalland();
dataPluginImporter.ImportDataForDikeRings(null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(Location275Id);
NameValueParameter[] nameValueParameters = locationDetails as NameValueParameter[] ?? locationDetails.ToArray();
Assert.That(nameValueParameters.Count(), Is.GreaterThan(0));
Assert.That(nameValueParameters.FirstOrDefault(x => x.ParameterName.Equals("TrafficLoad")).ParameterValue, Is.EqualTo("13"));
}
[Test]
public void CanRetrieveTrafficLoadDistributionAngleFromDataShapeFile()
{
SetupGrootSalland();
dataPluginImporter.ImportDataForDikeRings(null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(Location275Id);
NameValueParameter[] nameValueParameters = locationDetails as NameValueParameter[] ?? locationDetails.ToArray();
Assert.That(nameValueParameters.Count(), Is.GreaterThan(0));
Assert.That(nameValueParameters.FirstOrDefault(x => x.ParameterName.Equals("TrafficLoadDistributionAngle")).ParameterValue, Is.EqualTo("0.123"));
}
[Test]
public void CanRetrieveTrafficLoadDistributionAngleFromDataShapeFileInCombinationWithCrossSectionShapeFile()
{
SetupHHNK_WILMEBREEK();
dataPluginImporter.ImportDataForDikeRings(null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(Location1Id);
NameValueParameter[] nameValueParameters = locationDetails as NameValueParameter[] ?? locationDetails.ToArray();
Assert.That(nameValueParameters.Count(), Is.GreaterThan(0));
Assert.That(nameValueParameters.FirstOrDefault(x => x.ParameterName.Equals("TrafficLoadDistributionAngle")).ParameterValue, Is.EqualTo("25"));
locationDetails = dataPluginImporter.GetLocationDetails(Location22Id);
Assert.That(locationDetails.First(
x => x.ParameterName.Equals("TrafficLoadDistributionAngle")).ParameterValue, Is.EqualTo("32"));
}
/*[Test]
public void Import_NoCoverageFoundForPoint_ImporterContinuesAndErrorsAreRetrievable()
{
string dikeRingId = dataPluginImporter.GetDikeRingIdList().FirstOrDefault();
dataPluginImporter.GetLocationDetails(dikeRingId, location18_6Id);
var errors = dataPluginImporter.GetImportErrors();
Assert.IsNotNull(errors);
Assert.IsTrue(errors.Count() > 0);
Assert.IsTrue(errors.Contains());
}
*/
[Test]
[Category("Slow")]
public void CanRetrievePenetrationLengthFromDataShapeFile()
{
SetupGrootSalland();
dataPluginImporter.ImportDataForDikeRings(null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(Location275Id);
Assert.That(locationDetails.First(
x => x.ParameterName.Equals("PenetrationLength")).ParameterValue, Is.EqualTo("-1.5"));
locationDetails = dataPluginImporter.GetLocationDetails(Location475Id);
Assert.That(locationDetails.First(
x => x.ParameterName.Equals("PenetrationLength")).ParameterValue, Is.EqualTo("-1"));
}
private void SetupGrootSalland()
{
srcDataSources = new List
{
new DataSource
{
DataSourceType = DataSourceType.CsvFiles,
DataLocation = DirectoryWithCsvFiles
},
new DataSource
{
DataSourceType = DataSourceType.DataShapeFiles,
DataLocation = DirectoryWithDataShapeFiles
}
};
dataPluginImporter = new DataPluginImporter
{
Attributes = new[]
{
new DataAttribute
{
AttributeId =
LocationShapeFileAttributeMap.TrafficLoadAttributeId
},
new DataAttribute
{
AttributeId =
LocationShapeFileAttributeMap.PenetrationLengthAttributeId
},
new DataAttribute
{
AttributeId =
LocationShapeFileAttributeMap.TrafficLoadDistributionAngleAttributeId
}
}
};
dataPluginImporter.SetDataSources("", srcDataSources);
}
private void SetupHHNK_WILMEBREEK()
{
srcDataSources = new List
{
new DataSource
{
DataSourceType = DataSourceType.CsvFiles,
DataLocation = HHNK_WILMEBREEKDirectoryWithCsvFiles
},
new DataSource
{
DataSourceType = DataSourceType.DataShapeFiles,
DataLocation = HHNK_WILMEBREEKDirectoryWithDataShapeFiles
}
};
dataPluginImporter = new DataPluginImporter
{
Attributes = new[]
{
new DataAttribute
{
AttributeId = LocationShapeFileAttributeMap.LocationAttributeId,
AttributeName = "LocationID",
DataSource = "Locations2.shp"
},
new DataAttribute
{
AttributeId = LocationShapeFileAttributeMap.DikeRingAttributeId,
AttributeName = "DikeringID",
DataSource = "Locations2.shp"
},
new DataAttribute
{
AttributeId = LocationShapeFileAttributeMap.CrossSectionAttributId,
AttributeName = "LocationID",
DataSource = "Crosssections.shp"
},
new DataAttribute
{
AttributeId = LocationShapeFileAttributeMap.TrafficLoadDistributionAngleAttributeId,
AttributeName = "TL_Angle",
DataSource = "TrafficLoad.shp"
}
}
};
dataPluginImporter.SetDataSources("", srcDataSources);
}
}
}