// 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 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 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 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 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.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.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 }); 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, 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, 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); 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.DampingFactorPl3); Assert.AreEqual(doubleTestValue, location.DampingFactorPl4); Assert.AreEqual(stringTestValue, location.DikeEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.DistanceToEntryPoint); Assert.AreEqual(doubleTestValue, location.HeadPl2); Assert.AreEqual(doubleTestValue, location.HeadPl3); Assert.AreEqual(doubleTestValue, location.HeadPl4); Assert.AreEqual(doubleTestValue, location.MinimalCircleDepth); Assert.AreEqual(doubleTestValue, location.PenetrationLength); Assert.AreEqual(doubleTestValue, location.PolderLevel); 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.TrafficLoad); Assert.AreEqual(doubleTestValue, location.TL_DegreeOfConsolidation); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorPiping); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorStabilityInnerSlope); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorStabilityOuterSlope); Assert.AreEqual(stringTestValue, location.ShoulderEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowSlope); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowDeltaX); Assert.AreEqual(doubleTestValue, location.StabilitySlopeAdaptionDeltaX); Assert.AreEqual(doubleTestValue, location.UpliftCriterionPiping); Assert.AreEqual(doubleTestValue, location.UpliftCriterionStability); 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); Assert.AreEqual(doubleTestValue, location.DikeTableHeight); Assert.AreEqual(doubleTestValue, location.RiverLevel); Assert.AreEqual(doubleTestValue, location.RiverLevelLow); mocks.VerifyAll(); } [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.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 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.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 }; 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" }; 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(dampingPl3Value, location.DampingFactorPl3); Assert.AreEqual(0, location.DampingFactorPl4); // as testvalue is beyond the limits, its reset to 0 Assert.AreEqual(stringTestValue, location.DikeEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.DistanceToEntryPoint); Assert.AreEqual(doubleTestValue, location.HeadPl2); Assert.AreEqual(doubleTestValue, location.HeadPl3); Assert.AreEqual(doubleTestValue, location.HeadPl4); Assert.AreEqual(doubleTestValue, location.MinimalCircleDepth); Assert.AreEqual(doubleTestValue, location.PenetrationLength); Assert.AreEqual(doubleTestValue, location.PolderLevel); 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.TrafficLoad); Assert.AreEqual(doubleTestValue, location.TL_DegreeOfConsolidation); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorPiping); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorStabilityInnerSlope); Assert.AreEqual(doubleTestValue, location.RequiredSafetyFactorStabilityOuterSlope); Assert.AreEqual(stringTestValue, location.ShoulderEmbankmentMaterial); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowSlope); Assert.AreEqual(doubleTestValue, location.StabilityShoulderGrowDeltaX); Assert.AreEqual(doubleTestValue, location.StabilitySlopeAdaptionDeltaX); Assert.AreEqual(doubleTestValue, location.UpliftCriterionPiping); Assert.AreEqual(doubleTestValue, location.UpliftCriterionStability); 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); Assert.AreEqual(doubleTestValue, location.DikeTableHeight); Assert.AreEqual(doubleTestValue, location.RiverLevel); Assert.AreEqual(doubleTestValue, location.RiverLevelLow); 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" }; 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(); 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.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"; var location = new CsvImporterLocations.LocationRecord { LocationId = locationId, GeoX = 1, GeoY = 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" }; 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] [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.AreEqual(1, importer.ImproperAttributeMessages.Count); } [Test] [Category("Integration")] //[ExpectedException(typeof(FeatureCoverageException))] 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.IsTrue(importer.ImportErrors.OfType().Count() == 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.AreEqual(trafLoadValueInShapeFile, location.TrafficLoad); } } }