// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System.Collections.Generic; using System.IO; using Deltares.Dam.Data.Importers; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.SurfaceLines; using Deltares.Maps; using GeoAPI.Geometries; using NetTopologySuite.Geometries; using NUnit.Framework; using Rhino.Mocks; using Location = Deltares.Dam.Data.Location; namespace Deltares.Dam.Tests.Importers { [TestFixture] public class LocationCharacteristicPointImporterTest { 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() { mocks.ReplayAll(); Assert.That(() => new LocationCharacteristicPointImporter(@"\someunknowndirectory", new List()), Throws.InstanceOf()); } [Test] public void ImportRepository_DoesNotContainTheRequiredAttributeLocationID_Throws() { importer = new LocationCharacteristicPointImporter(new List()) { CharacteristicLineRepository = characteresticLines, ProfileLocationsRepository = profiles }; //this.profileLine.AddAttribute(LocationProfileImporter.LocationIDAttributeName, new object()); profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); Expect.Call(profiles.Features).Return(new[] { profileLine }); Expect.Call(characteresticLines.Features).Return(new[] { characteristicLine }); mocks.ReplayAll(); Assert.That(() => importer.Import(), Throws.InvalidOperationException); } [Test] public void ImportRepository_DoesNotContainTheRequiredAttributeDikeID_Throws() { importer = new LocationCharacteristicPointImporter(new List()) { CharacteristicLineRepository = characteresticLines, ProfileLocationsRepository = profiles }; profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, new object()); //this.profileLine.AddAttribute(LocationProfileImporter.LocationDikeAttributeName, new object()); characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, new object()); Expect.Call(profiles.Features).Return(new[] { profileLine }); Expect.Call(characteresticLines.Features).Return(new[] { characteristicLine }); mocks.ReplayAll(); Assert.That(() => importer.Import(), Throws.InvalidOperationException); } [Test] public void ImportRepository_DoesNotContainARequiredAttribute_Throws() { importer = new LocationCharacteristicPointImporter(new List()) { CharacteristicLineRepository = characteresticLines, ProfileLocationsRepository = profiles }; //this.profileLine.AddAttribute(LocationProfileImporter.LocationIDAttributeName, new object()); //this.profileLine.AddAttribute(LocationProfileImporter.LocationDikeAttributeName, new object()); //this.characteristicLine.AddAttribute(LocationProfileImporter.CharacteristicLineAttributeName, new object()); Expect.Call(characteresticLines.Features).Return(new[] { characteristicLine }); //Expect.Call(profiles.Geometries).Return(new[] { this.profileLine }); mocks.ReplayAll(); Assert.That(() => importer.Import(), Throws.InvalidOperationException); } [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 = new LocationCharacteristicPointImporter(new List { location }) { CharacteristicLineRepository = characteresticLines, ProfileLocationsRepository = profiles }; profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationDikeAttributeName, new object()); profileLine.AddAttribute(LocationCharacteristicPointImporter.LocationIDAttributeName, locationID); characteristicLine.AddAttribute(LocationCharacteristicPointImporter.CharacteristicLineAttributeName, "kruin-binnen"); 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 }); mocks.ReplayAll(); importer.Import(); Assert.AreEqual(0, location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).X); Assert.AreEqual(0, location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(dikeTopAtPolder).Y); } } #region Setup [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 } }