public void ConvertLayerFeatures_LayerWithDataInDifferentCoordinateSystem_CreatedPointIsNotReprojected()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapLayer      = new TestFeatureLayer
            {
                Projection = KnownCoordinateSystems.Geographic.World.WGS1984
            };
            var mapData = new TestFeatureBasedMapData("test")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>()) // TestFeatureBasedMapDataConverter will generate a Point feature at (1.1, 2.2)
                }
            };

            testConverter.ConvertLayerFeatures(mapData, mapLayer);
            mapLayer.Projection = MapDataConstants.FeatureBasedMapDataCoordinateSystem;

            // Call
            testConverter.ConvertLayerFeatures(mapData, mapLayer);

            // Assert
            Assert.AreEqual(1, mapLayer.FeatureSet.Features.Count);
            Assert.AreEqual(1.1, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].X);
            Assert.AreEqual(2.2, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].Y);
            Assert.AreEqual(MapDataConstants.FeatureBasedMapDataCoordinateSystem, mapLayer.Projection);
        }
        public void ConvertLayerProperties_MapDataWithoutMetaData_DefaultLabelLayerSetToLayer()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapData       = new TestFeatureBasedMapData("test data")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                },
                SelectedMetaDataAttribute = "Name"
            };
            var mapLayer = new TestFeatureLayer
            {
                DataSet =
                {
                    DataTable   =
                    {
                        Columns =
                        {
                            "1",
                            "2"
                        }
                    }
                }
            };

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.IsNotNull(mapLayer.LabelLayer);
            Assert.AreEqual("FID", mapLayer.LabelLayer.Symbology.Categories[0].Symbolizer.PriorityField);
            Assert.IsNull(mapLayer.LabelLayer.Symbology.Categories[0].Expression);
        }
        public void ConvertLayerFeatures_LayerInDifferentSystemAsMapData_CreatedPointIsReprojected()
        {
            // Setup
            var            testConverter    = new TestFeatureBasedMapDataConverter();
            ProjectionInfo coordinateSystem = KnownCoordinateSystems.Geographic.World.WGS1984;
            var            mapLayer         = new TestFeatureLayer
            {
                Projection = coordinateSystem
            };
            var mapData = new TestFeatureBasedMapData("test")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>()) // TestFeatureBasedMapDataConverter will generate a Point feature at (1.1, 2.2)
                }
            };

            // Call
            testConverter.ConvertLayerFeatures(mapData, mapLayer);

            // Assert
            Assert.AreEqual(1, mapLayer.FeatureSet.Features.Count);
            Assert.AreEqual(3.3135717854013329, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].X);
            Assert.AreEqual(47.974786294874853, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].Y);
            Assert.AreEqual(coordinateSystem, mapLayer.Projection);
        }
        public void ConvertLayerFeatures_LayerWithoutCoordinateSystem_CreatePointFeatureInMapDataCoordinateSystem()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapLayer      = new TestFeatureLayer
            {
                Projection = null
            };
            var mapData = new TestFeatureBasedMapData("test")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>()) // TestFeatureBasedMapDataConverter will generate a Point feature at (1.1, 2.2)
                }
            };

            // Call
            testConverter.ConvertLayerFeatures(mapData, mapLayer);

            // Assert
            Assert.AreEqual(1, mapLayer.FeatureSet.Features.Count);
            Assert.AreEqual(1.1, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].X);
            Assert.AreEqual(2.2, mapLayer.FeatureSet.Features[0].Geometry.Coordinates[0].Y);
            Assert.AreEqual(MapDataConstants.FeatureBasedMapDataCoordinateSystem, mapLayer.Projection);
        }
        public void GivenLayerWithConvertedProperties_WhenConvertingLayerFeatures_ThenOnlyDefaultCategoryAdded()
        {
            // Given
            var mocks           = new MockRepository();
            var defaultCategory = mocks.Stub <IPointCategory>();
            var categoryOne     = mocks.Stub <IPointCategory>();
            var categoryTwo     = mocks.Stub <IPointCategory>();

            mocks.ReplayAll();

            const string metadataAttributeName = "Meta";
            var          theme = new MapTheme <TestCategoryTheme>(metadataAttributeName, new[]
            {
                new TestCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion())
            });
            var mapData = new TestFeatureBasedMapData("test data", theme)
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                metadataAttributeName, new object()
                            }
                        }
                    }
                }
            };

            var scheme = new PointScheme();

            scheme.Categories.Clear();
            scheme.Categories.Add(categoryOne);
            scheme.Categories.Add(categoryTwo);

            var mapLayer = new TestFeatureLayer
            {
                Symbology = scheme
            };

            var testConverter = new TestFeatureBasedMapDataConverter
            {
                CreatedDefaultCategory = defaultCategory
            };

            // Precondition
            Assert.AreEqual(2, mapLayer.Symbology.Categories.Count);

            // When
            mapData.Features = Enumerable.Empty <MapFeature>();
            testConverter.ConvertLayerFeatures(mapData, mapLayer);

            // Then
            Assert.AreSame(defaultCategory, mapLayer.Symbology.Categories.Single());
        }
        public void ConvertLayerProperties_MapDataWithMapThemeAndVaryingValueCriteria_SetsCorrectFilterExpression(ValueCriterionOperator criterionOperator,
                                                                                                                  string expressionFormat)
        {
            // Setup
            const string metadataAttributeName = "Meta";
            const string value = "test value";

            var valueCriterion = new ValueCriterion(criterionOperator,
                                                    value);
            var theme = new MapTheme <TestCategoryTheme>(metadataAttributeName, new[]
            {
                new TestCategoryTheme(valueCriterion)
            });

            var mapData = new TestFeatureBasedMapData("test data", theme)
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                metadataAttributeName, new object()
                            }
                        }
                    }
                }
            };

            var featureScheme   = new PointScheme();
            var defaultCategory = new PointCategory();
            var category        = new PointCategory();
            var testConverter   = new TestFeatureBasedMapDataConverter
            {
                CreatedFeatureScheme         = featureScheme,
                CreatedDefaultCategory       = defaultCategory,
                CreatedCategoryThemeCategory = category
            };

            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.IsNull(defaultCategory.FilterExpression);
            string expectedFilterExpression = string.Format(expressionFormat, value);

            Assert.AreEqual(expectedFilterExpression, category.FilterExpression);
        }
        public void ConvertLayerProperties_DataNull_ThrowsArgumentNullException()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapLayer      = new TestFeatureLayer();

            // Call
            TestDelegate test = () => testConverter.ConvertLayerProperties(null, mapLayer);

            // Assert
            const string expectedMessage = "Null data cannot be converted into feature layer data.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentNullException>(test, expectedMessage);
        }
        public void ConvertLayerProperties_MapDataWithMetaAndSelectedMetaDataAttributeInDataColumns_CustomLabelLayerSetToLayer()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapData       = new TestFeatureBasedMapData("test data")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                "Id", 1.1
                            },
                            {
                                "Name", "Feature"
                            }
                        }
                    }
                },
                SelectedMetaDataAttribute = "Name"
            };
            var mapLayer = new TestFeatureLayer
            {
                DataSet =
                {
                    DataTable   =
                    {
                        Columns =
                        {
                            "1",
                            "2"
                        }
                    }
                }
            };

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.IsNotNull(mapLayer.LabelLayer);
            ILabelCategory labelCategory = mapLayer.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("[2]", labelCategory.Expression);
        }
        public void ConvertLayerProperties_MapData_NameSetToLayer()
        {
            // Setup
            const string name          = "<Some name>";
            var          testConverter = new TestFeatureBasedMapDataConverter();
            var          mapData       = new TestFeatureBasedMapData(name);
            var          mapLayer      = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.AreEqual(name, mapLayer.Name);
        }
        public void ConvertLayerProperties_MapDataWithMapThemeAndExistingMetaData_SetsExpectedSymbology()
        {
            // Setup
            const string metadataAttributeName = "metaData";
            var          theme = new MapTheme <TestCategoryTheme>(metadataAttributeName, new[]
            {
                new TestCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion())
            });
            var mapData = new TestFeatureBasedMapData("test data", theme)
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                metadataAttributeName, new object()
                            }
                        }
                    }
                }
            };

            var scheme          = new PointScheme();
            var defaultCategory = new PointCategory();
            var categoryTheme   = new PointCategory();
            var testConverter   = new TestFeatureBasedMapDataConverter
            {
                CreatedFeatureScheme         = scheme,
                CreatedDefaultCategory       = defaultCategory,
                CreatedCategoryThemeCategory = categoryTheme
            };

            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            IPointScheme symbology = mapLayer.Symbology;

            Assert.AreSame(scheme, symbology);
            CollectionAssert.AreEqual(new[]
            {
                defaultCategory,
                categoryTheme
            }, symbology.Categories);
        }
        public void ConvertLayerProperties_MapData_IsVisibleSetToLayer(bool isVisible)
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapData       = new TestFeatureBasedMapData("test data")
            {
                IsVisible = isVisible
            };
            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.AreEqual(isVisible, mapLayer.IsVisible);
        }
        public void ConvertLayerProperties_MapData_ShowLabelsSetToLayer(bool showLabels)
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapData       = new TestFeatureBasedMapData("test data")
            {
                ShowLabels = showLabels
            };
            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.AreEqual(showLabels, mapLayer.ShowLabels);
        }
        public void ConvertLayerProperties_MapDataWithMapTheme_UsesCorrectInputsForConversion()
        {
            // Setup
            const string metadataAttributeName = "metaData";
            var          theme = new MapTheme <TestCategoryTheme>(metadataAttributeName, new[]
            {
                new TestCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion()),
                new TestCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion())
            });
            var mapData = new TestFeatureBasedMapData("test data", theme)
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                metadataAttributeName, new object()
                            }
                        }
                    }
                }
            };

            var testConverter = new TestFeatureBasedMapDataConverter
            {
                CreatedFeatureScheme         = new PointScheme(),
                CreatedDefaultCategory       = new PointCategory(),
                CreatedCategoryThemeCategory = new PointCategory()
            };

            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                mapData
            }, testConverter.DefaultCategoryInputs);
            CollectionAssert.AreEqual(theme.CategoryThemes, testConverter.CategoryThemeInputs);
        }
        public void ConvertLayerFeatures_MapDataWithMetaData_MetaDataSetToLayer()
        {
            // Setup
            var testConverter = new TestFeatureBasedMapDataConverter();
            var mapLayer      = new TestFeatureLayer();
            var mapData       = new TestFeatureBasedMapData("test")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                "Id", 1.1
                            },
                            {
                                "Name", "Feature 1"
                            },
                            {
                                "Extra 1", "Feature 1 extra"
                            }
                        }
                    },
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                "Id", 2.2
                            },
                            {
                                "Name", "Feature 2"
                            },
                            {
                                "Extra 2", "Feature 2 extra"
                            }
                        }
                    }
                }
            };

            // Call
            testConverter.ConvertLayerFeatures(mapData, mapLayer);

            // Assert
            DataColumnCollection dataColumnCollection = mapLayer.DataSet.DataTable.Columns;

            Assert.AreEqual(4, dataColumnCollection.Count);
            Assert.AreEqual("1", dataColumnCollection[0].ToString());
            Assert.AreEqual("2", dataColumnCollection[1].ToString());
            Assert.AreEqual("3", dataColumnCollection[2].ToString());
            Assert.AreEqual("4", dataColumnCollection[3].ToString());

            DataRowCollection dataRowCollection = mapLayer.DataSet.DataTable.Rows;

            Assert.AreEqual(2, dataRowCollection.Count);
            Assert.AreEqual(1.1.ToString(CultureInfo.CurrentCulture), dataRowCollection[0][0]);
            Assert.AreEqual("Feature 1", dataRowCollection[0][1]);
            Assert.AreEqual("Feature 1 extra", dataRowCollection[0][2]);
            Assert.IsEmpty(dataRowCollection[0][3].ToString());
            Assert.AreEqual(2.2.ToString(CultureInfo.CurrentCulture), dataRowCollection[1][0]);
            Assert.AreEqual("Feature 2", dataRowCollection[1][1]);
            Assert.IsEmpty(dataRowCollection[1][2].ToString());
            Assert.AreEqual("Feature 2 extra", dataRowCollection[1][3]);
        }