// Copyright (C) Stichting Deltares 2017. 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.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Threading;
using System.Windows.Forms;
using BruTile;
using BruTile.Predefined;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.TestUtil;
using Core.Common.Utils.Reflection;
using Core.Common.Utils.TestUtil.Settings;
using Core.Components.BruTile.Configurations;
using Core.Components.BruTile.TestUtil;
using Core.Components.DotSpatial.Layer.BruTile;
using Core.Components.DotSpatial.MapFunctions;
using Core.Components.Gis.Data;
using Core.Components.Gis.Exceptions;
using Core.Components.Gis.Features;
using Core.Components.Gis.Forms;
using Core.Components.Gis.Geometries;
using Core.Components.Gis.TestUtil;
using DotSpatial.Controls;
using DotSpatial.Projections;
using DotSpatial.Symbology;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Extent = DotSpatial.Data.Extent;
using IMapView = DotSpatial.Controls.IMapView;
namespace Core.Components.DotSpatial.Forms.Test
{
[TestFixture]
public class MapControlTest
{
private const double padding = 0.05;
private DirectoryDisposeHelper directoryDisposeHelper;
private TestSettingsHelper testSettingsHelper;
private string settingsDirectory;
[Test]
public void DefaultConstructor_DefaultValues()
{
// Call
using (var map = new MapControl())
{
// Assert
Assert.IsInstanceOf(map);
Assert.IsInstanceOf(map);
Assert.IsNull(map.Data);
Assert.IsNull(map.BackgroundMapData);
Assert.IsTrue(map.IsPanningEnabled);
Assert.IsFalse(map.IsRectangleZoomingEnabled);
Assert.IsTrue(map.IsMouseCoordinatesVisible);
}
}
[Test]
[Apartment(ApartmentState.STA)]
public void DefaultConstructor_MapCorrectlyInitialized()
{
using (var form = new Form())
{
// Call
var mapControl = new MapControl();
form.Controls.Add(mapControl);
form.Show();
var map = (Map) form.Controls.Find("Map", true)[0];
// Assert
Assert.AreEqual(MapDataConstants.FeatureBasedMapDataCoordinateSystem, map.Projection);
Assert.AreEqual(ActionMode.Never, map.ProjectionModeDefine);
Assert.AreEqual(9, map.MapFunctions.Count);
Assert.AreEqual(1, map.MapFunctions.OfType().Count());
Assert.AreEqual(1, map.MapFunctions.OfType().Count());
Assert.AreEqual(KnownCoordinateSystems.Projected.NationalGrids.Rijksdriehoekstelsel, map.Projection);
Assert.AreEqual(ActionMode.Never, map.ProjectionModeDefine);
Assert.IsTrue(map.ZoomOutFartherThanMaxExtent);
}
}
[Test]
public void RemoveAllData_Always_SetDataAndBackgroundMapDataNull()
{
// Setup
WmtsMapData backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
using (new UseCustomSettingsHelper(testSettingsHelper))
using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
using (var map = new MapControl())
{
map.BackgroundMapData = backgroundMapData;
var mapDataCollection = new MapDataCollection("A");
mapDataCollection.Add(new MapPointData("points")
{
Features = new[]
{
new MapFeature(new[]
{
new MapGeometry(new[]
{
new[]
{
new Point2D(1.1, 2.2)
}
})
})
}
});
map.Data = mapDataCollection;
// Precondition
Assert.IsNotNull(map.Data);
Assert.IsNotNull(map.BackgroundMapData);
// Call
map.RemoveAllData();
// Assert
Assert.IsNull(map.Data);
Assert.IsNull(map.BackgroundMapData);
}
}
[Test]
public void GivenMapControlWithoutData_WhenDataSetToMapDataCollection_ThenMapControlUpdated()
{
// Given
using (var map = new MapControl())
{
var mapPointData = new MapPointData("Points")
{
Features = new[]
{
new MapFeature(new[]
{
new MapGeometry(new[]
{
new[]
{
new Point2D(1.1, 2.2)
}
})
})
}
};
var mapLineData = new MapLineData("Lines");
var mapPolygonData = new MapPolygonData("Polygons");
var mapDataCollection = new MapDataCollection("Root collection");
var nestedMapDataCollection1 = new MapDataCollection("Nested collection 1");
var nestedMapDataCollection2 = new MapDataCollection("Nested collection 2");
mapDataCollection.Add(mapPointData);
mapDataCollection.Add(nestedMapDataCollection1);
nestedMapDataCollection1.Add(mapLineData);
nestedMapDataCollection1.Add(nestedMapDataCollection2);
nestedMapDataCollection2.Add(mapPolygonData);
// When
map.Data = mapDataCollection;
// Then
Map mapView = map.Controls.OfType