// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Core.Components.Gis.Geometries; using NUnit.Framework; namespace Core.Components.Gis.Test.Data { [TestFixture] public class FeatureBasedMapDataTest { [Test] public void Constructor_WithoutPoints_ThrowsArgumentNullException() { // Call TestDelegate test = () => new TestFeatureBasedMapData(null, "some name"); // Assert var expectedMessage = "A feature collection is required when creating a subclass of Core.Components.Gis.Data.FeatureBasedMapData."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); } [Test] [TestCase(null)] [TestCase("")] [TestCase(" ")] public void Constructor_InvalidName_ThrowsArgumentException(string invalidName) { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(new[] { Enumerable.Empty() }) }) }; // Call TestDelegate test = () => new TestFeatureBasedMapData(features, invalidName); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "A name must be set to map data"); } [Test] public void Constructor_WithPoints_PropertiesSet() { // Setup var points = new[] { new Point2D(0.0, 1.0), new Point2D(2.5, 1.1) }; var features = new[] { new MapFeature(new[] { new MapGeometry(new[] { points }) }) }; // Call var data = new TestFeatureBasedMapData(features, "some name"); // Assert Assert.AreNotSame(features, data.Features); Assert.AreEqual(features.Length, data.Features.Count()); Assert.AreEqual(features[0].MapGeometries.Count(), data.Features.First().MapGeometries.Count()); CollectionAssert.AreEqual(points, data.Features.First().MapGeometries.First().PointCollections.First()); } [Test] public void Constructor_WithName_SetsName() { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(new[] { Enumerable.Empty() }) }) }; var name = "Some name"; // Call var data = new TestFeatureBasedMapData(features, name); // Assert Assert.AreEqual(name, data.Name); } private class TestFeatureBasedMapData : FeatureBasedMapData { public TestFeatureBasedMapData(IEnumerable features, string name) : base(features, name) { } } } }