// Copyright (C) Stichting Deltares 2018. 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 Deltares.Dam.Data;
using Deltares.Dam.Data.DataPlugins.Configuration;
using Deltares.Dam.Data.Importers;
using Deltares.Standard.TestUtils;
namespace Deltares.Dam.Tests
{
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Data.DataPlugins;
[TestFixture]
public class DataPluginImporterDataShapeFileTests
{
const string DirectoryWithCsvFiles = @"..\..\..\data\Dam\Waterboards\Groot Salland\Binnenwaarts\";
const string DirectoryWithDataShapeFiles = @"..\..\..\data\Dam\Waterboards\Groot Salland\Binnenwaarts\GWS\gis-customdata\ShapeFiles\";
private const string Location186Id = "dwp18_6";
private const string Location275Id = "dwp27_5";
private const string Location475Id = "dwp47_5";
List srcDataSources;
DataPluginImporter dataPluginImporter;
[TestFixtureSetUp]
public void TestFixtureSetup()
{
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
}
}
};
dataPluginImporter.SetDataSources("", srcDataSources);
}
[Test]
public void CanRetrieveTrafficLoadFromDataShapeFile()
{
string dikeRingId = dataPluginImporter.GetDikeRingIdList(DamType.Primary).FirstOrDefault();
dataPluginImporter.ImportDataForDikeRings(new List { dikeRingId }, DamType.Primary, null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, Location275Id);
var nameValueParameters = locationDetails as NameValueParameter[] ?? locationDetails.ToArray();
Assert.IsTrue(nameValueParameters.Count() > 0);
Assert.AreEqual("13", nameValueParameters.FirstOrDefault(x => x.ParameterName.Equals("TrafficLoad")).ParameterValue);
}
/*[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(Categories.Slow)]
public void CanRetrievePenetrationLengthFromDataShapeFile()
{
string dikeRingId = dataPluginImporter.GetDikeRingIdList(DamType.Primary).FirstOrDefault();
dataPluginImporter.ImportDataForDikeRings(new List { dikeRingId }, DamType.Primary, null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, Location275Id);
Assert.AreEqual("-1.5", locationDetails.First(
x => x.ParameterName.Equals("PenetrationLength")).ParameterValue);
locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, Location475Id);
Assert.AreEqual("-1", locationDetails.First(
x => x.ParameterName.Equals("PenetrationLength")).ParameterValue);
}
[Test, Ignore("Waiting on proper test file")]
public void CanRetrieveDetrimentFactorFromDataShapeFile()
{
string dikeRingId = dataPluginImporter.GetDikeRingIdList(DamType.Primary).FirstOrDefault();
dataPluginImporter.ImportDataForDikeRings(new List { dikeRingId }, DamType.Primary, null);
IEnumerable locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, Location275Id);
Assert.AreEqual("1.05", locationDetails.First(
x => x.ParameterName.Equals("DetrimentFactor")).ParameterValue);
locationDetails = dataPluginImporter.GetLocationDetails(dikeRingId, Location475Id);
Assert.AreEqual("1.07", locationDetails.First(
x => x.ParameterName.Equals("DetrimentFactor")).ParameterValue);
}
}
}