Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs =================================================================== diff -u -r1496f669024aeba114c77af3276e54f35642521f -r9a153c67ff2fe11d068c3e5516093e3a39a0437c --- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision 1496f669024aeba114c77af3276e54f35642521f) +++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapLineDataConverterTest.cs (.../MapLineDataConverterTest.cs) (revision 9a153c67ff2fe11d068c3e5516093e3a39a0437c) @@ -189,7 +189,7 @@ [TestCase(KnownColor.AliceBlue)] [TestCase(KnownColor.Azure)] [TestCase(KnownColor.Beige)] - public void Convert_MapDataStyleSetWithDifferentColors_AppliesStyleToLayer(KnownColor color) + public void Convert_LineStyleSetWithDifferentColors_AppliesStyleToLayer(KnownColor color) { // Setup var converter = new MapLineDataConverter(); @@ -210,7 +210,7 @@ [TestCase(1)] [TestCase(5)] [TestCase(7)] - public void Convert_MapDataStyleSetWithDifferentWidths_AppliesStyleToLayer(int width) + public void Convert_LineStyleSetWithDifferentWidths_AppliesStyleToLayer(int width) { // Setup var converter = new MapLineDataConverter(); @@ -230,7 +230,7 @@ [TestCase(DashStyle.Solid)] [TestCase(DashStyle.Dash)] [TestCase(DashStyle.Dot)] - public void Convert_MapDataStyleSetWithDifferentLineStyles_AppliesStyleToLayer(DashStyle lineStyle) + public void Convert_LineStyleSetWithDifferentLineStyles_AppliesStyleToLayer(DashStyle lineStyle) { // Setup var converter = new MapLineDataConverter(); Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs =================================================================== diff -u -r2737a3a45f330d73b3201c474ee75e7e4bfa3b2f -r9a153c67ff2fe11d068c3e5516093e3a39a0437c --- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs (.../MapPointDataConverterTest.cs) (revision 2737a3a45f330d73b3201c474ee75e7e4bfa3b2f) +++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapPointDataConverterTest.cs (.../MapPointDataConverterTest.cs) (revision 9a153c67ff2fe11d068c3e5516093e3a39a0437c) @@ -19,9 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; -using System.Data; using System.Drawing; using System.Linq; using Core.Common.Base.Geometry; @@ -35,6 +33,7 @@ using DotSpatial.Symbology; using DotSpatial.Topology; using NUnit.Framework; +using Point = DotSpatial.Topology.Point; using PointShape = DotSpatial.Symbology.PointShape; namespace Core.Components.DotSpatial.Test.Converter @@ -53,207 +52,103 @@ } [Test] - [TestCase(true)] - [TestCase(false)] - public void Convert_RandomPointDataWithoutAttributes_ReturnsNewMapPointLayerWithDefaultLabelLayer(bool showLabels) + public void Convert_SimpleMapPointData_ReturnMapPointLayer() { // Setup var converter = new MapPointDataConverter(); - var random = new Random(21); - var randomCount = random.Next(5, 10); - var features = new List(); - - for (var i = 0; i < randomCount; i++) - { - features.Add(new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(random.NextDouble(), random.NextDouble()) - } - }) - })); - } - var pointData = new MapPointData("test data") { - Features = features.ToArray(), - ShowLabels = showLabels + Features = new MapFeature[0] }; // Call IMapFeatureLayer layer = converter.Convert(pointData); // Assert - Assert.AreEqual(pointData.Features.Length, layer.DataSet.Features.Count); Assert.IsInstanceOf(layer); Assert.AreEqual(FeatureType.Point, layer.DataSet.FeatureType); - - IEnumerable points = pointData.Features.First().MapGeometries.First().PointCollections.First(); - CollectionAssert.AreEqual(points.Select(p => new Coordinate(p.X, p.Y)), layer.DataSet.Features[0].Coordinates); - Assert.AreEqual(showLabels, layer.ShowLabels); - CollectionAssert.IsEmpty(layer.DataSet.GetColumns()); - - Assert.IsNotNull(layer.LabelLayer); - Assert.AreEqual("FID", layer.LabelLayer.Symbology.Categories[0].Symbolizer.PriorityField); - Assert.IsNull(layer.LabelLayer.Symbology.Categories[0].Expression); } [Test] - public void Convert_RandomPointDataWithAttributesShowLabelsFalse_ReturnsNewMapPointLayerWithDefaultLabelLayer() + public void Convert_MapPointDataWithMultipleFeatures_ConvertsEachGeometryAsSingleFeature() { // Setup var converter = new MapPointDataConverter(); - var random = new Random(21); - var randomCount = random.Next(5, 10); - var features = new List(); - for (var i = 0; i < randomCount; i++) + MapFeature[] features = { - var mapFeature = new MapFeature(new[] + new MapFeature(new[] { new MapGeometry(new[] { new[] { - new Point2D(random.NextDouble(), random.NextDouble()) + new Point2D(1, 2) } }) - }); - mapFeature.MetaData["ID"] = random.NextDouble(); - mapFeature.MetaData["Name"] = string.Format("feature [{0}]", i); - - features.Add(mapFeature); - } - - var pointData = new MapPointData("test data") - { - Features = features.ToArray(), - ShowLabels = false - }; - - // Call - IMapFeatureLayer layer = converter.Convert(pointData); - - // Assert - Assert.AreEqual(pointData.Features.Length, layer.DataSet.Features.Count); - Assert.IsInstanceOf(layer); - Assert.AreEqual(FeatureType.Point, layer.DataSet.FeatureType); - - IEnumerable points = pointData.Features.First().MapGeometries.First().PointCollections.First(); - CollectionAssert.AreEqual(points.Select(p => new Coordinate(p.X, p.Y)), layer.DataSet.Features[0].Coordinates); - Assert.IsFalse(layer.ShowLabels); - - DataColumn[] dataColumns = layer.DataSet.GetColumns(); - Assert.AreEqual(2, dataColumns.Length); - Assert.AreEqual("1", dataColumns[0].ColumnName); - Assert.AreEqual("2", dataColumns[1].ColumnName); - - Assert.IsNotNull(layer.LabelLayer); - Assert.AreEqual("FID", layer.LabelLayer.Symbology.Categories[0].Symbolizer.PriorityField); - Assert.IsNull(layer.LabelLayer.Symbology.Categories[0].Expression); - } - - [Test] - [TestCase("ID", 1)] - [TestCase("Name", 2)] - public void Convert_RandomPointDataWithAttributesShowLabelsTrue_ReturnsNewMapPointLayerWithCustomLabelLayer(string selectedAttribute, int selectedAttributeId) - { - // Setup - var converter = new MapPointDataConverter(); - var random = new Random(21); - var randomCount = random.Next(5, 10); - var features = new List(); - - for (var i = 0; i < randomCount; i++) - { - var mapFeature = new MapFeature(new[] + }), + new MapFeature(Enumerable.Empty()), + new MapFeature(new[] { new MapGeometry(new[] { new[] { - new Point2D(random.NextDouble(), random.NextDouble()) + new Point2D(2, 3) } }) - }); - mapFeature.MetaData["ID"] = random.NextDouble(); - mapFeature.MetaData["Name"] = string.Format("feature [{0}]", i); + }), + new MapFeature(Enumerable.Empty()), + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(3, 4) + } + }), + new MapGeometry(new[] + { + new[] + { + new Point2D(5, 6) + } + }) + }) + }; - features.Add(mapFeature); - } - - var pointData = new MapPointData("test data") + var pointData = new MapPointData("test") { - Features = features.ToArray(), - ShowLabels = true, - SelectedMetaDataAttribute = selectedAttribute + Features = features }; // Call IMapFeatureLayer layer = converter.Convert(pointData); // Assert - Assert.AreEqual(pointData.Features.Length, layer.DataSet.Features.Count); - Assert.IsInstanceOf(layer); - Assert.AreEqual(FeatureType.Point, layer.DataSet.FeatureType); - - IEnumerable points = pointData.Features.First().MapGeometries.First().PointCollections.First(); - CollectionAssert.AreEqual(points.Select(p => new Coordinate(p.X, p.Y)), layer.DataSet.Features[0].Coordinates); - Assert.IsTrue(layer.ShowLabels); - - DataColumn[] dataColumns = layer.DataSet.GetColumns(); - Assert.AreEqual(2, dataColumns.Length); - Assert.AreEqual("1", dataColumns[0].ColumnName); - Assert.AreEqual("2", dataColumns[1].ColumnName); - - Assert.IsNotNull(layer.LabelLayer); - ILabelCategory labelCategory = layer.LabelLayer.Symbology.Categories[0]; - Assert.AreEqual("FID", labelCategory.Symbolizer.PriorityField); - Assert.AreEqual(ContentAlignment.MiddleRight, labelCategory.Symbolizer.Orientation); - Assert.AreEqual(5, labelCategory.Symbolizer.OffsetX); - Assert.AreEqual(string.Format("[{0}]", selectedAttributeId), labelCategory.Expression); + Assert.AreEqual(4, layer.DataSet.Features.Count); } [Test] - public void Convert_MultipleFeatures_ReturnsAllFeaturesWithOneGeometry() + public void Convert_MapPointDataWithFeature_ReturnMapPointLayerWithPointData() { // Setup var converter = new MapPointDataConverter(); - MapFeature[] features = + var mapFeature = new MapFeature(new[] { - new MapFeature(new[] + new MapGeometry(new[] { - new MapGeometry(new[] + new[] { - new[] - { - new Point2D(1, 2) - } - }) - }), - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(2, 3) - } - }) - }), - new MapFeature(new[] - { - new MapGeometry(new[] - { - new[] - { - new Point2D(4, 6) - } - }) + new Point2D(1, 2) + } }) + }); + + MapFeature[] features = + { + mapFeature }; var pointData = new MapPointData("test") @@ -265,29 +160,26 @@ IMapFeatureLayer layer = converter.Convert(pointData); // Assert + IFeature feature = layer.DataSet.Features[0]; Assert.AreEqual(features.Length, layer.DataSet.Features.Count); - layer.DataSet.InitializeVertices(); - Assert.AreEqual(3, layer.DataSet.ShapeIndices.Count); + Assert.IsInstanceOf(feature.BasicGeometry); - foreach (ShapeRange shapeIndex in layer.DataSet.ShapeIndices) - { - Assert.AreEqual(1, shapeIndex.NumParts); - } + var expectedCoordinates = mapFeature.MapGeometries.ElementAt(0).PointCollections.ElementAt(0).Select(p => new Coordinate(p.X, p.Y)); + CollectionAssert.AreEqual(expectedCoordinates, feature.Coordinates); } [Test] [TestCase(KnownColor.AliceBlue)] [TestCase(KnownColor.Azure)] [TestCase(KnownColor.Beige)] - public void Convert_WithDifferentColors_AppliesStyleToLayer(KnownColor color) + public void Convert_PointStyleSetWithDifferentColors_AppliesStyleToLayer(KnownColor color) { // Setup var converter = new MapPointDataConverter(); var expectedColor = Color.FromKnownColor(color); - var style = new PointStyle(expectedColor, 3, PointSymbol.Circle); var data = new MapPointData("test") { - Style = style + Style = new PointStyle(expectedColor, 3, PointSymbol.Circle) }; // Call @@ -301,14 +193,13 @@ [TestCase(1)] [TestCase(5)] [TestCase(7)] - public void Convert_WithDifferentWidths_AppliesStyleToLayer(int width) + public void Convert_PointStyleSetWithDifferentWidths_AppliesStyleToLayer(int width) { // Setup var converter = new MapPointDataConverter(); - var style = new PointStyle(Color.AliceBlue, width, PointSymbol.Circle); var data = new MapPointData("test") { - Style = style + Style = new PointStyle(Color.AliceBlue, width, PointSymbol.Circle) }; // Call @@ -322,14 +213,13 @@ [TestCase(PointSymbol.Circle)] [TestCase(PointSymbol.Square)] [TestCase(PointSymbol.Triangle)] - public void Convert_WithDifferentPointStyles_AppliesStyleToLayer(PointSymbol pointStyle) + public void Convert_PointStyleSetWithDifferentPointStyles_AppliesStyleToLayer(PointSymbol pointStyle) { // Setup var converter = new MapPointDataConverter(); - var style = new PointStyle(Color.AliceBlue, 3, pointStyle); var data = new MapPointData("test") { - Style = style + Style = new PointStyle(Color.AliceBlue, 3, pointStyle) }; // Call