using System; using System.Collections.Generic; using System.IO; using System.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.Importers; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; using Deltares.Maps; using Deltares.Probabilistic; using Deltares.Standard; using GeoAPI.Geometries; using NetTopologySuite.Geometries; using NUnit.Framework; using Rhino.Mocks; using Location = Deltares.Dam.Data.Location; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LocationPropertyImporterTest { const string DirectoryWithDataShapeFiles = @"..\..\..\data\Dam\Waterboards\Groot Salland\Binnenwaarts\GWS\gis-customdata\ShapeFiles\"; private const string TestShapeFile = "trafficload.shp"; private const string TestAttribute = "trafload"; private LocationPropertyImporter importer; #region Setup [TestFixtureSetUp] public void FixtureSetup() { } [TestFixtureTearDown] public void FixtureTearDown() { } [SetUp] public void TestSetup() { importer = new LocationPropertyImporter(); } [TearDown] public void TestTearDown() { } #endregion [Test] [ExpectedException(typeof(ArgumentException))] public void Register_AttributeArgumentNull_Throws() { importer.RegisterAttributeMapping(null, "test", "test"); } [Test] public void CheckingIfAttributeIdIsSupported_UsingHeadPL3LowerCase_ShouldReturnThatItIsSupported() { const bool expectedValue = true; const string attributeId = "head_pl3"; bool actualValue = LocationShapeFileAttributeMap.IsAttributeIdSupported(attributeId); Assert.AreEqual(expectedValue, actualValue); } [Test] public void IsPropertyAttribute_UsingLocationID_ReturnsFalse() { Assert.IsFalse(LocationShapeFileAttributeMap.IsPropertyAttribute(LocationShapeFileAttributeMap.LocationAttributeId)); Assert.IsFalse(LocationShapeFileAttributeMap.IsPropertyAttribute("Location_Id")); } [Test] [ExpectedException(typeof(FileNotFoundException))] public void Register_RequiredFileNotFound_Throws() { importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, "somefile.shp"); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void Import_NoTargetLocationsSet_Throws() { importer.Import(null); } [Test] [Category("Integration")] public void Import_AllPropertiesUsingPolygonAttributeImporter_CorrectValuesShouldBeSetOnTarget() { const string stringInitialValue = "someValue"; const double doubleInitialValue = 99.9; const bool boolInitialValue = false; const SoilType soilTypeInitialValue = SoilType.Peat; const DistributionType distributionInitialValue = DistributionType.Weibull; const PLLineCreationMethod plLineCreationMethodInitialValue = PLLineCreationMethod.ExpertKnowledgeRRD; const string stringTestValue = "testValue"; const double doubleTestValue = 111.1; const bool boolTestValue = true; const SoilType soilTypeTestValue = SoilType.Sand; const DistributionType distributionTestValue = DistributionType.Uniform; const PLLineCreationMethod plLineCreationMethodTestValue = PLLineCreationMethod.GaugesWithFallbackToExpertKnowledgeRRD; const MStabZonesType mstabZonesTypeTestValue = MStabZonesType.ZoneAreas; const StabilityDesignMethod stabilityDesignMethodTestValue = StabilityDesignMethod.OptimizedSlopeAndShoulderAdaption; var mocks = new MockRepository(); var mockImporter = mocks.DynamicMock(); var attributeRepository = mocks.DynamicMock(); 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 (var key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) { var 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.LayerHeightDistributionAttributeId, StringComparison.InvariantCultureIgnoreCase)) { geom.AddAttribute(mapping.Name, distributionTestValue); } else if (key.Equals(LocationShapeFileAttributeMap.UseOriginalPlLineAssignmentsAttributeId, StringComparison.InvariantCultureIgnoreCase)) { geom.AddAttribute(mapping.Name, boolTestValue); } else if (key.Equals(LocationShapeFileAttributeMap.DikeMaterialTypeAttributeId, StringComparison.InvariantCultureIgnoreCase)) { geom.AddAttribute(mapping.Name, soilTypeTestValue); } 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); } } Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); Expect.Call(attributeRepository.Features).Return(new[] { geom }); Expect.Call(attributeRepository.Query((IGeometry)null)).IgnoreArguments().Return(new[]{ geom }); using (var location = new Location { XRd = 1, YRd = 1, SegmentId = stringInitialValue, BoezemLevelTp = doubleInitialValue, BoezemLevelHbp = doubleInitialValue, BoezemLevelLbp = doubleInitialValue, DampingFactorPL3 = doubleInitialValue, DampingFactorPL4 = doubleInitialValue, DikeMaterialType = soilTypeInitialValue, DikeEmbankmentMaterial = stringInitialValue, Direction = doubleInitialValue, DistanceToEntryPoint = doubleInitialValue, DredgingDepth = doubleInitialValue, GrassQuality = doubleInitialValue, HeadPL2 = doubleInitialValue, HeadPl3 = doubleInitialValue, HeadPl4 = doubleInitialValue, LayerHeightDistribution = distributionInitialValue, LayerHeightDeviation = doubleInitialValue, LevelReductionInside = doubleInitialValue, LevelReductionOutside = doubleInitialValue, MinimalCircleDepth = doubleInitialValue, PenetrationLength = doubleInitialValue, PolderLevel = doubleInitialValue, PolderLevelLow = doubleInitialValue, PLLineCreationMethod = plLineCreationMethodInitialValue, PlLineOffsetBelowDikeTopAtRiver = doubleInitialValue, PlLineOffsetBelowDikeTopAtPolder = doubleInitialValue, PlLineOffsetBelowShoulderBaseInside = doubleInitialValue, PlLineOffsetBelowDikeToeAtPolder = doubleInitialValue, PLLineOffsetDryBelowDikeTopAtRiver = doubleInitialValue, PLLineOffsetDryBelowDikeTopAtPolder = doubleInitialValue, PLLineOffsetDryBelowShoulderBaseInside = doubleInitialValue, PLLineOffsetDryBelowDikeToeAtPolder = doubleInitialValue, ModelFactors = new ModelFactors() { RequiredProbabilityOfFailureStabilityInnerslope = doubleInitialValue, RequiredProbabilityOfFailureStabilityOuterslope = doubleInitialValue, RequiredProbabilityOfFailurePiping = doubleInitialValue, RequiredSafetyFactorPiping = doubleInitialValue, RequiredSafetyFactorStabilityInnerSlope = doubleInitialValue, RequiredSafetyFactorStabilityOuterSlope = doubleInitialValue, UpliftCriterionPiping = doubleInitialValue, UpliftCriterionStability = doubleInitialValue }, TrafficLoad = doubleInitialValue, ShoulderEmbankmentMaterial = stringInitialValue, SheetPileLength = doubleInitialValue, SheetPilePointX = doubleInitialValue, SheetPilePointY = doubleInitialValue, SheetPilePointZ = doubleInitialValue, RwBankProtectionBottomLevel = doubleInitialValue, StabilityShoulderGrowSlope = doubleInitialValue, StabilityShoulderGrowDeltaX = doubleInitialValue, StabilitySlopeAdaptionDeltaX = doubleInitialValue, IsUseOriginalPLLineAssignments = boolInitialValue, XSoilGeometry2DOrigin = doubleInitialValue, StabilityZoneType = MStabZonesType.NoZones, ForbiddenZoneFactor = doubleInitialValue, ZoneAreaRestSlopeCrestWidth = 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, }) { mockImporter.Targets = new List { location }; var file = new ShapeFileLocation("test.shp"); string[] lines = { "First line", "Second line", "Third line" }; System.IO.File.WriteAllLines(file.FullPath, lines); Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); mocks.ReplayAll(); foreach (var key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) { mockImporter.RegisterAttributeMapping(key, null); } mockImporter.Import(null); Assert.AreEqual(stringTestValue, location.SegmentId); Assert.AreEqual(doubleTestValue, location.BoezemLevelTp); Assert.AreEqual(doubleTestValue, location.BoezemLevelHbp); Assert.AreEqual(doubleTestValue, location.BoezemLevelLbp); Assert.AreEqual(doubleTestValue, location.DampingFactorPL3); Assert.AreEqual(doubleTestValue, location.DampingFactorPL4); Assert.AreEqual(soilTypeTestValue, location.DikeMaterialType); Assert.AreEqual(stringTestValue, location.DikeEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.Direction); Assert.AreEqual(doubleTestValue, location.DistanceToEntryPoint); Assert.AreEqual(doubleTestValue, location.DredgingDepth); Assert.AreEqual(doubleTestValue, location.GrassQuality); Assert.AreEqual(doubleTestValue, location.HeadPL2); Assert.AreEqual(doubleTestValue, location.HeadPl3); Assert.AreEqual(doubleTestValue, location.HeadPl4); Assert.AreEqual(distributionTestValue, location.LayerHeightDistribution); Assert.AreEqual(doubleTestValue, location.LayerHeightDeviation); Assert.AreEqual(doubleTestValue, location.LevelReductionInside); Assert.AreEqual(doubleTestValue, location.LevelReductionOutside); Assert.AreEqual(doubleTestValue, location.MinimalCircleDepth); Assert.AreEqual(doubleTestValue, location.PenetrationLength); Assert.AreEqual(doubleTestValue, location.PolderLevel); Assert.AreEqual(doubleTestValue, location.PolderLevelLow); Assert.AreEqual(plLineCreationMethodTestValue, location.PLLineCreationMethod); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeTopAtRiver); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeTopAtPolder); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowShoulderBaseInside); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeToeAtPolder); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeTopAtRiver); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeTopAtPolder); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowShoulderBaseInside); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeToeAtPolder); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailureStabilityInnerslope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailureStabilityOuterslope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailurePiping); Assert.AreEqual(doubleTestValue, location.TrafficLoad); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorPiping); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorStabilityInnerSlope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorStabilityOuterSlope); Assert.AreEqual(stringTestValue, location.ShoulderEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.SheetPileLength); Assert.AreEqual(doubleTestValue, location.SheetPilePointX); Assert.AreEqual(doubleTestValue, location.SheetPilePointY); Assert.AreEqual(doubleTestValue, location.SheetPilePointZ); Assert.AreEqual(doubleTestValue, location.RwBankProtectionBottomLevel); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowSlope); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowDeltaX); Assert.AreEqual(doubleTestValue, location.StabilitySlopeAdaptionDeltaX); Assert.AreEqual(doubleTestValue, location.ModelFactors.UpliftCriterionPiping); Assert.AreEqual(doubleTestValue, location.ModelFactors.UpliftCriterionStability); Assert.AreEqual(boolTestValue, location.IsUseOriginalPLLineAssignments); Assert.AreEqual(doubleTestValue, location.XSoilGeometry2DOrigin); Assert.AreEqual(mstabZonesTypeTestValue, location.StabilityZoneType); Assert.AreEqual(doubleTestValue, location.ForbiddenZoneFactor); Assert.AreEqual(doubleTestValue, location.ZoneAreaRestSlopeCrestWidth); Assert.AreEqual(boolTestValue, location.UseNewDikeTopWidth); Assert.AreEqual(doubleTestValue, location.NewDikeTopWidth); Assert.AreEqual(boolTestValue, location.UseNewDikeSlopeInside); Assert.AreEqual(doubleTestValue, location.NewDikeSlopeInside); Assert.AreEqual(boolTestValue, location.UseNewDikeSlopeOutside); Assert.AreEqual(doubleTestValue, location.NewDikeSlopeOutside); Assert.AreEqual(boolTestValue, location.UseNewShoulderTopSlope); Assert.AreEqual(doubleTestValue, location.NewShoulderTopSlope); Assert.AreEqual(boolTestValue, location.UseNewShoulderBaseSlope); Assert.AreEqual(doubleTestValue, location.NewShoulderBaseSlope); Assert.AreEqual(boolTestValue, location.UseNewMaxHeightShoulderAsFraction); Assert.AreEqual(doubleTestValue, location.NewMaxHeightShoulderAsFraction); Assert.AreEqual(boolTestValue, location.UseNewMinDistanceDikeToeStartDitch); Assert.AreEqual(doubleTestValue, location.NewMinDistanceDikeToeStartDitch); Assert.AreEqual(boolTestValue, location.UseNewDitchDefinition); Assert.AreEqual(doubleTestValue, location.NewWidthDitchBottom); Assert.AreEqual(doubleTestValue, location.NewDepthDitch); Assert.AreEqual(doubleTestValue, location.NewSlopeAngleDitch); Assert.AreEqual(stabilityDesignMethodTestValue, location.StabilityDesignMethod); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionStartCotangent); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionEndCotangent); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionStepCotangent); mocks.VerifyAll(); } } [Test] [Category("Integration")] public void Import_AllPropertiesUsingLineAttributeImporter_CorrectValuesShouldBeSetOnTarget() { const string stringInitialValue = "someValue"; const double doubleInitialValue = 99.9; const bool boolInitialValue = false; const SoilType soilTypeInitialValue = SoilType.Peat; const DistributionType distributionInitialValue = DistributionType.Weibull; const PLLineCreationMethod plLineCreationMethodInitialValue = PLLineCreationMethod.ExpertKnowledgeRRD; const MStabZonesType mstabZonesTypeTestValue = MStabZonesType.ZoneAreas; 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 bool boolTestValue = true; const SoilType soilTypeTestValue = SoilType.Sand; const DistributionType distributionTestValue = DistributionType.Uniform; const PLLineCreationMethod plLineCreationMethodTestValue = PLLineCreationMethod.GaugesWithFallbackToExpertKnowledgeRRD; var mocks = new MockRepository(); var mockImporter = mocks.DynamicMock(); var attributeRepository = mocks.DynamicMock(); var crossSectionRepository = mocks.DynamicMock(); 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 (var key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) { var 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.LayerHeightDistributionAttributeId, StringComparison.InvariantCultureIgnoreCase)) { attributeLine.AddAttribute(mapping.Name, distributionTestValue); } else if (key.Equals(LocationShapeFileAttributeMap.UseOriginalPlLineAssignmentsAttributeId, StringComparison.InvariantCultureIgnoreCase)) { attributeLine.AddAttribute(mapping.Name, boolTestValue); } else if (key.Equals(LocationShapeFileAttributeMap.DikeMaterialTypeAttributeId, StringComparison.InvariantCultureIgnoreCase)) { attributeLine.AddAttribute(mapping.Name, soilTypeTestValue); } 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"; using (var location = new Location { Name = locationID, XRd = 1, YRd = 1, SegmentId = stringInitialValue, BoezemLevelTp = doubleInitialValue, BoezemLevelHbp = doubleInitialValue, BoezemLevelLbp = doubleInitialValue, DampingFactorPL3 = doubleInitialValue, DampingFactorPL4 = doubleInitialValue, DikeMaterialType = soilTypeInitialValue, DikeEmbankmentMaterial = stringInitialValue, Direction = doubleInitialValue, DistanceToEntryPoint = doubleInitialValue, DredgingDepth = doubleInitialValue, GrassQuality = doubleInitialValue, HeadPL2 = doubleInitialValue, HeadPl3 = dampingPl3Value, HeadPl4 = doubleInitialValue, LayerHeightDistribution = distributionInitialValue, LayerHeightDeviation = doubleInitialValue, LevelReductionInside = doubleInitialValue, LevelReductionOutside = doubleInitialValue, MinimalCircleDepth = doubleInitialValue, PenetrationLength = doubleInitialValue, PolderLevel = doubleInitialValue, PolderLevelLow = doubleInitialValue, PLLineCreationMethod = plLineCreationMethodInitialValue, PlLineOffsetBelowDikeTopAtRiver = doubleInitialValue, PlLineOffsetBelowDikeTopAtPolder = doubleInitialValue, PlLineOffsetBelowShoulderBaseInside = doubleInitialValue, PlLineOffsetBelowDikeToeAtPolder = doubleInitialValue, PLLineOffsetDryBelowDikeTopAtRiver = doubleInitialValue, PLLineOffsetDryBelowDikeTopAtPolder = doubleInitialValue, PLLineOffsetDryBelowShoulderBaseInside = doubleInitialValue, PLLineOffsetDryBelowDikeToeAtPolder = doubleInitialValue, ModelFactors = new ModelFactors() { RequiredProbabilityOfFailureStabilityInnerslope = doubleInitialValue, RequiredProbabilityOfFailureStabilityOuterslope = doubleInitialValue, RequiredProbabilityOfFailurePiping = doubleInitialValue, RequiredSafetyFactorPiping = doubleInitialValue, RequiredSafetyFactorStabilityInnerSlope = doubleInitialValue, RequiredSafetyFactorStabilityOuterSlope = doubleInitialValue, UpliftCriterionPiping = doubleInitialValue, UpliftCriterionStability = doubleInitialValue }, TrafficLoad = doubleInitialValue, ShoulderEmbankmentMaterial = stringInitialValue, SheetPileLength = doubleInitialValue, SheetPilePointX = doubleInitialValue, SheetPilePointY = doubleInitialValue, SheetPilePointZ = doubleInitialValue, RwBankProtectionBottomLevel = doubleInitialValue, StabilityShoulderGrowSlope = doubleInitialValue, StabilityShoulderGrowDeltaX = doubleInitialValue, StabilitySlopeAdaptionDeltaX = doubleInitialValue, IsUseOriginalPLLineAssignments = boolInitialValue, XSoilGeometry2DOrigin = doubleInitialValue, StabilityZoneType = MStabZonesType.NoZones, SlopeDampingPiezometricHeightPolderSide = doubleInitialValue, IntrusionVerticalWaterPressure = IntrusionVerticalWaterPressureType.Standard }) { mockImporter.Targets = new List { location }; Expect.Call(mockImporter.GetCrossSectionRepository(null)).IgnoreArguments().Return(crossSectionRepository); var crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); crossSection.AddAttribute(crossSectionMapping.Name, locationID); Expect.Call(crossSectionRepository.Features).Return(new[] { crossSection }); Expect.Call(mockImporter.GetAttributeName(null)).IgnoreArguments().Return(crossSectionMapping.Name); Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); Expect.Call(attributeRepository.Features).Return(new[] { attributeLine }); Expect.Call(attributeRepository.Query((IFeature)null)).IgnoreArguments().Return(new[] { attributeLine }); var file = new ShapeFileLocation("test.shp"); string[] lines = { "First line", "Second line", "Third line" }; System.IO.File.WriteAllLines(file.FullPath, lines); Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); mocks.ReplayAll(); // file. foreach (var key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) { mockImporter.RegisterAttributeMapping(key, null); } mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); mockImporter.Import(null); Assert.AreEqual(stringTestValue, location.SegmentId); Assert.AreEqual(doubleTestValue, location.BoezemLevelTp); Assert.AreEqual(doubleTestValue, location.BoezemLevelHbp); Assert.AreEqual(doubleTestValue, location.BoezemLevelLbp); Assert.AreEqual(dampingPl3Value, location.DampingFactorPL3); Assert.AreEqual(0, location.DampingFactorPL4); // as testvalue is beyond the limits, its reset to 0 Assert.AreEqual(soilTypeTestValue, location.DikeMaterialType); Assert.AreEqual(stringTestValue, location.DikeEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.Direction); Assert.AreEqual(doubleTestValue, location.DistanceToEntryPoint); Assert.AreEqual(doubleTestValue, location.DredgingDepth); Assert.AreEqual(doubleTestValue, location.GrassQuality); Assert.AreEqual(doubleTestValue, location.HeadPL2); Assert.AreEqual(doubleTestValue, location.HeadPl3); Assert.AreEqual(doubleTestValue, location.HeadPl4); Assert.AreEqual(distributionTestValue, location.LayerHeightDistribution); Assert.AreEqual(doubleTestValue, location.LayerHeightDeviation); Assert.AreEqual(doubleTestValue, location.LevelReductionInside); Assert.AreEqual(doubleTestValue, location.LevelReductionOutside); Assert.AreEqual(doubleTestValue, location.MinimalCircleDepth); Assert.AreEqual(doubleTestValue, location.PenetrationLength); Assert.AreEqual(doubleTestValue, location.PolderLevel); Assert.AreEqual(doubleTestValue, location.PolderLevelLow); Assert.AreEqual(plLineCreationMethodTestValue, location.PLLineCreationMethod); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeTopAtRiver); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeTopAtPolder); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowShoulderBaseInside); Assert.AreEqual(doubleTestValue, location.PlLineOffsetBelowDikeToeAtPolder); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeTopAtRiver); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeTopAtPolder); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowShoulderBaseInside); Assert.AreEqual(doubleTestValue, location.PLLineOffsetDryBelowDikeToeAtPolder); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailureStabilityInnerslope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailureStabilityOuterslope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredProbabilityOfFailurePiping); Assert.AreEqual(doubleTestValue, location.TrafficLoad); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorPiping); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorStabilityInnerSlope); Assert.AreEqual(doubleTestValue, location.ModelFactors.RequiredSafetyFactorStabilityOuterSlope); Assert.AreEqual(stringTestValue, location.ShoulderEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.SheetPileLength); Assert.AreEqual(doubleTestValue, location.SheetPilePointX); Assert.AreEqual(doubleTestValue, location.SheetPilePointY); Assert.AreEqual(doubleTestValue, location.SheetPilePointZ); Assert.AreEqual(doubleTestValue, location.RwBankProtectionBottomLevel); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowSlope); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowDeltaX); Assert.AreEqual(doubleTestValue, location.StabilitySlopeAdaptionDeltaX); Assert.AreEqual(doubleTestValue, location.ModelFactors.UpliftCriterionPiping); Assert.AreEqual(doubleTestValue, location.ModelFactors.UpliftCriterionStability); Assert.AreEqual(boolTestValue, location.IsUseOriginalPLLineAssignments); Assert.AreEqual(doubleTestValue, location.XSoilGeometry2DOrigin); Assert.AreEqual(mstabZonesTypeTestValue, location.StabilityZoneType); Assert.AreEqual(doubleTestValue, location.SlopeDampingPiezometricHeightPolderSide); Assert.AreEqual(stabilityDesignMethodTestValue, location.StabilityDesignMethod); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionStartCotangent); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionEndCotangent); Assert.AreEqual(doubleTestValue, location.SlopeAdaptionStepCotangent); mocks.VerifyAll(); } } [Test] //[ExpectedException(typeof(AttributeMissingException))] [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); var mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); var supportedAttributes = new List { mapping.Name }; var mocks = new MockRepository(); var mockImporter = mocks.DynamicMock(); var attributeRepository = mocks.DynamicMock(); var file = new ShapeFileLocation("test.shp"); string[] lines = { "First line", "Second line", "Third line" }; System.IO.File.WriteAllLines(file.FullPath, lines); Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); Expect.Call(attributeRepository.Features).Return(new[] { geom }); Expect.Call(attributeRepository.Query((IGeometry)null)).IgnoreArguments().Return(new[]{ geom }); Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); mocks.ReplayAll(); using (var location = new Location { XRd = 11, YRd = 11 }) { mockImporter.Targets = new List { location }; mockImporter.RegisterAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); mockImporter.Import(null); Assert.IsTrue(mockImporter.ImportErrors.OfType().Count() == 1, "The error list should contain an AttributeMissingException"); mocks.VerifyAll(); } } [Test] [Category("Integration")] public void Import_AttributeMissingUsingLineImporter_ErrorIsAddedToList() { var mocks = new MockRepository(); var mockImporter = mocks.DynamicMock(); var attributeRepository = mocks.DynamicMock(); var crossSectionRepository = mocks.DynamicMock(); 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; var mapping = LocationShapeFileAttributeMap.GetAttributeMapping(attributeId); supportedAttributes.Add(mapping.Name); const string locationID = "Test_Location_01"; using (var location = new Location { Name = locationID, XRd = 1, YRd = 1, }) { mockImporter.Targets = new List { location }; Expect.Call(mockImporter.GetCrossSectionRepository(null)).IgnoreArguments().Return(crossSectionRepository); var crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); crossSection.AddAttribute(crossSectionMapping.Name, locationID); Expect.Call(crossSectionRepository.Features).Return(new[] { crossSection }); Expect.Call(mockImporter.GetAttributeName(null)).IgnoreArguments().Return(crossSectionMapping.Name); Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); Expect.Call(attributeRepository.Features).Return(new[] { attributeLine }); Expect.Call(attributeRepository.Query((IFeature)null)).IgnoreArguments().Return(new[] { attributeLine }); var file = new ShapeFileLocation("test.shp"); string[] lines = { "First line", "Second line", "Third line" }; System.IO.File.WriteAllLines(file.FullPath, lines); Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); mocks.ReplayAll(); mockImporter.RegisterAttributeMapping(attributeId); mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); mockImporter.Import(null); Assert.IsTrue(mockImporter.ImportErrors.OfType().Count() == 1, "The error list should contain an AttributeMissingException"); mocks.VerifyAll(); } } [Test] [ExpectedException(typeof(NotSupportedException))] [Category("Integration")] public void RegisterAttribute_AttributeNotSupported_Throws() { using (var location = new Location { XRd = 10, YRd = 10, TrafficLoad = 0 }) { importer.Targets = new List { location }; importer.DataFileLocation = DirectoryWithDataShapeFiles; importer.RegisterAttributeMapping("someattributeid", "test", TestShapeFile); } } [Test] [Category("Integration")] //[ExpectedException(typeof(FeatureCoverageException))] public void Import_PointOutsideGeometry_ErrorIsAddedToList() { using (var location = new Location { XRd = 0.0, YRd = 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.IsTrue(importer.ImportErrors.OfType().Count() == 1); } } [Test] [Category("Integration")] public void Import_OnLegalInitialization_LocationPropertyHasChanged() { const double trafLoadValueInShapeFile = 13.000; using (var location = new Location { XRd = 192704.726628436, YRd = 505976.228134643, TrafficLoad = 0 }) { importer.Targets = new List { location }; importer.DataFileLocation = DirectoryWithDataShapeFiles; importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile); importer.Import(null); Assert.AreEqual(trafLoadValueInShapeFile, location.TrafficLoad); } } } }