// 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.CsvImporters;
using Deltares.Dam.Data.Importers;
using Deltares.Maps;
using NetTopologySuite.Geometries;
using NUnit.Framework;
using NSubstitute;
namespace Deltares.Dam.Tests.Importers
{
[TestFixture]
public class LocationPropertyImporterTest
{
private const string TestShapeFile = "trafficload.shp";
private readonly string DirectoryWithDataShapeFiles = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\GrootSallandBinnenwaarts\Shapes\");
private LocationPropertyImporter importer;
[Test]
public void Register_AttributeArgumentNull_Throws()
{
Assert.That(() => importer.RegisterAttributeMapping(null, "test", "test"), Throws.ArgumentException);
}
[Test]
public void CheckingIfAttributeIdIsSupported_UsingHeadPL3LowerCase_ShouldReturnThatItIsSupported()
{
const bool expectedValue = true;
const string attributeId = "head_pl3";
bool actualValue = LocationShapeFileAttributeMap.IsAttributeIdSupported(attributeId);
Assert.That(actualValue, Is.EqualTo(expectedValue));
}
[Test]
public void IsPropertyAttribute_UsingLocationID_ReturnsFalse()
{
Assert.That(LocationShapeFileAttributeMap.IsPropertyAttribute(LocationShapeFileAttributeMap.LocationAttributeId), Is.False);
Assert.That(LocationShapeFileAttributeMap.IsPropertyAttribute("Location_Id"), Is.False);
}
[Test]
public void Register_RequiredFileNotFound_Throws()
{
Assert.That(() => importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, "somefile.shp"), Throws.InstanceOf());
}
[Test]
public void Import_NoTargetLocationsSet_Throws()
{
Assert.That(() => importer.Import(null), Throws.InvalidOperationException);
}
[Test]
[Category("Integration")]
public void Import_AllPropertiesUsingPolygonAttributeImporter_CorrectValuesShouldBeSetOnTarget()
{
const string stringInitialValue = "someValue";
const double doubleInitialValue = 99.9;
const bool boolInitialValue = false;
const PLLineCreationMethod plLineCreationMethodInitialValue = PLLineCreationMethod.ExpertKnowledgeRRD;
const string stringTestValue = "testValue";
const double doubleTestValue = 111.1;
const bool boolTestValue = true;
const PLLineCreationMethod plLineCreationMethodTestValue = PLLineCreationMethod.GaugesWithFallbackToExpertKnowledgeRRD;
const MStabZonesType mstabZonesTypeTestValue = MStabZonesType.ForbiddenZone;
const StabilityDesignMethod stabilityDesignMethodTestValue = StabilityDesignMethod.OptimizedSlopeAndShoulderAdaption;
var mockImporter = Substitute.For();
var attributeRepository = Substitute.For();
var supportedAttributes = new List();
var square = new Polygon(new LinearRing(new[]
{
new Coordinate(-1, 1),
new Coordinate(1, 1),
new Coordinate(1, -1),
new Coordinate(-1, -1),
new Coordinate(-1, 1)
}));
var geom = Feature.Create(square);
foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys)
{
LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(key);
supportedAttributes.Add(mapping.Name);
if (key.Equals(LocationShapeFileAttributeMap.SegmentAttributeId, StringComparison.InvariantCultureIgnoreCase) ||
key.Equals(LocationShapeFileAttributeMap.DikeEmbankmentMaterialAttributeId, StringComparison.InvariantCultureIgnoreCase) ||
key.Equals(LocationShapeFileAttributeMap.ShoulderEmbankmentMaterialAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
geom.AddAttribute(mapping.Name, stringTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.PlLineCreationMethodAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
geom.AddAttribute(mapping.Name, plLineCreationMethodTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.ZoneTypeAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
geom.AddAttribute(mapping.Name, mstabZonesTypeTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.StabilityDesignMethodAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
geom.AddAttribute(mapping.Name, stabilityDesignMethodTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.IntrusionVerticalWaterPressureAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
geom.AddAttribute(mapping.Name, IntrusionVerticalWaterPressureType.Standard);
}
else
{
geom.AddAttribute(mapping.Name, doubleTestValue);
}
}
attributeRepository.SupportedAttributes.Returns(supportedAttributes);
attributeRepository.Features.Returns(new[]
{
geom
});
attributeRepository.Query(Arg.Any()).Returns(new[]
{
geom
});
const string locationId = "Test_Location_01";
var location = new CsvImporterLocations.LocationRecord
{
LocationId = locationId,
GeoX = 1,
GeoY = 1,
SegmentId = stringInitialValue,
DampingFactorPl3 = doubleInitialValue,
DampingFactorPl4 = doubleInitialValue,
DikeEmbankmentMaterial = stringInitialValue,
DistanceToEntryPoint = doubleInitialValue,
HeadPl2 = doubleInitialValue,
HeadPl3 = doubleInitialValue,
HeadPl4 = doubleInitialValue,
MinimalCircleDepth = doubleInitialValue,
PenetrationLength = doubleInitialValue,
PolderLevel = doubleInitialValue,
PLLineCreationMethod = plLineCreationMethodInitialValue,
PlLineOffsetBelowDikeTopAtRiver = doubleInitialValue,
PlLineOffsetBelowDikeTopAtPolder = doubleInitialValue,
PlLineOffsetBelowShoulderBaseInside = doubleInitialValue,
PlLineOffsetBelowDikeToeAtPolder = doubleInitialValue,
RequiredSafetyFactorPiping = doubleInitialValue,
RequiredSafetyFactorStabilityInnerSlope = doubleInitialValue,
RequiredSafetyFactorStabilityOuterSlope = doubleInitialValue,
UpliftCriterionPiping = doubleInitialValue,
UpliftCriterionStability = doubleInitialValue,
TrafficLoad = doubleInitialValue,
TL_DegreeOfConsolidation = doubleInitialValue,
ShoulderEmbankmentMaterial = stringInitialValue,
StabilityShoulderGrowSlope = doubleInitialValue,
StabilityShoulderGrowDeltaX = doubleInitialValue,
StabilitySlopeAdaptionDeltaX = doubleInitialValue,
XSoilGeometry2DOrigin = doubleInitialValue,
StabilityZoneType = MStabZonesType.NoZones,
ForbiddenZoneFactor = doubleInitialValue,
UseNewDikeTopWidth = boolInitialValue,
NewDikeTopWidth = doubleInitialValue,
UseNewDikeSlopeInside = boolInitialValue,
NewDikeSlopeInside = doubleInitialValue,
UseNewDikeSlopeOutside = boolInitialValue,
NewDikeSlopeOutside = doubleInitialValue,
UseNewShoulderTopSlope = boolInitialValue,
NewShoulderTopSlope = doubleInitialValue,
UseNewShoulderBaseSlope = boolInitialValue,
NewShoulderBaseSlope = doubleInitialValue,
UseNewMaxHeightShoulderAsFraction = boolInitialValue,
NewMaxHeightShoulderAsFraction = doubleInitialValue,
UseNewMinDistanceDikeToeStartDitch = boolInitialValue,
NewMinDistanceDikeToeStartDitch = doubleInitialValue,
UseNewDitchDefinition = boolInitialValue,
NewWidthDitchBottom = doubleInitialValue,
NewDepthDitch = doubleInitialValue,
NewSlopeAngleDitch = doubleInitialValue,
DikeTableHeight = doubleInitialValue,
RiverLevel = doubleInitialValue,
RiverLevelLow = doubleInitialValue
};
mockImporter.Targets = new List
{
location
};
var file = new ShapeFileLocation("test.shp");
string[] lines =
{
"First line",
"Second line",
"Third line"
};
File.WriteAllLines(file.FullPath, lines);
mockImporter.GetFile(Arg.Any()).Returns(file);
mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository);
foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys)
{
mockImporter.RegisterAttributeMapping(key, null);
}
mockImporter.Import(null);
Assert.That(location.SegmentId, Is.EqualTo(stringTestValue));
Assert.That(location.DampingFactorPl3, Is.EqualTo(doubleTestValue));
Assert.That(location.DampingFactorPl4, Is.EqualTo(doubleTestValue));
Assert.That(location.DikeEmbankmentMaterial, Is.EqualTo(stringTestValue));
Assert.That(location.DistanceToEntryPoint, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl2, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl3, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl4, Is.EqualTo(doubleTestValue));
Assert.That(location.MinimalCircleDepth, Is.EqualTo(doubleTestValue));
Assert.That(location.PenetrationLength, Is.EqualTo(doubleTestValue));
Assert.That(location.PolderLevel, Is.EqualTo(doubleTestValue));
Assert.That(location.PLLineCreationMethod, Is.EqualTo(plLineCreationMethodTestValue));
Assert.That(location.PlLineOffsetBelowDikeTopAtRiver, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowDikeTopAtPolder, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowShoulderBaseInside, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowDikeToeAtPolder, Is.EqualTo(doubleTestValue));
Assert.That(location.TrafficLoad, Is.EqualTo(doubleTestValue));
Assert.That(location.TL_DegreeOfConsolidation, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorPiping, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorStabilityInnerSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorStabilityOuterSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.ShoulderEmbankmentMaterial, Is.EqualTo(stringTestValue));
Assert.That(location.StabilityShoulderGrowSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityShoulderGrowDeltaX, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilitySlopeAdaptionDeltaX, Is.EqualTo(doubleTestValue));
Assert.That(location.UpliftCriterionPiping, Is.EqualTo(doubleTestValue));
Assert.That(location.UpliftCriterionStability, Is.EqualTo(doubleTestValue));
Assert.That(location.XSoilGeometry2DOrigin, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityZoneType, Is.EqualTo(mstabZonesTypeTestValue));
Assert.That(location.ForbiddenZoneFactor, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewDikeTopWidth, Is.EqualTo(boolTestValue));
Assert.That(location.NewDikeTopWidth, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewDikeSlopeInside, Is.EqualTo(boolTestValue));
Assert.That(location.NewDikeSlopeInside, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewDikeSlopeOutside, Is.EqualTo(boolTestValue));
Assert.That(location.NewDikeSlopeOutside, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewShoulderTopSlope, Is.EqualTo(boolTestValue));
Assert.That(location.NewShoulderTopSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewShoulderBaseSlope, Is.EqualTo(boolTestValue));
Assert.That(location.NewShoulderBaseSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewMaxHeightShoulderAsFraction, Is.EqualTo(boolTestValue));
Assert.That(location.NewMaxHeightShoulderAsFraction, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewMinDistanceDikeToeStartDitch, Is.EqualTo(boolTestValue));
Assert.That(location.NewMinDistanceDikeToeStartDitch, Is.EqualTo(doubleTestValue));
Assert.That(location.UseNewDitchDefinition, Is.EqualTo(boolTestValue));
Assert.That(location.NewWidthDitchBottom, Is.EqualTo(doubleTestValue));
Assert.That(location.NewDepthDitch, Is.EqualTo(doubleTestValue));
Assert.That(location.NewSlopeAngleDitch, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityDesignMethod, Is.EqualTo(stabilityDesignMethodTestValue));
Assert.That(location.SlopeAdaptionStartCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.SlopeAdaptionEndCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.SlopeAdaptionStepCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.DikeTableHeight, Is.EqualTo(doubleTestValue));
Assert.That(location.RiverLevel, Is.EqualTo(doubleTestValue));
Assert.That(location.RiverLevelLow, Is.EqualTo(doubleTestValue));
}
[Test]
[Category("Integration")]
public void Import_AllPropertiesUsingLineAttributeImporter_CorrectValuesShouldBeSetOnTarget()
{
const string stringInitialValue = "someValue";
const double doubleInitialValue = 99.9;
const PLLineCreationMethod plLineCreationMethodInitialValue = PLLineCreationMethod.ExpertKnowledgeRRD;
const MStabZonesType mstabZonesTypeTestValue = MStabZonesType.ForbiddenZone;
const StabilityDesignMethod stabilityDesignMethodTestValue = StabilityDesignMethod.SlopeAdaptionBeforeShoulderAdaption;
const IntrusionVerticalWaterPressureType intrusionVerticalWaterPressureTestValue = IntrusionVerticalWaterPressureType.Standard;
const string stringTestValue = "testValue";
const double doubleTestValue = 111.1;
const double dampingPl3Value = 0.34;
const PLLineCreationMethod plLineCreationMethodTestValue = PLLineCreationMethod.GaugesWithFallbackToExpertKnowledgeRRD;
var mockImporter = Substitute.For();
var attributeRepository = Substitute.For();
var crossSectionRepository = Substitute.For();
var supportedAttributes = new List();
var crossSection = Feature.Create(new LineString(new[]
{
new Coordinate(-1, 0),
new Coordinate(1, 0)
}));
var attributeLine = Feature.Create(new LineString(new[]
{
new Coordinate(0, -1),
new Coordinate(0, 1)
}));
foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys)
{
LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(key);
supportedAttributes.Add(mapping.Name);
if (key.Equals(LocationShapeFileAttributeMap.SegmentAttributeId, StringComparison.InvariantCultureIgnoreCase) ||
key.Equals(LocationShapeFileAttributeMap.DikeEmbankmentMaterialAttributeId, StringComparison.InvariantCultureIgnoreCase) ||
key.Equals(LocationShapeFileAttributeMap.ShoulderEmbankmentMaterialAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, stringTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.PlLineCreationMethodAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, plLineCreationMethodTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.ZoneTypeAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, mstabZonesTypeTestValue);
}
// TODO this property is not specifically set for Import_AllPropertiesUsingPolygonAttributeImporter_CorrectValuesShouldBeSetOnTarget
else if (key.Equals(LocationShapeFileAttributeMap.DampingFactorPl3AttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, dampingPl3Value);
}
else if (key.Equals(LocationShapeFileAttributeMap.StabilityDesignMethodAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, stabilityDesignMethodTestValue);
}
else if (key.Equals(LocationShapeFileAttributeMap.IntrusionVerticalWaterPressureAttributeId, StringComparison.InvariantCultureIgnoreCase))
{
attributeLine.AddAttribute(mapping.Name, intrusionVerticalWaterPressureTestValue);
}
else
{
attributeLine.AddAttribute(mapping.Name, doubleTestValue);
}
}
const string locationId = "Test_Location_01";
var location = new CsvImporterLocations.LocationRecord
{
LocationId = locationId,
GeoX = 1,
GeoY = 1,
SegmentId = stringInitialValue,
DampingFactorPl3 = doubleInitialValue,
DampingFactorPl4 = doubleInitialValue,
DikeEmbankmentMaterial = stringInitialValue,
DistanceToEntryPoint = doubleInitialValue,
HeadPl2 = doubleInitialValue,
HeadPl3 = dampingPl3Value,
HeadPl4 = doubleInitialValue,
MinimalCircleDepth = doubleInitialValue,
PenetrationLength = doubleInitialValue,
PolderLevel = doubleInitialValue,
PLLineCreationMethod = plLineCreationMethodInitialValue,
PlLineOffsetBelowDikeTopAtRiver = doubleInitialValue,
PlLineOffsetBelowDikeTopAtPolder = doubleInitialValue,
PlLineOffsetBelowShoulderBaseInside = doubleInitialValue,
PlLineOffsetBelowDikeToeAtPolder = doubleInitialValue,
RequiredSafetyFactorPiping = doubleInitialValue,
RequiredSafetyFactorStabilityInnerSlope = doubleInitialValue,
RequiredSafetyFactorStabilityOuterSlope = doubleInitialValue,
UpliftCriterionPiping = doubleInitialValue,
UpliftCriterionStability = doubleInitialValue,
TrafficLoad = doubleInitialValue,
TL_DegreeOfConsolidation = doubleInitialValue,
ShoulderEmbankmentMaterial = stringInitialValue,
StabilityShoulderGrowSlope = doubleInitialValue,
StabilityShoulderGrowDeltaX = doubleInitialValue,
StabilitySlopeAdaptionDeltaX = doubleInitialValue,
XSoilGeometry2DOrigin = doubleInitialValue,
StabilityZoneType = MStabZonesType.NoZones,
SlopeDampingPiezometricHeightPolderSide = doubleInitialValue,
IntrusionVerticalWaterPressure = IntrusionVerticalWaterPressureType.Standard,
DikeTableHeight = doubleInitialValue,
RiverLevel = doubleInitialValue,
RiverLevelLow = doubleInitialValue
};
mockImporter.Targets = new List
{
location
};
mockImporter.GetCrossSectionRepository(Arg.Any()).Returns(crossSectionRepository);
LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId);
crossSection.AddAttribute(crossSectionMapping.Name, locationId);
crossSectionRepository.Features.Returns(new[]
{
crossSection
});
mockImporter.GetAttributeName(Arg.Any()).Returns(crossSectionMapping.Name);
attributeRepository.SupportedAttributes.Returns(supportedAttributes);
attributeRepository.Features.Returns(new[]
{
attributeLine
});
attributeRepository.Query(Arg.Any()).Returns(new[]
{
attributeLine
});
var file = new ShapeFileLocation("test.shp");
string[] lines =
{
"First line",
"Second line",
"Third line"
};
File.WriteAllLines(file.FullPath, lines);
mockImporter.GetFile(Arg.Any()).Returns(file);
mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository);
// file.
foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys)
{
mockImporter.RegisterAttributeMapping(key, null);
}
mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File);
mockImporter.Import(null);
Assert.That(location.SegmentId, Is.EqualTo(stringTestValue));
Assert.That(location.DampingFactorPl3, Is.EqualTo(dampingPl3Value));
Assert.That(location.DampingFactorPl4, Is.EqualTo(0)); // as testvalue is beyond the limits, its reset to 0
Assert.That(location.DikeEmbankmentMaterial, Is.EqualTo(stringTestValue));
Assert.That(location.DistanceToEntryPoint, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl2, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl3, Is.EqualTo(doubleTestValue));
Assert.That(location.HeadPl4, Is.EqualTo(doubleTestValue));
Assert.That(location.MinimalCircleDepth, Is.EqualTo(doubleTestValue));
Assert.That(location.PenetrationLength, Is.EqualTo(doubleTestValue));
Assert.That(location.PolderLevel, Is.EqualTo(doubleTestValue));
Assert.That(location.PLLineCreationMethod, Is.EqualTo(plLineCreationMethodTestValue));
Assert.That(location.PlLineOffsetBelowDikeTopAtRiver, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowDikeTopAtPolder, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowShoulderBaseInside, Is.EqualTo(doubleTestValue));
Assert.That(location.PlLineOffsetBelowDikeToeAtPolder, Is.EqualTo(doubleTestValue));
Assert.That(location.TrafficLoad, Is.EqualTo(doubleTestValue));
Assert.That(location.TL_DegreeOfConsolidation, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorPiping, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorStabilityInnerSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.RequiredSafetyFactorStabilityOuterSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.ShoulderEmbankmentMaterial, Is.EqualTo(stringTestValue));
Assert.That(location.StabilityShoulderGrowSlope, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityShoulderGrowDeltaX, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilitySlopeAdaptionDeltaX, Is.EqualTo(doubleTestValue));
Assert.That(location.UpliftCriterionPiping, Is.EqualTo(doubleTestValue));
Assert.That(location.UpliftCriterionStability, Is.EqualTo(doubleTestValue));
Assert.That(location.XSoilGeometry2DOrigin, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityZoneType, Is.EqualTo(mstabZonesTypeTestValue));
Assert.That(location.SlopeDampingPiezometricHeightPolderSide, Is.EqualTo(doubleTestValue));
Assert.That(location.StabilityDesignMethod, Is.EqualTo(stabilityDesignMethodTestValue));
Assert.That(location.SlopeAdaptionStartCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.SlopeAdaptionEndCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.SlopeAdaptionStepCotangent, Is.EqualTo(doubleTestValue));
Assert.That(location.DikeTableHeight, Is.EqualTo(doubleTestValue));
Assert.That(location.RiverLevel, Is.EqualTo(doubleTestValue));
Assert.That(location.RiverLevelLow, Is.EqualTo(doubleTestValue));
}
[Test]
[Category("Integration")]
public void Import_AttributeMissingUsingPolygonImporter_ErrorIsAddedToList()
{
var square = new Polygon(new LinearRing(new[]
{
new Coordinate(-100, 100),
new Coordinate(100, 100),
new Coordinate(100, -100),
new Coordinate(-100, -100),
new Coordinate(-100, 100)
}));
var geom = Feature.Create(square);
geom.AddAttribute("test", 10);
LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId);
var supportedAttributes = new List
{
mapping.Name
};
var mockImporter = Substitute.For();
var attributeRepository = Substitute.For();
var file = new ShapeFileLocation("test.shp");
string[] lines =
{
"First line",
"Second line",
"Third line"
};
File.WriteAllLines(file.FullPath, lines);
attributeRepository.SupportedAttributes.Returns(supportedAttributes);
attributeRepository.Features.Returns(new[]
{
geom
});
attributeRepository.Query(Arg.Any()).Returns(new[]
{
geom
});
mockImporter.GetFile(Arg.Any()).Returns(file);
mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository);
var location = new CsvImporterLocations.LocationRecord
{
LocationId = "Location 1",
GeoX = 11,
GeoY = 11
};
mockImporter.Targets = new List
{
location
};
mockImporter.RegisterAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId);
mockImporter.Import(null);
Assert.That(mockImporter.ImportErrors.OfType().Count() == 1, Is.True, "The error list should contain an AttributeMissingException");
}
[Test]
[Category("Integration")]
public void Import_AttributeMissingUsingLineImporter_ErrorIsAddedToList()
{
var mockImporter = Substitute.For();
var attributeRepository = Substitute.For();
var crossSectionRepository = Substitute.For();
var supportedAttributes = new List();
var crossSection = Feature.Create(new LineString(new[]
{
new Coordinate(-1, 0),
new Coordinate(1, 0)
}));
var attributeLine = Feature.Create(new LineString(new[]
{
new Coordinate(0, -1),
new Coordinate(0, 1)
}));
attributeLine.AddAttribute("TEST_ATTR", 0);
const string attributeId = LocationShapeFileAttributeMap.PolderLevelAttributeId;
LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(attributeId);
supportedAttributes.Add(mapping.Name);
const string locationId = "Test_Location_01";
var location = new CsvImporterLocations.LocationRecord
{
LocationId = locationId,
GeoX = 1,
GeoY = 1
};
mockImporter.Targets = new List
{
location
};
mockImporter.GetCrossSectionRepository(Arg.Any()).Returns(crossSectionRepository);
LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId);
crossSection.AddAttribute(crossSectionMapping.Name, locationId);
crossSectionRepository.Features.Returns(new[]
{
crossSection
});
mockImporter.GetAttributeName(Arg.Any()).Returns(crossSectionMapping.Name);
attributeRepository.SupportedAttributes.Returns(supportedAttributes);
attributeRepository.Features.Returns(new[]
{
attributeLine
});
attributeRepository.Query(Arg.Any()).Returns(new[]
{
attributeLine
});
var file = new ShapeFileLocation("test.shp");
string[] lines =
{
"First line",
"Second line",
"Third line"
};
File.WriteAllLines(file.FullPath, lines);
mockImporter.GetFile(Arg.Any()).Returns(file);
mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository);
mockImporter.RegisterAttributeMapping(attributeId);
mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File);
mockImporter.Import(null);
Assert.That(mockImporter.ImportErrors.OfType().Count(), Is.EqualTo(1), "The error list should contain an AttributeMissingException");
}
[Test]
[Category("Integration")]
public void RegisterAttribute_AttributeNotSupported_GivesMessage()
{
var location = new CsvImporterLocations.LocationRecord
{
LocationId = "Location 1",
GeoX = 10,
GeoY = 10,
TrafficLoad = 0
};
importer.Targets = new List
{
location
};
importer.DataFileLocation = DirectoryWithDataShapeFiles;
importer.RegisterAttributeMapping("someattributeid", "test", TestShapeFile);
Assert.That(importer.ImproperAttributeMessages.Count, Is.EqualTo(1));
}
[Test]
[Category("Integration")]
public void Import_PointOutsideGeometry_ErrorIsAddedToList()
{
var location = new CsvImporterLocations.LocationRecord
{
LocationId = "Location 1",
GeoX = 0.0,
GeoY = 0.0
};
importer.Targets = new List
{
location
};
importer.DataFileLocation = DirectoryWithDataShapeFiles;
importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile);
importer.Import(null);
if (importer.ImportErrors.OfType().Any())
{
throw importer.ImportErrors.OfType().First();
}
Assert.That(importer.ImportErrors.OfType().Count(), Is.EqualTo(1));
}
[Test]
[Category("Integration")]
public void Import_OnLegalInitialization_LocationPropertyHasChanged()
{
const double trafLoadValueInShapeFile = 13.000;
var location = new CsvImporterLocations.LocationRecord
{
LocationId = "Location 1",
GeoX = 192704.726628436,
GeoY = 505976.228134643,
TrafficLoad = 0
};
importer.Targets = new List
{
location
};
importer.DataFileLocation = DirectoryWithDataShapeFiles;
importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile);
importer.Import(null);
Assert.That(location.TrafficLoad, Is.EqualTo(trafLoadValueInShapeFile));
}
#region Setup
[SetUp]
public void FixtureSetup() {}
[TearDown]
public void FixtureTearDown() {}
[SetUp]
public void TestSetup()
{
importer = new LocationPropertyImporter();
}
[TearDown]
public void TestTearDown() {}
#endregion
}
}