Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Deltares.Dam.Tests.csproj =================================================================== diff -u -r4881 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Deltares.Dam.Tests.csproj (.../Deltares.Dam.Tests.csproj) (revision 4881) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Deltares.Dam.Tests.csproj (.../Deltares.Dam.Tests.csproj) (revision 4890) @@ -2214,7 +2214,11 @@ - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Deltares.Maps.Tests.csproj =================================================================== diff -u -r4806 -r4890 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Deltares.Maps.Tests.csproj (.../Deltares.Maps.Tests.csproj) (revision 4806) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Deltares.Maps.Tests.csproj (.../Deltares.Maps.Tests.csproj) (revision 4890) @@ -22,9 +22,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - 3.6.1 - Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationCharacteristicPointImporterTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationCharacteristicPointImporterTest.cs (.../LocationCharacteristicPointImporterTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationCharacteristicPointImporterTest.cs (.../LocationCharacteristicPointImporterTest.cs) (revision 4890) @@ -27,201 +27,176 @@ using Deltares.Maps; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; using Location = Deltares.Dam.Data.Location; +using NSubstitute; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LocationCharacteristicPointImporterTest { - //TODO: .net 6 replace by substitute + private LocationCharacteristicPointImporter importer; + private IFeatureRepository profiles, characteristicLines; + private Feature profileLine, characteristicLine; - //private const string TestDataFolder = @"..\..\..\data\Dam\Waterboards\Groot Salland\Binnenwaarts\GWS\gis-irisdata\ShapeFiles"; - //private LocationCharacteristicPointImporter importer; - //private MockRepository mocks; - //private IFeatureRepository profiles, characteresticLines; - //private Feature profileLine, characteristicLine; + [Test] + public void Import_DataFolderNotFound_Throws() + { + Assert.That(() => new LocationCharacteristicPointImporter(@"\someunknowndirectory", new List()), Throws.InstanceOf()); + } - //[Test] - //public void Import_DataFolderNotFound_Throws() - //{ - // mocks.ReplayAll(); - // Assert.That(() => new LocationCharacteristicPointImporter(@"\someunknowndirectory", new List()), Throws.InstanceOf()); - //} + [Test] + public void ImportRepository_DoesNotContainTheRequiredAttributeLocationID_Throws() + { + importer = new LocationCharacteristicPointImporter(new List()) + { + CharacteristicLineRepository = characteristicLines, + ProfileLocationsRepository = profiles + }; - //[Test] - //public void ImportRepository_DoesNotContainTheRequiredAttributeLocationID_Throws() - //{ - // importer = new LocationCharacteristicPointImporter(new List()) - // { - // CharacteristicLineRepository = characteresticLines, - // ProfileLocationsRepository = profiles - // }; + profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); + characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); - // //this.profileLine.AddAttribute(LocationProfileImporter.LocationIDAttributeName, new object()); - // profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); - // characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); + profiles.Features.Returns(new[] + { + profileLine + }); + characteristicLines.Features.Returns(new[] + { + characteristicLine + }); - // Expect.Call(profiles.Features).Return(new[] - // { - // profileLine - // }); - // Expect.Call(characteresticLines.Features).Return(new[] - // { - // characteristicLine - // }); + Assert.That(() => importer.Import(), Throws.InvalidOperationException); + } - // mocks.ReplayAll(); + [Test] + public void ImportRepository_DoesNotContainTheRequiredAttributeDikeID_Throws() + { + importer = new LocationCharacteristicPointImporter(new List()) + { + CharacteristicLineRepository = characteristicLines, + ProfileLocationsRepository = profiles + }; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException); - //} + profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, new object()); + characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); - //[Test] - //public void ImportRepository_DoesNotContainTheRequiredAttributeDikeID_Throws() - //{ - // importer = new LocationCharacteristicPointImporter(new List()) - // { - // CharacteristicLineRepository = characteresticLines, - // ProfileLocationsRepository = profiles - // }; + profiles.Features.Returns(new[] + { + profileLine + }); + characteristicLines.Features.Returns(new[] + { + characteristicLine + }); - // profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, new object()); - // //this.profileLine.AddAttribute(LocationProfileImporter.LocationDikeAttributeName, new object()); - // characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); + Assert.That(() => importer.Import(), Throws.InvalidOperationException); + } - // Expect.Call(profiles.Features).Return(new[] - // { - // profileLine - // }); - // Expect.Call(characteresticLines.Features).Return(new[] - // { - // characteristicLine - // }); + [Test] + public void ImportRepository_DoesNotContainARequiredAttribute_Throws() + { + importer = new LocationCharacteristicPointImporter(new List()) + { + CharacteristicLineRepository = characteristicLines, + ProfileLocationsRepository = profiles + }; - // mocks.ReplayAll(); + characteristicLines.Features.Returns(new[] + { + characteristicLine + }); - // Assert.That(() => importer.Import(), Throws.InvalidOperationException); - //} + Assert.That(() => importer.Import(), Throws.InvalidOperationException); + } - //[Test] - //public void ImportRepository_DoesNotContainARequiredAttribute_Throws() - //{ - // importer = new LocationCharacteristicPointImporter(new List()) - // { - // CharacteristicLineRepository = characteresticLines, - // ProfileLocationsRepository = profiles - // }; + [Test] + public void ImportRepositories_LineIntersectionResultsAreRetrieved_LocationsValuesAreSet() + { + const string locationID = "testloc"; + const CharacteristicPointType dikeTopAtPolder = CharacteristicPointType.DikeTopAtPolder; + using (var surfaceLine = new SurfaceLine2 + { + Geometry = new LocalizedGeometryPointString(), + CharacteristicPoints = + { + GeometryMustContainPoint = true + } + }) + using (var location = new Location + { + Name = locationID, + SurfaceLine2 = surfaceLine + }) + { + surfaceLine.EnsurePointOfType(9.0, 9.0, 9.0, dikeTopAtPolder); - // //this.profileLine.AddAttribute(LocationProfileImporter.LocationIDAttributeName, new object()); - // //this.profileLine.AddAttribute(LocationProfileImporter.LocationDikeAttributeName, new object()); - // //this.characteristicLine.AddAttribute(LocationProfileImporter.CharacteristicLineAttributeName, new object()); + importer = new LocationCharacteristicPointImporter(new List + { + location + }) + { + CharacteristicLineRepository = characteristicLines, + ProfileLocationsRepository = profiles + }; - // Expect.Call(characteresticLines.Features).Return(new[] - // { - // characteristicLine - // }); - // //Expect.Call(profiles.Geometries).Return(new[] { this.profileLine }); + profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); + profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, locationID); - // mocks.ReplayAll(); + characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, "kruin-binnen"); - // Assert.That(() => importer.Import(), Throws.InvalidOperationException); - //} + characteristicLines.Features.Returns(new[] + { + characteristicLine + }); + characteristicLines.Query(Arg.Any()).Returns(new[] + { + characteristicLine + }); + profiles.Features.Returns(new[] + { + profileLine + }); - //[Test] - //public void ImportRepositories_LineIntersectionResultsAreRetrieved_LocationsValuesAreSet() - //{ - // const string locationID = "testloc"; - // const CharacteristicPointType dikeTopAtPolder = CharacteristicPointType.DikeTopAtPolder; - // using (var surfaceLine = new SurfaceLine2 - // { - // Geometry = new LocalizedGeometryPointString(), - // CharacteristicPoints = - // { - // GeometryMustContainPoint = true - // } - // }) - // using (var location = new Location - // { - // Name = locationID, - // SurfaceLine2 = surfaceLine - // }) - // { - // surfaceLine.EnsurePointOfType(9.0, 9.0, 9.0, dikeTopAtPolder); + importer.Import(); - // importer = new LocationCharacteristicPointImporter(new List - // { - // location - // }) - // { - // CharacteristicLineRepository = characteresticLines, - // ProfileLocationsRepository = profiles - // }; + Assert.That(location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).X, Is.EqualTo(0)); + Assert.That(location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).Y, Is.EqualTo(0)); + } + } - // profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); - // profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, locationID); + #region Setup - // characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, "kruin-binnen"); + [SetUp] + public void FixtureSetup() + { + } - // Expect.Call(characteresticLines.Features).Return(new[] - // { - // characteristicLine - // }); - // Expect.Call(characteresticLines.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // characteristicLine - // }); - // Expect.Call(profiles.Features).Return(new[] - // { - // profileLine - // }); - // //Expect.Call(profiles.Query((IFeature)null)).IgnoreArguments().Return(new[] { this.profileLine }); + [TearDown] + public void FixtureTearDown() {} - // mocks.ReplayAll(); + [SetUp] + public void TestSetup() + { + profiles = Substitute.For(); + characteristicLines = Substitute.For(); - // importer.Import(); + profileLine = Feature.Create(new LineString(new[] + { + new Coordinate(-1, 0), + new Coordinate(1, 0) + })); - // Assert.That(location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).X, Is.EqualTo(0)); - // Assert.That(location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).Y, Is.EqualTo(0)); - // } - //} + characteristicLine = Feature.Create(new LineString(new[] + { + new Coordinate(0, -1), + new Coordinate(0, 1) + })); + } - //#region Setup + [TearDown] + public void TestTearDown() {} - //[SetUp] - //public void FixtureSetup() - //{ - // mocks = new MockRepository(); - //} - - //[TearDown] - //public void FixtureTearDown() {} - - //[SetUp] - //public void TestSetup() - //{ - // profiles = mocks.DynamicMock(); - // characteresticLines = mocks.DynamicMock(); - - // profileLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(-1, 0), - // new Coordinate(1, 0) - // })); - - // characteristicLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(0, -1), - // new Coordinate(0, 1) - // })); - //} - - //[TearDown] - //public void TestTearDown() - //{ - // mocks.VerifyAll(); - //} - - //#endregion + #endregion } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/FeatueRepositoryExtensionsTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/FeatueRepositoryExtensionsTest.cs (.../FeatueRepositoryExtensionsTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/FeatueRepositoryExtensionsTest.cs (.../FeatueRepositoryExtensionsTest.cs) (revision 4890) @@ -23,199 +23,186 @@ using System.Linq; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; namespace Deltares.Maps.Tests.Services { [TestFixture] public class FeatueRepositoryExtensionsTest { - //TODO: .net 6 replace by substitute - //private MockRepository mocks; - //private IFeatureRepository rep1, rep2; - //private LineString dikeRing; + private IFeatureRepository rep1, rep2; + private LineString dikeRing; - //[Test] - //public void GetLineIntersectionPoints_OneValidProfileIntersects_ListContainsOneElement() - //{ - // var profile1 = new LineString(new[] - // { - // new Coordinate(-3, 1), - // new Coordinate(0, 1) - // }); + [Test] + public void GetLineIntersectionPoints_OneValidProfileIntersects_ListContainsOneElement() + { + var profile1 = new LineString(new[] + { + new Coordinate(-3, 1), + new Coordinate(0, 1) + }); - // var profile2 = new LineString(new[] - // { - // new Coordinate(-3, -3), - // new Coordinate(0, -3) - // }); + var profile2 = new LineString(new[] + { + new Coordinate(-3, -3), + new Coordinate(0, -3) + }); - // var geom1 = Feature.Create(profile1); - // var geom2 = Feature.Create(profile2); - // Expect.Call(rep1.Features).Return(new[] - // { - // geom1, - // geom2 - // }); + var geom1 = Feature.Create(profile1); + var geom2 = Feature.Create(profile2); + rep1.Features.Returns(new[] + { + geom1, + geom2 + }); - // var dikeGeom = Feature.Create(dikeRing); - // Expect.Call(rep2.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // dikeGeom - // }); + var dikeGeom = Feature.Create(dikeRing); + rep2.Query(Arg.Any()).Returns(new[] + { + dikeGeom + }); - // mocks.ReplayAll(); + IEnumerable> results = rep1.GetIntersectionPoints(rep2); + Assert.That(results, Is.Not.Null); + Assert.That(results.Count(), Is.EqualTo(2)); + Assert.That(results.Any(r => r.Key == 1), Is.True); + Assert.That(results.Any(r => r.Key == 0), Is.True); + IntersectionResult result = results.GetResultsHavingCount(1).Single(); + Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); + Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); + Assert.That(result.IntersectionPoints.ElementAt(0).X, Is.EqualTo(-2).Within(0.0001)); + Assert.That(result.IntersectionPoints.ElementAt(0).Y, Is.EqualTo(1).Within(0.0001)); + } - // IEnumerable> results = rep1.GetIntersectionPoints(rep2); - // Assert.That(results, Is.Not.Null); - // Assert.That(results.Count(), Is.EqualTo(2)); - // Assert.That(results.Any(r => r.Key == 1), Is.True); - // Assert.That(results.Any(r => r.Key == 0), Is.True); - // IntersectionResult result = results.GetResultsHavingCount(1).Single(); - // Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); - // Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); - // Assert.That(result.IntersectionPoints.ElementAt(0).X, Is.EqualTo(-2).Within(0.0001)); - // Assert.That(result.IntersectionPoints.ElementAt(0).Y, Is.EqualTo(1).Within(0.0001)); - //} + [Test] + public void GetLineIntersectionPoints_TwoValidProfilesIntersects_ListContainsTwoElements() + { + var profile1 = new LineString(new[] + { + new Coordinate(-3, 1), + new Coordinate(0, 1) + }); - //[Test] - //public void GetLineIntersectionPoints_TwoValidProfilesIntersects_ListContainsTwoElements() - //{ - // var profile1 = new LineString(new[] - // { - // new Coordinate(-3, 1), - // new Coordinate(0, 1) - // }); + var profile2 = new LineString(new[] + { + new Coordinate(-3, -1), + new Coordinate(0, -1) + }); - // var profile2 = new LineString(new[] - // { - // new Coordinate(-3, -1), - // new Coordinate(0, -1) - // }); + var geom1 = Feature.Create(profile1); + var geom2 = Feature.Create(profile2); + rep1.Features.Returns(new[] + { + geom1, + geom2 + }); - // var geom1 = Feature.Create(profile1); - // var geom2 = Feature.Create(profile2); - // Expect.Call(rep1.Features).Return(new[] - // { - // geom1, - // geom2 - // }); + var dikeGeom = Feature.Create(dikeRing); + rep2.Query(Arg.Any()).Returns(new[] + { + dikeGeom + }); - // var dikeGeom = Feature.Create(dikeRing); - // Expect.Call(rep2.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // dikeGeom - // }); - // mocks.ReplayAll(); + IEnumerable> results = rep1.GetIntersectionPoints(rep2); - // IEnumerable> results = rep1.GetIntersectionPoints(rep2); + Assert.That(results, Is.Not.Null); + Assert.That(results.Count(), Is.EqualTo(1)); + Assert.That(results.Any(r => r.Key == 1), Is.True); - // Assert.That(results, Is.Not.Null); - // Assert.That(results.Count(), Is.EqualTo(1)); - // Assert.That(results.Any(r => r.Key == 1), Is.True); + Assert.That(results.GetResultsHavingCount(1).Count(), Is.EqualTo(2)); + IntersectionResult result = results.ElementAt(0).First(); + Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); + Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); + Assert.That(result.IntersectionPoints.ElementAt(0).X, Is.EqualTo(-2).Within(0.0001)); + Assert.That(result.IntersectionPoints.ElementAt(0).Y, Is.EqualTo(1).Within(0.0001)); + } - // Assert.That(results.GetResultsHavingCount(1).Count(), Is.EqualTo(2)); - // IntersectionResult result = results.ElementAt(0).First(); - // Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); - // Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); - // Assert.That(result.IntersectionPoints.ElementAt(0).X, Is.EqualTo(-2).Within(0.0001)); - // Assert.That(result.IntersectionPoints.ElementAt(0).Y, Is.EqualTo(1).Within(0.0001)); - //} + [Test] + public void GetLineIntersectionPoints_ProfileIntersectsOnTwoSegements_ListContainsOneElementAndTwoIntersectionPoints() + { + var profile1 = new LineString(new[] + { + new Coordinate(-3, 1), + new Coordinate(3, 1) + }); - //[Test] - //public void GetLineIntersectionPoints_ProfileIntersectsOnTwoSegements_ListContainsOneElementAndTwoIntersectionPoints() - //{ - // var profile1 = new LineString(new[] - // { - // new Coordinate(-3, 1), - // new Coordinate(3, 1) - // }); + var geom1 = Feature.Create(profile1); + rep1.Features.Returns(new[] + { + geom1 + }); - // var geom1 = Feature.Create(profile1); - // Expect.Call(rep1.Features).Return(new[] - // { - // geom1 - // }); + var dikeGeom = Feature.Create(dikeRing); + rep2.Query(Arg.Any()).Returns(new[] + { + dikeGeom + }); - // var dikeGeom = Feature.Create(dikeRing); - // Expect.Call(rep2.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // dikeGeom - // }); + IEnumerable> results = rep1.GetIntersectionPoints(rep2); + Assert.That(results, Is.Not.Null); + Assert.That(results.Count(), Is.EqualTo(1)); + Assert.That(results.GetResultsHavingCount(2).Count(), Is.EqualTo(1)); + IntersectionResult result = results.ElementAt(0).First(); + Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); + Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); + } - // mocks.ReplayAll(); + [Test] + public void GetLineIntersectionPoints_ProfileDoesNotIntersects_ListContainsOneElementAndZeroIntersectionPoints() + { + var profile1 = new LineString(new[] + { + new Coordinate(-3, -3), + new Coordinate(3, -3) + }); - // IEnumerable> results = rep1.GetIntersectionPoints(rep2); - // Assert.That(results, Is.Not.Null); - // Assert.That(results.Count(), Is.EqualTo(1)); - // Assert.That(results.GetResultsHavingCount(2).Count(), Is.EqualTo(1)); - // IntersectionResult result = results.ElementAt(0).First(); - // Assert.That(geom1.Id, Is.EqualTo(result.Source.Id)); - // Assert.That(dikeGeom.Id, Is.EqualTo(result.Target.Id)); - //} + var geom1 = Feature.Create(profile1); + rep1.Features.Returns(new[] + { + geom1 + }); - //[Test] - //public void GetLineIntersectionPoints_ProfileDoesNotIntersects_ListContainsOneElementAndZeroIntersectionPoints() - //{ - // var profile1 = new LineString(new[] - // { - // new Coordinate(-3, -3), - // new Coordinate(3, -3) - // }); + var dikeGeom = Feature.Create(dikeRing); + rep2.Query(Arg.Any()).Returns(new[] + { + dikeGeom + }); - // var geom1 = Feature.Create(profile1); - // Expect.Call(rep1.Features).Return(new[] - // { - // geom1 - // }); + IEnumerable> results = rep1.GetIntersectionPoints(rep2); + Assert.That(results, Is.Not.Null); + Assert.That(results.Count(), Is.EqualTo(1)); + Assert.That(results.GetResultsHavingCount(0).Count(), Is.EqualTo(1)); + } - // var dikeGeom = Feature.Create(dikeRing); - // Expect.Call(rep2.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // dikeGeom - // }); + #region Setup - // mocks.ReplayAll(); + [SetUp] + public void FixtureSetup() + { + } - // IEnumerable> results = rep1.GetIntersectionPoints(rep2); - // Assert.That(results, Is.Not.Null); - // Assert.That(results.Count(), Is.EqualTo(1)); - // Assert.That(results.GetResultsHavingCount(0).Count(), Is.EqualTo(1)); - //} + [TearDown] + public void FixtureTearDown() {} - //#region Setup + [SetUp] + public void TestSetup() + { + rep1 = Substitute.For(); + rep2 = Substitute.For(); - //[SetUp] - //public void FixtureSetup() - //{ - // mocks = new MockRepository(); - //} + dikeRing = new LineString(new[] + { + new Coordinate(-2, 2), + new Coordinate(2, 2), + new Coordinate(2, -2), + new Coordinate(-2, -2), + new Coordinate(-2, 2) + }); + } - //[TearDown] - //public void FixtureTearDown() {} + [TearDown] + public void TestTearDown() {} - //[SetUp] - //public void TestSetup() - //{ - // rep1 = mocks.DynamicMock(); - // rep2 = mocks.DynamicMock(); - - // dikeRing = new LineString(new[] - // { - // new Coordinate(-2, 2), - // new Coordinate(2, 2), - // new Coordinate(2, -2), - // new Coordinate(-2, -2), - // new Coordinate(-2, 2) - // }); - //} - - //[TearDown] - //public void TestTearDown() - //{ - // mocks.VerifyAll(); - //} - - //#endregion + #endregion } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DataPluginImporterBackgroundTests.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DataPluginImporterBackgroundTests.cs (.../DataPluginImporterBackgroundTests.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DataPluginImporterBackgroundTests.cs (.../DataPluginImporterBackgroundTests.cs) (revision 4890) @@ -27,15 +27,13 @@ using Deltares.Dam.Data.DataPlugins.Configuration; using Deltares.Maps; using NUnit.Framework; -using Rhino.Mocks; namespace Deltares.Dam.Tests { [TestFixture] public class DataPluginImporterBackgroundTests { private DataPluginImporter importer; - private MockRepository mocks; private IEnumerable dataSources; [Test] @@ -44,11 +42,10 @@ // Precondition : Importer has read all data public void ImporterGetIdList_InvokedOnClient_ReturnsNonEmptyList() { - //TODO: .net 6 replace by substitute - //importer.ImportDataForDikeRings(null); - //IEnumerable idlist = importer.MapGeometryIdList; - //Assert.That(idlist, Is.Not.Null); - //Assert.That(idlist.Any(), Is.True); + importer.ImportDataForDikeRings(null); + IEnumerable idlist = importer.MapGeometryIdList; + Assert.That(idlist, Is.Not.Null); + Assert.That(idlist.Any(), Is.True); } [Test] @@ -57,10 +54,9 @@ // Precondition : Importer has read all data public void ImporterGetGeometry_InvokedOnClient_ReturnsGeometry() { - //TODO: .net 6 replace by substitute - //importer.ImportDataForDikeRings(null); - //IEnumerable idlist = importer.MapGeometryIdList; - //Assert.That(importer.GetMapGeometry(idlist.ElementAt(0)), Is.Not.Null); + importer.ImportDataForDikeRings(null); + IEnumerable idlist = importer.MapGeometryIdList; + Assert.That(importer.GetMapGeometry(idlist.ElementAt(0)), Is.Not.Null); } [Test] @@ -69,31 +65,28 @@ // Precondition : Importer has read all data public void ImporterGetGeometryAttributes_InvokedOnClient_ReturnsAttributeList() { - //TODO: .net 6 replace by substitute - //importer.ImportDataForDikeRings(null); - //IEnumerable idlist = importer.MapGeometryIdList; - //Assert.That(importer.GetMapGeometryAttributes(idlist.ElementAt(0)), Is.Not.Null); + importer.ImportDataForDikeRings(null); + IEnumerable idlist = importer.MapGeometryIdList; + Assert.That(importer.GetMapGeometryAttributes(idlist.ElementAt(0)), Is.Not.Null); } #region Setup [SetUp] public void FixtureSetup() { - //TODO: .net 6 replace by substitute - //mocks = new MockRepository(); - //string testDataFolder = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\ShapeFiles\Gemeenten.shp"); - //var testFile = new ShapeFileLocation(testDataFolder); - //Assert.That(testFile.IsValid, Is.True); + string testDataFolder = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\ShapeFiles\Gemeenten.shp"); + var testFile = new ShapeFileLocation(testDataFolder); + Assert.That(testFile.IsValid, Is.True); - //dataSources = new List - //{ - // new DataSource - // { - // DataSourceType = DataSourceType.BackgroundShapeFiles, - // DataLocation = testFile.FullPath - // } - //}; + dataSources = new List + { + new DataSource + { + DataSourceType = DataSourceType.BackgroundShapeFiles, + DataLocation = testFile.FullPath + } + }; } [TearDown] @@ -102,17 +95,14 @@ [SetUp] public void TestSetup() { - //TODO: .net 6 replace by substitute - //mocks.DynamicMock(); - //importer = new DataPluginImporter(); - //importer.SetDataSources("", dataSources); + importer = new DataPluginImporter(); + importer.SetDataSources("", dataSources); } [TearDown] public void TestTearDown() { importer = null; - //mocks.VerifyAll(); } #endregion Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationPropertyImporterTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationPropertyImporterTest.cs (.../LocationPropertyImporterTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationPropertyImporterTest.cs (.../LocationPropertyImporterTest.cs) (revision 4890) @@ -29,714 +29,693 @@ using Deltares.Maps; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LocationPropertyImporterTest { - //TODO: .net 6 replace by substitute + private const string TestShapeFile = "trafficload.shp"; + private readonly string DirectoryWithDataShapeFiles = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\GrootSallandBinnenwaarts\Shapes\"); + private LocationPropertyImporter importer; - //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 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"; - //[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)); + } - // 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 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 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] - //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; - //[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; - // 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 mocks = new MockRepository(); - // var mockImporter = mocks.DynamicMock(); - // var attributeRepository = mocks.DynamicMock(); + var supportedAttributes = new List(); - // 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 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); - // var geom = Feature.Create(square); + foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) + { + LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(key); + supportedAttributes.Add(mapping.Name); - // 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); + } + } - // 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 + }); - // Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); - // Expect.Call(attributeRepository.Features).Return(new[] - // { - // geom - // }); - // Expect.Call(attributeRepository.Query((NetTopologySuite.Geometries.Geometry) 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, + 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 + }; - // 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); - // 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); + foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) + { + mockImporter.RegisterAttributeMapping(key, null); + } - // mocks.ReplayAll(); + mockImporter.Import(null); - // foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) - // { - // mockImporter.RegisterAttributeMapping(key, 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)); + } - // mockImporter.Import(null); + [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; - // 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)); + var mockImporter = Substitute.For(); + var attributeRepository = Substitute.For(); + var crossSectionRepository = Substitute.For(); - // mocks.VerifyAll(); - //} + var supportedAttributes = new List(); - //[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 crossSection = Feature.Create(new LineString(new[] + { + new Coordinate(-1, 0), + new Coordinate(1, 0) + })); - // var mocks = new MockRepository(); - // var mockImporter = mocks.DynamicMock(); - // var attributeRepository = mocks.DynamicMock(); - // var crossSectionRepository = mocks.DynamicMock(); + var attributeLine = Feature.Create(new LineString(new[] + { + new Coordinate(0, -1), + new Coordinate(0, 1) + })); - // var supportedAttributes = new List(); + foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) + { + LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(key); + supportedAttributes.Add(mapping.Name); - // var crossSection = Feature.Create(new LineString(new[] - // { - // new Coordinate(-1, 0), - // new Coordinate(1, 0) - // })); + 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); + } + } - // var attributeLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(0, -1), - // new Coordinate(0, 1) - // })); + const string locationId = "Test_Location_01"; - // foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) - // { - // LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(key); - // supportedAttributes.Add(mapping.Name); + 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 + }; - // 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); - // } - // } + mockImporter.Targets = new List + { + location + }; - // const string locationId = "Test_Location_01"; + mockImporter.GetCrossSectionRepository(Arg.Any()).Returns(crossSectionRepository); - // 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 - // }; + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + crossSection.AddAttribute(crossSectionMapping.Name, locationId); + crossSectionRepository.Features.Returns(new[] + { + crossSection + }); + mockImporter.GetAttributeName(Arg.Any()).Returns(crossSectionMapping.Name); - // mockImporter.Targets = new List - // { - // location - // }; + attributeRepository.SupportedAttributes.Returns(supportedAttributes); + attributeRepository.Features.Returns(new[] + { + attributeLine + }); + attributeRepository.Query(Arg.Any()).Returns(new[] + { + attributeLine + }); - // Expect.Call(mockImporter.GetCrossSectionRepository(null)).IgnoreArguments().Return(crossSectionRepository); + var file = new ShapeFileLocation("test.shp"); + string[] lines = + { + "First line", + "Second line", + "Third line" + }; + File.WriteAllLines(file.FullPath, lines); - // LocationAttributeMapping 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); + mockImporter.GetFile(Arg.Any()).Returns(file); + mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository); + // file. + foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) + { + mockImporter.RegisterAttributeMapping(key, null); + } - // Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); - // Expect.Call(attributeRepository.Features).Return(new[] - // { - // attributeLine - // }); - // Expect.Call(attributeRepository.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // attributeLine - // }); + mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); + mockImporter.Import(null); - // var file = new ShapeFileLocation("test.shp"); - // string[] lines = - // { - // "First line", - // "Second line", - // "Third line" - // }; - // File.WriteAllLines(file.FullPath, lines); + 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)); + } - // Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); - // Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); - // mocks.ReplayAll(); - // // file. - // foreach (string key in LocationShapeFileAttributeMap.AttributePropertyMap.Keys) - // { - // mockImporter.RegisterAttributeMapping(key, null); - // } + [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) + })); - // mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); - // mockImporter.Import(null); + var geom = Feature.Create(square); + geom.AddAttribute("test", 10); - // 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)); + LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); + var supportedAttributes = new List + { + mapping.Name + }; - // mocks.VerifyAll(); - //} + 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 + }); - //[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) - // })); + mockImporter.GetFile(Arg.Any()).Returns(file); + mockImporter.CreateFromShapeFile(Arg.Any()).Returns(attributeRepository); - // var geom = Feature.Create(square); - // geom.AddAttribute("test", 10); + var location = new CsvImporterLocations.LocationRecord + { + LocationId = "Location 1", + GeoX = 11, + GeoY = 11 + }; + mockImporter.Targets = new List + { + location + }; - // LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); - // var supportedAttributes = new List - // { - // mapping.Name - // }; + mockImporter.RegisterAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); + mockImporter.Import(null); - // 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((NetTopologySuite.Geometries.Geometry) null)).IgnoreArguments().Return(new[] - // { - // geom - // }); + Assert.That(mockImporter.ImportErrors.OfType().Count() == 1, Is.True, "The error list should contain an AttributeMissingException"); + } - // Expect.Call(mockImporter.GetFile(null)).IgnoreArguments().Return(file); - // Expect.Call(mockImporter.CreateFromShapeFile(null)).IgnoreArguments().Return(attributeRepository); + [Test] + [Category("Integration")] + public void Import_AttributeMissingUsingLineImporter_ErrorIsAddedToList() + { + var mockImporter = Substitute.For(); + var attributeRepository = Substitute.For(); + var crossSectionRepository = Substitute.For(); - // mocks.ReplayAll(); + var supportedAttributes = new List(); - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = "Location 1", - // GeoX = 11, - // GeoY = 11 - // }; - // mockImporter.Targets = new List - // { - // location - // }; + var crossSection = Feature.Create(new LineString(new[] + { + new Coordinate(-1, 0), + new Coordinate(1, 0) + })); - // mockImporter.RegisterAttributeMapping(LocationShapeFileAttributeMap.PenetrationLengthAttributeId); - // mockImporter.Import(null); + var attributeLine = Feature.Create(new LineString(new[] + { + new Coordinate(0, -1), + new Coordinate(0, 1) + })); - // Assert.That(mockImporter.ImportErrors.OfType().Count() == 1, Is.True, "The error list should contain an AttributeMissingException"); + attributeLine.AddAttribute("TEST_ATTR", 0); - // mocks.VerifyAll(); - //} + const string attributeId = LocationShapeFileAttributeMap.PolderLevelAttributeId; + LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(attributeId); + supportedAttributes.Add(mapping.Name); - //[Test] - //[Category("Integration")] - //public void Import_AttributeMissingUsingLineImporter_ErrorIsAddedToList() - //{ - // var mocks = new MockRepository(); - // var mockImporter = mocks.DynamicMock(); - // var attributeRepository = mocks.DynamicMock(); - // var crossSectionRepository = mocks.DynamicMock(); + const string locationId = "Test_Location_01"; - // var supportedAttributes = new List(); + var location = new CsvImporterLocations.LocationRecord + { + LocationId = locationId, + GeoX = 1, + GeoY = 1 + }; + mockImporter.Targets = new List + { + location + }; - // var crossSection = Feature.Create(new LineString(new[] - // { - // new Coordinate(-1, 0), - // new Coordinate(1, 0) - // })); + mockImporter.GetCrossSectionRepository(Arg.Any()).Returns(crossSectionRepository); - // var attributeLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(0, -1), - // new Coordinate(0, 1) - // })); + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + crossSection.AddAttribute(crossSectionMapping.Name, locationId); + crossSectionRepository.Features.Returns(new[] + { + crossSection + }); + mockImporter.GetAttributeName(Arg.Any()).Returns(crossSectionMapping.Name); - // attributeLine.AddAttribute("TEST_ATTR", 0); + attributeRepository.SupportedAttributes.Returns(supportedAttributes); + attributeRepository.Features.Returns(new[] + { + attributeLine + }); + attributeRepository.Query(Arg.Any()).Returns(new[] + { + attributeLine + }); - // const string attributeId = LocationShapeFileAttributeMap.PolderLevelAttributeId; - // LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(attributeId); - // supportedAttributes.Add(mapping.Name); + 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); - // const string locationId = "Test_Location_01"; + mockImporter.RegisterAttributeMapping(attributeId); + mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); + mockImporter.Import(null); - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = locationId, - // GeoX = 1, - // GeoY = 1 - // }; - // mockImporter.Targets = new List - // { - // location - // }; + Assert.That(mockImporter.ImportErrors.OfType().Count(), Is.EqualTo(1), "The error list should contain an AttributeMissingException"); + } - // Expect.Call(mockImporter.GetCrossSectionRepository(null)).IgnoreArguments().Return(crossSectionRepository); + [Test] + [Category("Integration")] + public void RegisterAttribute_AttributeNotSupported_GivesMessage() + { + var location = new CsvImporterLocations.LocationRecord + { + LocationId = "Location 1", + GeoX = 10, + GeoY = 10, + TrafficLoad = 0 + }; - // LocationAttributeMapping 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); + importer.Targets = new List + { + location + }; + importer.DataFileLocation = DirectoryWithDataShapeFiles; + importer.RegisterAttributeMapping("someattributeid", "test", TestShapeFile); + Assert.That(importer.ImproperAttributeMessages.Count, Is.EqualTo(1)); + } - // Expect.Call(attributeRepository.SupportedAttributes).Return(supportedAttributes); - // Expect.Call(attributeRepository.Features).Return(new[] - // { - // attributeLine - // }); - // Expect.Call(attributeRepository.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // attributeLine - // }); + [Test] + [Category("Integration")] + public void Import_PointOutsideGeometry_ErrorIsAddedToList() + { + var location = new CsvImporterLocations.LocationRecord + { + LocationId = "Location 1", + GeoX = 0.0, + GeoY = 0.0 + }; - // 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); + importer.Targets = new List + { + location + }; + importer.DataFileLocation = DirectoryWithDataShapeFiles; + importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile); + importer.Import(null); - // mocks.ReplayAll(); + if (importer.ImportErrors.OfType().Any()) + { + throw importer.ImportErrors.OfType().First(); + } - // mockImporter.RegisterAttributeMapping(attributeId); - // mockImporter.RegisterCrossSectionAttribute(crossSectionMapping.Name, crossSectionMapping.File); - // mockImporter.Import(null); + Assert.That(importer.ImportErrors.OfType().Count(), Is.EqualTo(1)); + } - // Assert.That(mockImporter.ImportErrors.OfType().Count(), Is.EqualTo(1), "The error list should contain an AttributeMissingException"); + [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 + }; - // mocks.VerifyAll(); - //} + importer.Targets = new List + { + location + }; + importer.DataFileLocation = DirectoryWithDataShapeFiles; + importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile); + importer.Import(null); - //[Test] - //[Category("Integration")] - //public void RegisterAttribute_AttributeNotSupported_GivesMessage() - //{ - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = "Location 1", - // GeoX = 10, - // GeoY = 10, - // TrafficLoad = 0 - // }; + Assert.That(location.TrafficLoad, Is.EqualTo(trafLoadValueInShapeFile)); + } - // importer.Targets = new List - // { - // location - // }; - // importer.DataFileLocation = DirectoryWithDataShapeFiles; - // importer.RegisterAttributeMapping("someattributeid", "test", TestShapeFile); - // Assert.That(importer.ImproperAttributeMessages.Count, Is.EqualTo(1)); - //} + #region Setup - //[Test] - //[Category("Integration")] - //public void Import_PointOutsideGeometry_ErrorIsAddedToList() - //{ - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = "Location 1", - // GeoX = 0.0, - // GeoY = 0.0 - // }; + [SetUp] + public void FixtureSetup() {} - // importer.Targets = new List - // { - // location - // }; - // importer.DataFileLocation = DirectoryWithDataShapeFiles; - // importer.RegisterAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId, TestShapeFile); - // importer.Import(null); + [TearDown] + public void FixtureTearDown() {} - // if (importer.ImportErrors.OfType().Any()) - // { - // throw importer.ImportErrors.OfType().First(); - // } + [SetUp] + public void TestSetup() + { + importer = new LocationPropertyImporter(); + } - // Assert.That(importer.ImportErrors.OfType().Count(), Is.EqualTo(1)); - //} + [TearDown] + public void TestTearDown() {} - //[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 + #endregion } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/PolygonAttributeImporterTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/PolygonAttributeImporterTest.cs (.../PolygonAttributeImporterTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Services/PolygonAttributeImporterTest.cs (.../PolygonAttributeImporterTest.cs) (revision 4890) @@ -23,333 +23,315 @@ using System.Linq; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; namespace Deltares.Maps.Tests.Services { [TestFixture] public class PolygonAttributeImporterTest { - //TODO: .net 6 replace by substitute - //private MockRepository mocks; - //private IFeatureRepository repository; + private IFeatureRepository repository; - //[Test] - //public void Import_TargetPointIsInPolygon_TargetPropertyIsSet() - //{ - // const string attributeName = "TrafLoad"; - // const double expected = 20; + [Test] + public void Import_TargetPointIsInPolygon_TargetPropertyIsSet() + { + const string attributeName = "TrafLoad"; + const double expected = 20; - // var target = new MockTarget - // { - // X = 0, - // Y = 0 - // }; + var target = new MockTarget + { + X = 0, + Y = 0 + }; - // var geometryRepository = new FeatureRepository(); - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // }, - // AttributeRepository = geometryRepository - // }; + var geometryRepository = new FeatureRepository(); + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + }, + AttributeRepository = geometryRepository + }; - // 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 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); - // geom.AddAttribute(attributeName, expected); - // geometryRepository.Add(geom); + var geom = Feature.Create(square); + geom.AddAttribute(attributeName, expected); + geometryRepository.Add(geom); - // mocks.ReplayAll(); + importer.Import(); - // importer.Import(); + Assert.That(target.Property1, Is.EqualTo(expected)); + } - // Assert.That(target.Property1, Is.EqualTo(expected)); - //} + [Test] + public void Import_TargetPointTouchesPolygon_TargetPropertyIsSet() + { + const string attributeName = "TrafLoad"; + const double expected = 20; - //[Test] - //public void Import_TargetPointTouchesPolygon_TargetPropertyIsSet() - //{ - // const string attributeName = "TrafLoad"; - // const double expected = 20; + var target = new MockTarget + { + X = -1, + Y = 1 + }; - // var target = new MockTarget - // { - // X = -1, - // Y = 1 - // }; + var geometryRepository = new FeatureRepository(); + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + }, + AttributeRepository = geometryRepository + }; - // var geometryRepository = new FeatureRepository(); - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // }, - // AttributeRepository = geometryRepository - // }; + 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 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); + geom.AddAttribute(attributeName, expected); + geometryRepository.Add(geom); - // var geom = Feature.Create(square); - // geom.AddAttribute(attributeName, expected); - // geometryRepository.Add(geom); + importer.Import(); - // mocks.ReplayAll(); + Assert.That(target.Property1, Is.EqualTo(expected)); + } - // importer.Import(); + [Test] + public void Import_TargetPointOutsidePolygon_TargetPropertyIsNotSet() + { + const string attributeName = "TrafLoad"; + const double expected = -999; - // Assert.That(target.Property1, Is.EqualTo(expected)); - //} + var target = new MockTarget + { + X = -2, + Y = 2, + Property1 = expected + }; - //[Test] - //public void Import_TargetPointOutsidePolygon_TargetPropertyIsNotSet() - //{ - // const string attributeName = "TrafLoad"; - // const double expected = -999; + var geometryRepository = new FeatureRepository(); + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + }, + AttributeRepository = geometryRepository + }; - // var target = new MockTarget - // { - // X = -2, - // Y = 2, - // Property1 = expected - // }; + 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 geometryRepository = new FeatureRepository(); - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // }, - // AttributeRepository = geometryRepository - // }; + var geom = Feature.Create(square); + geom.AddAttribute(attributeName, expected); + geometryRepository.Add(geom); - // 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) - // })); + importer.Import(); - // var geom = Feature.Create(square); - // geom.AddAttribute(attributeName, expected); - // geometryRepository.Add(geom); + Assert.That(target.Property1, Is.EqualTo(expected)); + } - // mocks.ReplayAll(); + [Test] + public void Import_RepositoryContainsNoAttributes_Throws() + { + const string attributeName = "TrafLoad"; - // importer.Import(); + var target = new MockTarget + { + X = 0, + Y = 0 + }; - // Assert.That(target.Property1, Is.EqualTo(expected)); - //} + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + }, + AttributeRepository = repository + }; - //[Test] - //public void Import_RepositoryContainsNoAttributes_Throws() - //{ - // const string attributeName = "TrafLoad"; + repository.SupportedAttributes.Returns(new List()); - // var target = new MockTarget - // { - // X = 0, - // Y = 0 - // }; + Assert.That(() => importer.Import(), Throws.InvalidOperationException); + } - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // }, - // AttributeRepository = repository - // }; + [Test] + public void Import_RepositoryNotSet_Throws() + { + const string attributeName = "TrafLoad"; - // Expect.Call(repository.SupportedAttributes).Return(new List()); - // mocks.ReplayAll(); + var target = new MockTarget + { + X = 0, + Y = 0 + }; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException); - //} + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + } + }; - //[Test] - //public void Import_RepositoryNotSet_Throws() - //{ - // const string attributeName = "TrafLoad"; + Assert.That(() => importer.Import(), Throws.InvalidOperationException); + } - // var target = new MockTarget - // { - // X = 0, - // Y = 0 - // }; + [Test] + public void Import_AttributeNameMissing_ErrorIsAddedToList() + { + const string attributeName = "TrafLoad"; - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // } - // }; + var target = new MockTarget + { + X = 0, + Y = 0 + }; - // mocks.ReplayAll(); + var importer = new PolygonAttributeImporter + { + XGetter = t => t.X, + YGetter = t => t.Y, + Targets = new[] + { + target + }, + AttributeMappings = + new[] + { + new AttributeMapping + { + Name = attributeName, + Action = (t, value) => t.Property1 = (double) value + } + }, + AttributeRepository = repository + }; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException); - //} + 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) + })); - //[Test] - //public void Import_AttributeNameMissing_ErrorIsAddedToList() - //{ - // const string attributeName = "TrafLoad"; + var feature = Feature.Create(square); + const string testAttribute = "test"; + feature.AddAttribute(testAttribute, new object()); - // var target = new MockTarget - // { - // X = 0, - // Y = 0 - // }; + repository.Query(Arg.Any()).Returns(new[] + { + feature + }); + repository.SupportedAttributes.Returns(new[] + { + testAttribute + }); - // var importer = new PolygonAttributeImporter - // { - // XGetter = t => t.X, - // YGetter = t => t.Y, - // Targets = new[] - // { - // target - // }, - // AttributeMappings = - // new[] - // { - // new AttributeMapping - // { - // Name = attributeName, - // Action = (t, value) => t.Property1 = (double) value - // } - // }, - // AttributeRepository = repository - // }; + importer.Import(); - // 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) - // })); + Assert.That(importer.Errors.OfType().Count(), Is.EqualTo(1)); + } - // var feature = Feature.Create(square); - // const string testAttribute = "test"; - // feature.AddAttribute(testAttribute, new object()); + class MockTarget + { + public double X { get; set; } + public double Y { get; set; } + public double Property1 { get; set; } + } - // //Expect.Call(repository.Features).Return(new[] { feature }); - // Expect.Call(repository.Query((Geometry) null)).IgnoreArguments().Return(new[] - // { - // feature - // }); - // Expect.Call(repository.SupportedAttributes).Return(new[] - // { - // testAttribute - // }); + #region Setup - // mocks.ReplayAll(); + [SetUp] + public void FixtureSetup() + { + repository = Substitute.For(); + } - // importer.Import(); + [TearDown] + public void FixtureTearDown() {} - // Assert.That(importer.Errors.OfType().Count(), Is.EqualTo(1)); - //} + [SetUp] + public void TestSetup() {} - //class MockTarget - //{ - // public double X { get; set; } - // public double Y { get; set; } - // public double Property1 { get; set; } - //} + [TearDown] + public void TestTearDown() {} - //#region Setup - - //[SetUp] - //public void FixtureSetup() - //{ - // mocks = new MockRepository(); - // repository = mocks.DynamicMock(); - //} - - //[TearDown] - //public void FixtureTearDown() {} - - //[SetUp] - //public void TestSetup() {} - - //[TearDown] - //public void TestTearDown() - //{ - // mocks.VerifyAll(); - //} - - //#endregion + #endregion } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationShapeFileImporterTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationShapeFileImporterTest.cs (.../LocationShapeFileImporterTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LocationShapeFileImporterTest.cs (.../LocationShapeFileImporterTest.cs) (revision 4890) @@ -26,178 +26,165 @@ using Deltares.Maps; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; using DataAttribute = Deltares.Dam.Data.DataPlugins.Configuration.DataAttribute; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LocationShapeFileImporterTest { - //TODO: .net 6 replace by substitute - //private ICollection locations; - //private LocationShapeFileImporter importer; - //private MockRepository mocks; - //private IFeatureRepository repository; - //private Feature loc3, loc4; + private ICollection locations; + private LocationShapeFileImporter importer; + private IFeatureRepository repository; + private Feature loc3, loc4; - //[Test] - //public void Importer_GivenEmptyLocationList_ShouldNotThrow() - //{ - // Assert.DoesNotThrow(() => - // { - // _ = new LocationShapeFileImporter(null, null); - // mocks.ReplayAll(); - // }); - //} + [Test] + public void Importer_GivenEmptyLocationList_ShouldNotThrow() + { + Assert.DoesNotThrow(() => + { + _ = new LocationShapeFileImporter(null, null); + }); + } - //[Test] - //public void Importer_UsingValidConfiguredAttributed_NewLocationsAddedToImportedItems() - //{ - // const string locAttributeName = "LID"; - // const string dridAttributeName = "DRID"; + [Test] + public void Importer_UsingValidConfiguredAttributed_NewLocationsAddedToImportedItems() + { + const string locAttributeName = "LID"; + const string dridAttributeName = "DRID"; - // var configuredAttributes = new List - // { - // new DataAttribute - // { - // AttributeId = LocationShapeFileAttributeMap.LocationAttributeId, - // AttributeName = locAttributeName - // }, - // new DataAttribute - // { - // AttributeId = LocationShapeFileAttributeMap.DikeRingAttributeId, - // AttributeName = dridAttributeName - // } - // }; + var configuredAttributes = new List + { + new DataAttribute + { + AttributeId = LocationShapeFileAttributeMap.LocationAttributeId, + AttributeName = locAttributeName + }, + new DataAttribute + { + AttributeId = LocationShapeFileAttributeMap.DikeRingAttributeId, + AttributeName = dridAttributeName + } + }; - // importer = new LocationShapeFileImporter(locations, configuredAttributes) - // { - // Repository = repository - // }; + importer = new LocationShapeFileImporter(locations, configuredAttributes) + { + Repository = repository + }; - // var l3 = Feature.Create(new Coordinate(1, 1)); - // l3.AddAttribute(locAttributeName, "loc3"); - // l3.AddAttribute(dridAttributeName, "ring5"); + var l3 = Feature.Create(new Coordinate(1, 1)); + l3.AddAttribute(locAttributeName, "loc3"); + l3.AddAttribute(dridAttributeName, "ring5"); - // var l4 = Feature.Create(new Coordinate(2, 2)); - // l4.AddAttribute(locAttributeName, "loc4"); - // l4.AddAttribute(dridAttributeName, "ring5"); + var l4 = Feature.Create(new Coordinate(2, 2)); + l4.AddAttribute(locAttributeName, "loc4"); + l4.AddAttribute(dridAttributeName, "ring5"); - // Expect.Call(repository.Features).Return(new[] - // { - // l3, - // l4 - // }); + repository.Features.Returns(new[] + { + l3, + l4 + }); - // mocks.ReplayAll(); + importer.Import(); - // importer.Import(); + Assert.That(importer.ImportedItems.Count(), Is.EqualTo(4)); + } - // Assert.That(importer.ImportedItems.Count(), Is.EqualTo(4)); - //} + [Test] + public void Import_UsingValidRepository_NewLocationsAddedToImportedItems() + { + var configuredAttributes = new List + { + new DataAttribute + { + AttributeId = LocationShapeFileAttributeMap.LocationAttributeId + }, + new DataAttribute + { + AttributeId = LocationShapeFileAttributeMap.DikeRingAttributeId + } + }; - //[Test] - //public void Import_UsingValidRepository_NewLocationsAddedToImportedItems() - //{ - // var configuredAttributes = new List - // { - // new DataAttribute - // { - // AttributeId = LocationShapeFileAttributeMap.LocationAttributeId - // }, - // new DataAttribute - // { - // AttributeId = LocationShapeFileAttributeMap.DikeRingAttributeId - // } - // }; + // Add existing location to test if that is handled correctly + var location = new CsvImporterLocations.LocationRecord + { + LocationId = "loc3", + DikeRingId = "ring5", + GeoX = 111.11, + GeoY = 222.22 + }; + locations = new List + { + location + }; + importer = new LocationShapeFileImporter(locations, configuredAttributes) + { + Repository = repository + }; - // // Add existing location to test if that is handled correctly - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = "loc3", - // DikeRingId = "ring5", - // GeoX = 111.11, - // GeoY = 222.22 - // }; - // locations = new List - // { - // location - // }; - // importer = new LocationShapeFileImporter(locations, configuredAttributes) - // { - // Repository = repository - // }; + repository.Features.Returns(new[] + { + loc3, + loc4 + }); - // Expect.Call(repository.Features).Return(new[] - // { - // loc3, - // loc4 - // }); + importer.Import(); - // mocks.ReplayAll(); + // ImportedItems should contain the total list of imported locations + // In this test a location is already in the locations list having same id as + // one feature returned by the feature repository + // This will cause that the importer overriders the existing location + // because of having the same name (id) + // Total should be 2 + Assert.That(importer.ImportedItems.Count(), Is.EqualTo(2)); - // importer.Import(); + CsvImporterLocations.LocationRecord location2 = importer.ImportedItems.Single(l => l.LocationId == "loc3"); + Assert.That(loc3.Geometry.Coordinate.X, Is.EqualTo(location2.GeoX)); + Assert.That(loc3.Geometry.Coordinate.Y, Is.EqualTo(location2.GeoY)); + } - // // ImportedItems should contain the total list of imported locations - // // In this test a location is already in the locations list having same id as - // // one feature returned by the feature repository - // // This will cause that the importer overriders the existing location - // // because of having the same name (id) - // // Total should be 2 - // Assert.That(importer.ImportedItems.Count(), Is.EqualTo(2)); + #region Setup/Teardown - // CsvImporterLocations.LocationRecord location2 = importer.ImportedItems.Single(l => l.LocationId == "loc3"); - // Assert.That(loc3.Geometry.Coordinate.X, Is.EqualTo(location2.GeoX)); - // Assert.That(loc3.Geometry.Coordinate.Y, Is.EqualTo(location2.GeoY)); - //} + [SetUp] + public void FixtureSetup() {} - //#region Setup/Teardown + [SetUp] + public void TestSetup() + { + locations = new List + { + new CsvImporterLocations.LocationRecord + { + LocationId = "Location1" + }, + new CsvImporterLocations.LocationRecord + { + LocationId = "Location2" + } + }; - //[SetUp] - //public void FixtureSetup() - //{ - // mocks = new MockRepository(); - //} + repository = Substitute.For(); - //[SetUp] - //public void TestSetup() - //{ - // locations = new List - // { - // new CsvImporterLocations.LocationRecord - // { - // LocationId = "Location1" - // }, - // new CsvImporterLocations.LocationRecord - // { - // LocationId = "Location2" - // } - // }; + LocationAttributeMapping lm = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.LocationAttributeId); + LocationAttributeMapping drm = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.DikeRingAttributeId); - // repository = mocks.DynamicMock(); + loc3 = Feature.Create(new Coordinate(1, 1)); + loc3.AddAttribute(lm.Name, "loc3"); + loc3.AddAttribute(drm.Name, "ring5"); - // LocationAttributeMapping lm = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.LocationAttributeId); - // LocationAttributeMapping drm = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.DikeRingAttributeId); + loc4 = Feature.Create(new Coordinate(2, 2)); + loc4.AddAttribute(lm.Name, "loc4"); + loc4.AddAttribute(drm.Name, "ring5"); + } - // loc3 = Feature.Create(new Coordinate(1, 1)); - // loc3.AddAttribute(lm.Name, "loc3"); - // loc3.AddAttribute(drm.Name, "ring5"); + [TearDown] + public void TestTearDown() {} - // loc4 = Feature.Create(new Coordinate(2, 2)); - // loc4.AddAttribute(lm.Name, "loc4"); - // loc4.AddAttribute(drm.Name, "ring5"); - //} + [TearDown] + public void FixtureTearDown() {} - //[TearDown] - //public void TestTearDown() - //{ - // mocks.VerifyAll(); - //} - - //[TearDown] - //public void FixtureTearDown() {} - - //#endregion + #endregion } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LineAttributeImporterTest.cs =================================================================== diff -u -r4813 -r4890 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LineAttributeImporterTest.cs (.../LineAttributeImporterTest.cs) (revision 4813) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Importers/LineAttributeImporterTest.cs (.../LineAttributeImporterTest.cs) (revision 4890) @@ -28,355 +28,343 @@ using Deltares.Maps; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LineAttributeImporterTest { - //TODO: .net 6 replace by substitute + private IFeatureRepository crossSectionRepository, attributesRepository; + private Feature crossSection, attributeLine, outsideLine; - //private MockRepository mocks; - //private IFeatureRepository crossSectionRepository, attributesRepository; - //private Feature crossSection, attributeLine, outsideLine; + private LineAttributeImporter importer; - //private LineAttributeImporter importer; + [Test] + public void Import_NoRepositorySet_Throws() + { + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("No repository set")); + } - //[Test] - //public void Import_NoRepositorySet_Throws() - //{ - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("No repository set")); - //} + [Test] + public void Import_NoAttributesInRepository_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The repository doesn't contain attributes")); + } - //[Test] - //public void Import_NoAttributesInRepository_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The repository doesn't contain attributes")); - //} + [Test] + public void Import_LocationIDEmpty_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + importer.AttributeRepository.Add(Feature.Create(0, 0, new[] + { + new KeyValuePair("test", 0) + })); + importer.LocationIDAttributeName = ""; + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); + } - //[Test] - //public void Import_LocationIDEmpty_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // importer.AttributeRepository.Add(Feature.Create(0, 0, new[] - // { - // new KeyValuePair("test", 0) - // })); - // importer.LocationIDAttributeName = ""; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); - //} + [Test] + public void Import_LocationIDNull_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + importer.AttributeRepository.Add(Feature.Create(0, 0, new[] + { + new KeyValuePair("test", 0) + })); + importer.LocationIDAttributeName = null; + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); + } - //[Test] - //public void Import_LocationIDNull_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // importer.AttributeRepository.Add(Feature.Create(0, 0, new[] - // { - // new KeyValuePair("test", 0) - // })); - // importer.LocationIDAttributeName = null; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); - //} + [Test] + public void Import_LocationIDWhiteSpace_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + importer.AttributeRepository.Add(Feature.Create(0, 0, new[] + { + new KeyValuePair("test", 0) + })); + importer.LocationIDAttributeName = " "; + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); + } - //[Test] - //public void Import_LocationIDWhiteSpace_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // importer.AttributeRepository.Add(Feature.Create(0, 0, new[] - // { - // new KeyValuePair("test", 0) - // })); - // importer.LocationIDAttributeName = " "; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("The location ID attribute name is not valid")); - //} + [Test] + public void Import_NoCrossSectionSet_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + importer.AttributeRepository.Add(Feature.Create(0, 0, new[] + { + new KeyValuePair("test", 0) + })); + importer.LocationIDAttributeName = "Test"; + Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("No cross section repository set")); + } - //[Test] - //public void Import_NoCrossSectionSet_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // importer.AttributeRepository.Add(Feature.Create(0, 0, new[] - // { - // new KeyValuePair("test", 0) - // })); - // importer.LocationIDAttributeName = "Test"; - // Assert.That(() => importer.Import(), Throws.InvalidOperationException.With.Message.EqualTo("No cross section repository set")); - //} + [Test] + public void Import_NoAttributeMappingListSet_Throws() + { + importer.AttributeRepository = new FeatureRepository(); + importer.AttributeRepository.Add(Feature.Create(0, 0, new[] + { + new KeyValuePair("test", 0) + })); + importer.CrossSectionRepository = new FeatureRepository(); + importer.LocationIDAttributeName = "Test"; + Assert.That(() => importer.Import(), + Throws.InvalidOperationException.With.Message.EqualTo("No attribute mappings set")); + } - //[Test] - //public void Import_NoAttributeMappingListSet_Throws() - //{ - // importer.AttributeRepository = new FeatureRepository(); - // importer.AttributeRepository.Add(Feature.Create(0, 0, new[] - // { - // new KeyValuePair("test", 0) - // })); - // importer.CrossSectionRepository = new FeatureRepository(); - // importer.LocationIDAttributeName = "Test"; - // Assert.That(() => importer.Import(), - // Throws.InvalidOperationException.With.Message.EqualTo("No attribute mappings set")); - //} + [Test] + [Category("Integration")] + public void PerformanceOfImport_UsingSmallList_IsAcceptable() + { + string crossSectionFile = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\HHNKShapeFiles\Crosssection.shp"); + string attributeFile = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\HHNKShapeFiles\DampingFactorPL3.shp"); - //[Test] - //[Category("Integration")] - //public void PerformanceOfImport_UsingSmallList_IsAcceptable() - //{ - // string crossSectionFile = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\HHNKShapeFiles\Crosssection.shp"); - // string attributeFile = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\HHNKShapeFiles\DampingFactorPL3.shp"); + var locations = new List + { + new() + { + LocationId = "TPL_Hempolder_0010" + }, + new() + { + LocationId = "TPL_Hempolder_0020" + }, + new() + { + LocationId = "TPL_Hempolder_0030" + }, + new() + { + LocationId = "TPL_Hempolder_0040" + }, + new() + { + LocationId = "TPL_Hempolder_0050" + }, + new() + { + LocationId = "TPL_Hempolder_0060" + }, + new() + { + LocationId = "TPL_Hempolder_0070" + }, + new() + { + LocationId = "TPL_Hempolder_0080" + }, + new() + { + LocationId = "TPL_Hempolder_0090" + }, + new() + { + LocationId = "TPL_Hempolder_0100" + } + }; - // var locations = new List - // { - // new() - // { - // LocationId = "TPL_Hempolder_0010" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0020" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0030" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0040" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0050" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0060" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0070" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0080" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0090" - // }, - // new() - // { - // LocationId = "TPL_Hempolder_0100" - // } - // }; + IFeatureRepository crossSections = FeatureRepository.CreateFromShapeFile(crossSectionFile); + IFeatureRepository attributes = FeatureRepository.CreateFromShapeFile(attributeFile); - // IFeatureRepository crossSections = FeatureRepository.CreateFromShapeFile(crossSectionFile); - // IFeatureRepository attributes = FeatureRepository.CreateFromShapeFile(attributeFile); + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + importer.LocationIDAttributeName = crossSectionMapping.Name; - // LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); - // importer.LocationIDAttributeName = crossSectionMapping.Name; + importer.Targets = locations; + importer.CrossSectionRepository = crossSections; + importer.AttributeRepository = attributes; - // importer.Targets = locations; - // importer.CrossSectionRepository = crossSections; - // importer.AttributeRepository = attributes; + LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.DampingFactorPl3AttributeId); + importer.AttributeMappings = new[] + { + mapping + }; + importer.Import(); - // LocationAttributeMapping mapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.DampingFactorPl3AttributeId); - // importer.AttributeMappings = new[] - // { - // mapping - // }; - // importer.Import(); + Assert.That(locations.Count, Is.EqualTo(10)); + Assert.That(locations.First().LocationId, Is.EqualTo("TPL_Hempolder_0010")); + Assert.That(locations.Last().LocationId, Is.EqualTo("TPL_Hempolder_0100")); + } - // Assert.That(locations.Count, Is.EqualTo(10)); - // Assert.That(locations.First().LocationId, Is.EqualTo("TPL_Hempolder_0010")); - // Assert.That(locations.Last().LocationId, Is.EqualTo("TPL_Hempolder_0100")); - //} + [Test] + public void Import_IntersectionFoundBetweenCrossSectionAndAttributeLine_ValuesFromAttributeLineAreSetOnTarget() + { + const string locationId = "Test_Location_01"; + const double expectedValue = 5.7; + var location = new CsvImporterLocations.LocationRecord + { + LocationId = locationId + }; + importer.Targets = new[] + { + location + }; + importer.CrossSectionRepository = crossSectionRepository; + importer.AttributeRepository = attributesRepository; - //[Test] - //public void Import_IntersectionFoundBetweenCrossSectionAndAttributeLine_ValuesFromAttributeLineAreSetOnTarget() - //{ - // const string locationId = "Test_Location_01"; - // const double expectedValue = 5.7; - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = locationId - // }; - // importer.Targets = new[] - // { - // location - // }; - // importer.CrossSectionRepository = crossSectionRepository; - // importer.AttributeRepository = attributesRepository; + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + crossSection.AddAttribute(crossSectionMapping.Name, locationId); + crossSectionRepository.Features.Returns(new[] + { + crossSection + }); + importer.LocationIDAttributeName = crossSectionMapping.Name; - // LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); - // crossSection.AddAttribute(crossSectionMapping.Name, locationId); - // Expect.Call(crossSectionRepository.Features).Return(new[] - // { - // crossSection - // }); - // importer.LocationIDAttributeName = crossSectionMapping.Name; + LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); + importer.AttributeMappings = new[] + { + trafLoadMapping + }; + attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); + attributesRepository.Query(Arg.Any()).Returns(new[] + { + attributeLine + }); + attributesRepository.SupportedAttributes.Returns(new[] + { + LocationShapeFileAttributeMap.TrafficLoadAttributeId + }); - // LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); - // importer.AttributeMappings = new[] - // { - // trafLoadMapping - // }; - // attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); - // Expect.Call(attributesRepository.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // attributeLine - // }); - // Expect.Call(attributesRepository.SupportedAttributes).Return(new[] - // { - // LocationShapeFileAttributeMap.TrafficLoadAttributeId - // }); + importer.Import(); - // mocks.ReplayAll(); + Assert.That(location.TrafficLoad, Is.EqualTo(expectedValue)); + } - // importer.Import(); + [Test] + public void Import_NoIntersectionFoundBetweenCrossSectionAndOutsideLine_ValuesFromAttributeLineAreNotSetOnTarget() + { + const string locationId = "Test_Location_02"; + const double expectedValue = 5.7; + var location = new CsvImporterLocations.LocationRecord + { + LocationId = locationId, + TrafficLoad = expectedValue + }; + importer.Targets = new[] + { + location + }; + importer.CrossSectionRepository = crossSectionRepository; + importer.AttributeRepository = attributesRepository; - // Assert.That(location.TrafficLoad, Is.EqualTo(expectedValue)); - //} + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + crossSection.AddAttribute(crossSectionMapping.Name, locationId); + crossSectionRepository.Features.Returns(new[] + { + crossSection + }); + importer.LocationIDAttributeName = crossSectionMapping.Name; - //[Test] - //public void Import_NoIntersectionFoundBetweenCrossSectionAndOutsideLine_ValuesFromAttributeLineAreNotSetOnTarget() - //{ - // const string locationId = "Test_Location_02"; - // const double expectedValue = 5.7; - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = locationId, - // TrafficLoad = expectedValue - // }; - // importer.Targets = new[] - // { - // location - // }; - // importer.CrossSectionRepository = crossSectionRepository; - // importer.AttributeRepository = attributesRepository; + LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); + importer.AttributeMappings = new[] + { + trafLoadMapping + }; + attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); + attributesRepository.Query(Arg.Any()).Returns(new[] + { + outsideLine + }); + attributesRepository.SupportedAttributes.Returns(new[] + { + LocationShapeFileAttributeMap.TrafficLoadAttributeId + }); - // LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); - // crossSection.AddAttribute(crossSectionMapping.Name, locationId); - // Expect.Call(crossSectionRepository.Features).Return(new[] - // { - // crossSection - // }); - // importer.LocationIDAttributeName = crossSectionMapping.Name; + importer.Import(); - // LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); - // importer.AttributeMappings = new[] - // { - // trafLoadMapping - // }; - // attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); - // Expect.Call(attributesRepository.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // outsideLine - // }); - // Expect.Call(attributesRepository.SupportedAttributes).Return(new[] - // { - // LocationShapeFileAttributeMap.TrafficLoadAttributeId - // }); + Assert.That(location.TrafficLoad, Is.EqualTo(expectedValue)); + } - // mocks.ReplayAll(); + [Test] + public void Import_NoIntersectionFoundBetweenCrossSectionAndOutsideLine_ExceptionIsAdded() + { + const string locationId = "Test_Location_02"; + const double expectedValue = 5.7; + var location = new CsvImporterLocations.LocationRecord + { + LocationId = locationId, + TrafficLoad = expectedValue + }; + importer.Targets = new[] + { + location + }; + importer.CrossSectionRepository = crossSectionRepository; + importer.AttributeRepository = attributesRepository; - // importer.Import(); + LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); + crossSection.AddAttribute(crossSectionMapping.Name, locationId); + crossSectionRepository.Features.Returns(new[] + { + crossSection + }); + importer.LocationIDAttributeName = crossSectionMapping.Name; - // Assert.That(location.TrafficLoad, Is.EqualTo(expectedValue)); - //} + LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); + importer.AttributeMappings = new[] + { + trafLoadMapping + }; + attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); + attributesRepository.Query(Arg.Any()).Returns(new[] + { + outsideLine + }); + attributesRepository.SupportedAttributes.Returns(new[] + { + LocationShapeFileAttributeMap.TrafficLoadAttributeId + }); - //[Test] - //public void Import_NoIntersectionFoundBetweenCrossSectionAndOutsideLine_ExceptionIsAdded() - //{ - // const string locationId = "Test_Location_02"; - // const double expectedValue = 5.7; - // var location = new CsvImporterLocations.LocationRecord - // { - // LocationId = locationId, - // TrafficLoad = expectedValue - // }; - // importer.Targets = new[] - // { - // location - // }; - // importer.CrossSectionRepository = crossSectionRepository; - // importer.AttributeRepository = attributesRepository; + importer.Import(); - // LocationAttributeMapping crossSectionMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.CrossSectionAttributId); - // crossSection.AddAttribute(crossSectionMapping.Name, locationId); - // Expect.Call(crossSectionRepository.Features).Return(new[] - // { - // crossSection - // }); - // importer.LocationIDAttributeName = crossSectionMapping.Name; + Assert.That(importer.Errors.OfType().Count(), Is.EqualTo(1), "The NotSupported error was not added to the error list for logging when no intersections are found. "); + } - // LocationAttributeMapping trafLoadMapping = LocationShapeFileAttributeMap.GetAttributeMapping(LocationShapeFileAttributeMap.TrafficLoadAttributeId); - // importer.AttributeMappings = new[] - // { - // trafLoadMapping - // }; - // attributeLine.AddAttribute(trafLoadMapping.Name, expectedValue); - // Expect.Call(attributesRepository.Query((IFeature) null)).IgnoreArguments().Return(new[] - // { - // outsideLine - // }); - // Expect.Call(attributesRepository.SupportedAttributes).Return(new[] - // { - // LocationShapeFileAttributeMap.TrafficLoadAttributeId - // }); + #region Fixture Setup/Teardown - // mocks.ReplayAll(); + [SetUp] + public void FixtureSetup() {} - // importer.Import(); + [TearDown] + public void FixtureTearDown() {} - // Assert.That(importer.Errors.OfType().Count(), Is.EqualTo(1), "The NotSupported error was not added to the error list for logging when no intersections are found. "); - //} + #endregion - //#region Fixture Setup/Teardown + #region Setup/Teardown - //[SetUp] - //public void FixtureSetup() - //{ - // mocks = new MockRepository(); - //} + [SetUp] + public void TestSetup() + { + importer = new LineAttributeImporter(); - //[TearDown] - //public void FixtureTearDown() {} + crossSectionRepository = Substitute.For(); + attributesRepository = Substitute.For(); - //#endregion + crossSection = Feature.Create(new LineString(new[] + { + new Coordinate(-1, 0), + new Coordinate(1, 0) + })); - //#region Setup/Teardown + attributeLine = Feature.Create(new LineString(new[] + { + new Coordinate(0, -1), + new Coordinate(0, 1) + })); - //[SetUp] - //public void TestSetup() - //{ - // importer = new LineAttributeImporter(); + // this line should not touch + outsideLine = Feature.Create(new LineString(new[] + { + new Coordinate(10, -1), + new Coordinate(10, 1) + })); + } - // crossSectionRepository = mocks.DynamicMock(); - // attributesRepository = mocks.DynamicMock(); + [TearDown] + public void TestTearDown() {} - // crossSection = Feature.Create(new LineString(new[] - // { - // new Coordinate(-1, 0), - // new Coordinate(1, 0) - // })); - - // attributeLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(0, -1), - // new Coordinate(0, 1) - // })); - - // // this line should not touch - // outsideLine = Feature.Create(new LineString(new[] - // { - // new Coordinate(10, -1), - // new Coordinate(10, 1) - // })); - //} - - //[TearDown] - //public void TestTearDown() {} - - //#endregion + #endregion } } \ No newline at end of file