using System; 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 MapPolygonDataTest { [Test] public void Constructor_NullPoints_ThrowsArgumentNullException() { // Call TestDelegate test = () => new MapPolygonData(null, "test data"); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, string.Format("A feature collection is required when creating a subclass of {0}.", typeof(FeatureBasedMapData))); } [Test] [TestCase(null)] [TestCase("")] [TestCase(" ")] public void Constructor_InvalidName_ThrowsArgumentException(string invalidName) { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(Enumerable.Empty()) }) }; // Call TestDelegate test = () => new MapPolygonData(features, invalidName); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "A name must be set to map data"); } [Test] public void Constructor_WithEmptyPoints_CreatesNewMapPolygonData() { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(Enumerable.Empty()) }) }; // Call var data = new MapPolygonData(features, "test data"); // Assert Assert.IsInstanceOf(data); Assert.AreNotSame(features, data.Features); } [Test] public void Constructor_WithPoints_CreatesNewMapPolygonData() { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(CreateTestPoints()) }) }; // Call var data = new MapPolygonData(features, "test data"); // Assert Assert.IsInstanceOf(data); Assert.AreNotSame(features, data.Features); CollectionAssert.AreEqual(CreateTestPoints(), data.Features.First().MapGeometries.First().Points); } [Test] public void Constructor_WithName_SetsName() { // Setup var features = new Collection { new MapFeature(new Collection { new MapGeometry(Enumerable.Empty()) }) }; var name = "Some name"; // Call var data = new MapPolygonData(features, name); // Assert Assert.AreEqual(name, data.Name); } private static Collection CreateTestPoints() { return new Collection { new Point2D(0.0, 1.1), new Point2D(1.0, 2.1), new Point2D(1.6, 1.6) }; } } }