Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rd1b6ecd5c987d476725fe7a5f242a358e3748edb --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs (.../DotSpatialMapTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/DotSpatialMapTest.cs (.../DotSpatialMapTest.cs) (revision d1b6ecd5c987d476725fe7a5f242a358e3748edb) @@ -19,11 +19,17 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Linq; +using System.Net.NetworkInformation; using System.Threading; using System.Windows.Forms; +using Core.Components.Gis.TestUtil; +using DotSpatial.Controls; using DotSpatial.Data; using NUnit.Extensions.Forms; using NUnit.Framework; +using NUnit.Framework.Interfaces; namespace Core.Components.DotSpatial.Forms.Test { @@ -40,9 +46,9 @@ [TestCase(1e+10)] public void OnViewExtentsChanged_EdgeCases_DoesNotThrowException(double minExt) { + // Setup using (var form = new Form()) { - // Setup var mapControl = new MapControl(); form.Controls.Add(mapControl); form.Show(); @@ -56,5 +62,53 @@ Assert.DoesNotThrow(test); } } + + [Test] + [Apartment(ApartmentState.STA)] + [IgnoreOnNoInternet] + public void GivenMapControl_WhenPdokDataSetAsBackground_ThenMapControlShowsBackgroundLayer() + { + // Given + using (var form = new Form()) + { + var mapControl = new MapControl(); + Map mapView = mapControl.Controls.OfType().First(); + form.Controls.Add(mapControl); + form.Show(); + + // When + mapControl.BackgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData(); + + // Then + Assert.AreEqual(1, mapView.Layers.Count); + } + } + + private class IgnoreOnNoInternetAttribute : Attribute, ITestAction + { + public void BeforeTest(ITest test) + { + bool ignore; + try + { + var ping = new Ping(); + PingReply reply = ping.Send("deltares.nl", 100); + ignore = reply == null || reply.Status != IPStatus.Success; + } + catch (Exception e) when (e is ArgumentException || e is InvalidOperationException) + { + ignore = true; + } + + if (ignore) + { + Assert.Ignore("Test is Ignored, because there currently is no internet connection."); + } + } + + public void AfterTest(ITest test) { } + + public ActionTargets Targets { get; } + } } } \ No newline at end of file