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