// 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.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Threading;
using System.Windows.Forms;
using BruTile;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Gui.TestUtil.Settings;
using Core.Common.TestUtil;
using Core.Components.DotSpatial.Layer.BruTile;
using Core.Components.DotSpatial.Layer.BruTile.Configurations;
using Core.Components.DotSpatial.MapFunctions;
using Core.Components.DotSpatial.TestUtil;
using Core.Components.Gis;
using Core.Components.Gis.Data;
using Core.Components.Gis.Features;
using Core.Components.Gis.Forms;
using Core.Components.Gis.Geometries;
using DotSpatial.Controls;
using DotSpatial.Projections;
using DotSpatial.Symbology;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Extent = DotSpatial.Data.Extent;
namespace Core.Components.DotSpatial.Forms.Test
{
[TestFixture]
public class MapControlTest
{
private const double padding = 0.05;
private const string tileCachesFolder = "tilecaches";
private static readonly string rootPath = TestHelper.GetScratchPadPath();
[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]
[TestCase(true)]
[TestCase(false)]
public void GivenMapControlWithEmptyBackgroundMapDataContainer_WhenMapDataSetAndNotified_ThenMapControlUpdated(bool isVisible)
{
// Given
WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData();
var mapDataContainer = new BackgroundMapDataContainer
{
IsVisible = isVisible,
Transparency = (RoundedDouble) 0.25
};
using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
using (var map = new MapControl
{
BackgroundMapData = mapDataContainer
})
{
// When
mapDataContainer.MapData = backgroundMapData;
mapDataContainer.NotifyObservers();
// Then
var mapView = map.Controls.OfType