Index: Core/Components/src/Core.Components.BruTile.Forms/BrutileConfigurationFactory.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.BruTile.Forms/BrutileConfigurationFactory.cs (revision 0)
+++ Core/Components/src/Core.Components.BruTile.Forms/BrutileConfigurationFactory.cs (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -0,0 +1,140 @@
+// 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.ComponentModel;
+using Core.Common.Utils.Reflection;
+using Core.Components.BruTile.Configurations;
+using Core.Components.BruTile.Forms.Properties;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Exceptions;
+
+namespace Core.Components.BruTile.Forms
+{
+ ///
+ /// Class responsible for creating instances for a given
+ /// map data.
+ ///
+ public static class BrutileConfigurationFactory
+ {
+ ///
+ /// Creates a new initialized .
+ ///
+ /// The to create an
+ /// for.
+ /// A new initialized configuration.
+ /// Thrown when
+ /// is null.
+ /// Thrown when a configuration can't
+ /// be created for the type of .
+ /// Thrown when the configuration
+ /// can't connect with the tile service or creating the file cache failed.
+ public static IConfiguration CreateInitializedConfiguration(ImageBasedMapData mapData)
+ {
+ if (mapData == null)
+ {
+ throw new ArgumentNullException(nameof(mapData));
+ }
+
+ var wmtsBackgroundMapData = mapData as WmtsMapData;
+ var wellKnownBackgroundMapData = mapData as WellKnownTileSourceMapData;
+ if (wmtsBackgroundMapData != null)
+ {
+ return CreateInitializedConfiguration(wmtsBackgroundMapData);
+ }
+
+ if (wellKnownBackgroundMapData != null)
+ {
+ return CreateInitializedConfiguration(wellKnownBackgroundMapData);
+ }
+ throw new NotSupportedException($"Cannot create a configuration for type {mapData.GetType()}.");
+ }
+
+ ///
+ /// Creates a new initialized .
+ ///
+ /// The
+ /// to create the configuration for.
+ /// A new initialized .
+ /// Thrown when the configuration
+ /// can't connect with the tile service or creating the file cache failed.
+ private static WellKnownTileSourceLayerConfiguration CreateInitializedConfiguration(WellKnownTileSourceMapData wellKnownBackgroundMapData)
+ {
+ try
+ {
+ return WellKnownTileSourceLayerConfiguration.CreateInitializedConfiguration(wellKnownBackgroundMapData.TileSource);
+ }
+ catch (NotSupportedException e)
+ {
+ string tileDisplayName;
+ try
+ {
+ tileDisplayName = TypeUtils.GetDisplayName(wellKnownBackgroundMapData.TileSource);
+ }
+ catch (InvalidEnumArgumentException)
+ {
+ tileDisplayName = wellKnownBackgroundMapData.TileSource.ToString();
+ }
+
+ throw new ConfigurationInitializationException(
+ string.Format(Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Connect_to_TileSourceName_0_failed,
+ tileDisplayName),
+ e);
+ }
+ catch (CannotCreateTileCacheException e)
+ {
+ throw new ConfigurationInitializationException(
+ Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Persistent_cache_creation_failed,
+ e);
+ }
+ }
+
+ ///
+ /// Creates a new initialized .
+ ///
+ /// The
+ /// to create the configuration for.
+ /// A new initialized .
+ /// Thrown when the configuration
+ /// can't connect with the tile service or creating the file cache failed.
+ private static PersistentCacheConfiguration CreateInitializedConfiguration(WmtsMapData wmtsBackgroundMapData)
+ {
+ try
+ {
+ return WmtsLayerConfiguration.CreateInitializedConfiguration(wmtsBackgroundMapData.SourceCapabilitiesUrl,
+ wmtsBackgroundMapData.SelectedCapabilityIdentifier,
+ wmtsBackgroundMapData.PreferredFormat);
+ }
+ catch (Exception e) when (e is CannotFindTileSourceException || e is CannotReceiveTilesException)
+ {
+ throw new ConfigurationInitializationException(
+ Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Wmts_connection_failed,
+ e);
+ }
+ catch (CannotCreateTileCacheException e)
+ {
+ throw new ConfigurationInitializationException(
+ Resources.TryCreateInitializedConfiguration_InitializeBackgroundLayer_Persistent_cache_creation_failed,
+ e);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.BruTile.Forms/Core.Components.BruTile.Forms.csproj
===================================================================
diff -u -r396d39591f11aad05a6cd0e66ead43fefd9713c3 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.BruTile.Forms/Core.Components.BruTile.Forms.csproj (.../Core.Components.BruTile.Forms.csproj) (revision 396d39591f11aad05a6cd0e66ead43fefd9713c3)
+++ Core/Components/src/Core.Components.BruTile.Forms/Core.Components.BruTile.Forms.csproj (.../Core.Components.BruTile.Forms.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -43,8 +43,14 @@
Properties\GlobalAssembly.cs
+
+
+ True
+ True
+ Resources.resx
+
@@ -53,6 +59,16 @@
+
+ {3BBFD65B-B277-4E50-AE6D-BD24C3434609}
+ Core.Common.Base
+ False
+
+
+ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
+ Core.Common.Utils
+ False
+ {E02482C7-F12B-42F0-BB2B-C7EC17503A72}Core.Components.BruTile
@@ -68,6 +84,12 @@
Core.Components.Gis
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Verbinden met '{0}' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.
+
+
+ Configuratie van kaartgegevens hulpbestanden is mislukt.
+
+
+ Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.
+
+
\ No newline at end of file
Index: Core/Components/src/Core.Components.BruTile.Forms/packages.config
===================================================================
diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.BruTile.Forms/packages.config (.../packages.config) (revision 99f9004206bfb9de084275d749b7aeccafd6da18)
+++ Core/Components/src/Core.Components.BruTile.Forms/packages.config (.../packages.config) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -20,7 +20,6 @@
Stichting Deltares and remain full property of Stichting Deltares at all times.
All rights reserved.
-->
-
\ No newline at end of file
Index: Core/Components/src/Core.Components.BruTile/Configurations/WmtsLayerConfiguration.cs
===================================================================
diff -u -rc779a09fcdb11c7263b460e664e93cc36d0daf6f -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.BruTile/Configurations/WmtsLayerConfiguration.cs (.../WmtsLayerConfiguration.cs) (revision c779a09fcdb11c7263b460e664e93cc36d0daf6f)
+++ Core/Components/src/Core.Components.BruTile/Configurations/WmtsLayerConfiguration.cs (.../WmtsLayerConfiguration.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -98,6 +98,8 @@
/// Thrown when it has become impossible
/// to create an based on the given information (for example:
/// unable to connect to server).
+ /// Thrown when the configured
+ /// doesn't contain a .
public static WmtsLayerConfiguration CreateInitializedConfiguration(string wmtsCapabilitiesUrl, string capabilityIdentifier, string preferredFormat)
{
ValidateConfigurationParameters(wmtsCapabilitiesUrl, capabilityIdentifier, preferredFormat);
Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj
===================================================================
diff -u -r44fd917df62795d3f13fff346544cd5232c0986b -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 44fd917df62795d3f13fff346544cd5232c0986b)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -100,6 +100,11 @@
Core.Common.UtilsFalse
+
+ {1BA9EBD0-AA64-4BE3-9791-B2EE344EC938}
+ Core.Components.BruTile.Forms
+ False
+ {E02482C7-F12B-42F0-BB2B-C7EC17503A72}Core.Components.BruTile
Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs
===================================================================
diff -u -r44fd917df62795d3f13fff346544cd5232c0986b -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 44fd917df62795d3f13fff346544cd5232c0986b)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -26,6 +26,7 @@
using Core.Common.Base;
using Core.Common.Utils.Reflection;
using Core.Components.BruTile.Configurations;
+using Core.Components.BruTile.Forms;
using Core.Components.DotSpatial.Forms.Properties;
using Core.Components.DotSpatial.Layer;
using Core.Components.DotSpatial.Layer.BruTile;
@@ -202,7 +203,25 @@
///
private bool InitializeBackgroundLayer()
{
- IConfiguration configuration = CreateInitializedConfiguration(backgroundMapData);
+ IConfiguration configuration;
+
+ try
+ {
+ configuration = BrutileConfigurationFactory.CreateInitializedConfiguration(backgroundMapData);
+ }
+ catch (ConfigurationInitializationException e)
+ {
+ if (!backgroundLayerStatus.PreviousBackgroundLayerCreationFailed)
+ {
+ string fullMessage = string.Format(Resources.MapControl_HandleBruTileInitializationException_Message_0_therefore_cannot_show_background_layer,
+ e.Message);
+ log.Error(fullMessage, e);
+ }
+
+ backgroundLayerStatus.LayerInitializationFailed();
+ return false;
+ }
+
if (configuration == null)
{
return false;
@@ -218,63 +237,6 @@
return true;
}
- private IConfiguration CreateInitializedConfiguration(ImageBasedMapData mapdata)
- {
- var wmtsBackgroundMapData = mapdata as WmtsMapData;
- var wellKnownMapDataBackgroundMapData = mapdata as WellKnownTileSourceMapData;
- if (wmtsBackgroundMapData != null)
- {
- return TryCreateInitializedConfiguration(wmtsBackgroundMapData);
- }
-
- if (wellKnownMapDataBackgroundMapData != null)
- {
- return TryCreateInitializedConfiguration(wellKnownMapDataBackgroundMapData);
- }
- return null;
- }
-
- private IConfiguration TryCreateInitializedConfiguration(WellKnownTileSourceMapData wellKnownMapDataBackgroundMapData)
- {
- try
- {
- return WellKnownTileSourceLayerConfiguration.CreateInitializedConfiguration(wellKnownMapDataBackgroundMapData.TileSource);
- }
- catch (NotSupportedException e)
- {
- string tileDisplayName = TypeUtils.GetDisplayName(wellKnownMapDataBackgroundMapData.TileSource);
- HandleBruTileInitializationException(e, string.Format(Resources.MapControl_InitializeBackgroundLayer_Connect_to_TileSourceName_0_failed, tileDisplayName));
-
- return null;
- }
- catch (CannotCreateTileCacheException e)
- {
- HandleBruTileInitializationException(e, Resources.MapControl_InitializeBackgroundLayer_Persistent_cache_creation_failed);
-
- return null;
- }
- }
-
- private PersistentCacheConfiguration TryCreateInitializedConfiguration(WmtsMapData wmtsMapDataBackgroundMapData)
- {
- try
- {
- return WmtsLayerConfiguration.CreateInitializedConfiguration(wmtsMapDataBackgroundMapData.SourceCapabilitiesUrl,
- wmtsMapDataBackgroundMapData.SelectedCapabilityIdentifier,
- wmtsMapDataBackgroundMapData.PreferredFormat);
- }
- catch (Exception e) when (e is CannotFindTileSourceException || e is CannotReceiveTilesException)
- {
- HandleBruTileInitializationException(e, Resources.MapControl_InitializeBackgroundLayer_Wmts_connection_failed);
- return null;
- }
- catch (CannotCreateTileCacheException e)
- {
- HandleBruTileInitializationException(e, Resources.MapControl_InitializeBackgroundLayer_Persistent_cache_creation_failed);
- return null;
- }
- }
-
private void InsertBackgroundLayer()
{
if (backgroundMapData.IsConfigured)
@@ -329,18 +291,6 @@
return !backgroundLayerStatus.HasSameConfiguration(wmtsMapDataBackgroundMapData);
}
- private void HandleBruTileInitializationException(Exception e, string message)
- {
- if (!backgroundLayerStatus.PreviousBackgroundLayerCreationFailed)
- {
- string fullMessage = string.Format(Resources.MapControl_HandleBruTileInitializationException_Message_0_therefore_cannot_show_background_layer,
- message);
- log.Error(fullMessage, e);
- }
-
- backgroundLayerStatus.LayerInitializationFailed();
- }
-
#endregion
#region Event handlers
Index: Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs
===================================================================
diff -u -r44fd917df62795d3f13fff346544cd5232c0986b -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 44fd917df62795d3f13fff346544cd5232c0986b)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -90,32 +90,5 @@
"ackground_layer", resourceCulture);
}
}
-
- ///
- /// Looks up a localized string similar to Verbinden met '{0}' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden..
- ///
- internal static string MapControl_InitializeBackgroundLayer_Connect_to_TileSourceName_0_failed {
- get {
- return ResourceManager.GetString("MapControl_InitializeBackgroundLayer_Connect_to_TileSourceName_0_failed", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Configuratie van kaartgegevens hulpbestanden is mislukt..
- ///
- internal static string MapControl_InitializeBackgroundLayer_Persistent_cache_creation_failed {
- get {
- return ResourceManager.GetString("MapControl_InitializeBackgroundLayer_Persistent_cache_creation_failed", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden..
- ///
- internal static string MapControl_InitializeBackgroundLayer_Wmts_connection_failed {
- get {
- return ResourceManager.GetString("MapControl_InitializeBackgroundLayer_Wmts_connection_failed", resourceCulture);
- }
- }
}
}
Index: Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx
===================================================================
diff -u -r44fd917df62795d3f13fff346544cd5232c0986b -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx (.../Resources.resx) (revision 44fd917df62795d3f13fff346544cd5232c0986b)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx (.../Resources.resx) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -117,16 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.
-
{0} De achtergrondkaart kan nu niet getoond worden.
-
- Configuratie van kaartgegevens hulpbestanden is mislukt.
-
-
- Verbinden met '{0}' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.
-
\ No newline at end of file
Index: Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj
===================================================================
diff -u -rd00d30719d5bffa635f40b975e490af4e4c298e9 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision d00d30719d5bffa635f40b975e490af4e4c298e9)
+++ Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -54,6 +54,7 @@
+ True
Index: Core/Components/src/Core.Components.Gis/Exceptions/ConfigurationInitializationException.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.Gis/Exceptions/ConfigurationInitializationException.cs (revision 0)
+++ Core/Components/src/Core.Components.Gis/Exceptions/ConfigurationInitializationException.cs (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -0,0 +1,57 @@
+// 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.Runtime.Serialization;
+
+namespace Core.Components.Gis.Exceptions
+{
+ ///
+ /// The exception that is thrown when the initialization of a configuration failed.
+ ///
+ [Serializable]
+ public class ConfigurationInitializationException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ConfigurationInitializationException() { }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public ConfigurationInitializationException(string message) : base(message) { }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message and a reference to the inner exception that is
+ /// the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception,
+ /// or a null reference if no inner exception is specified.
+ public ConfigurationInitializationException(string message, Exception inner) : base(message, inner) { }
+
+ protected ConfigurationInitializationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
\ No newline at end of file
Index: Core/Components/test/Core.Components.BruTile.Forms.Test/BrutileConfigurationFactoryTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.BruTile.Forms.Test/BrutileConfigurationFactoryTest.cs (revision 0)
+++ Core/Components/test/Core.Components.BruTile.Forms.Test/BrutileConfigurationFactoryTest.cs (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -0,0 +1,223 @@
+// 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 BruTile;
+using BruTile.Predefined;
+using Core.Common.Gui.TestUtil.Settings;
+using Core.Common.TestUtil;
+using Core.Components.BruTile.Configurations;
+using Core.Components.BruTile.TestUtil;
+using Core.Components.Gis.Data;
+using Core.Components.Gis.Exceptions;
+using Core.Components.Gis.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Core.Components.BruTile.Forms.Test
+{
+ [TestFixture]
+ public class BrutileConfigurationFactoryTest
+ {
+ [Test]
+ public void CreateInitializedConfiguration_MapDataNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("mapData", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateInitializedConfiguration_MapDataNotWellKnownOrWmts_ThrowNotSupportedException()
+ {
+ // Setup
+ var mapData = new TestImageBasedMapData("test", true);
+
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(mapData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual($"Cannot create a configuration for type {mapData.GetType()}.", exception.Message);
+ }
+
+ [Test]
+ public void CreateInitializedConfiguration_InvalidWellKnownTileSource_ThrowConfigurationInitializationException()
+ {
+ // Setup
+ var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial)
+ {
+ TileSource = (WellKnownTileSource) 99
+ };
+
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(wellKnownMapData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual("Verbinden met '99' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.", exception.Message);
+ }
+
+ [Test]
+ public void CreateInitializedConfiguration_WellKnownTileSourceFactoryThrowsNotSupportedException_ThrowConfigurationInitializationException()
+ {
+ // Setup
+ var factoryThrowingNotSupportedException = MockRepository.GenerateStub();
+ factoryThrowingNotSupportedException.Stub(f => f.GetKnownTileSource(Arg.Is.NotNull))
+ .Throw(new NotSupportedException());
+
+ using (new UseCustomTileSourceFactoryConfig(factoryThrowingNotSupportedException))
+ {
+ var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial);
+
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(wellKnownMapData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual("Verbinden met 'Bing Maps - Satelliet' is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.", exception.Message);
+ }
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetBackgroundData))]
+ public void CreateInitializedConfiguration_CannotCreateFileCache_ThrowConfigurationInitializationException(ImageBasedMapData mapData)
+ {
+ // Setup
+ using (new UseCustomSettingsHelper(new TestSettingsHelper
+ {
+ ApplicationLocalUserSettingsDirectory = Path.Combine(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest))
+ }))
+ using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest)))
+ using (new UseCustomTileSourceFactoryConfig(mapData))
+ {
+ disposeHelper.LockDirectory(FileSystemRights.Write);
+
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(mapData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual("Configuratie van kaartgegevens hulpbestanden is mislukt.", exception.Message);
+ }
+ }
+
+ [Test]
+ public void CreateInitializedConfiguration_ValidWellKnownMapData_ReturnWellKnownTileSourceLayerConfiguration()
+ {
+ // Setup
+ var wellKnownMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial);
+
+ using (new UseCustomTileSourceFactoryConfig(wellKnownMapData))
+ {
+ // Call
+ IConfiguration configuration = BrutileConfigurationFactory.CreateInitializedConfiguration(wellKnownMapData);
+
+ // Assert
+ Assert.IsInstanceOf(configuration);
+ Assert.IsTrue(configuration.Initialized);
+ }
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetProblematicTileSourceFactoryTestCaseData), new object[]
+ {
+ "CreateInitializedConfiguration"
+ })]
+ public void CreateInitializedConfiguration_ProblematicTileSourceFactory_ThrowConfigurationInitializationException(ITileSourceFactory factory)
+ {
+ // Setup
+ WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData();
+
+ using (new UseCustomTileSourceFactoryConfig(factory))
+ {
+ // Call
+ TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(backgroundMapData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual("Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden.", exception.Message);
+ }
+ }
+
+ [Test]
+ public void CreateInitializedConfiguration_ValidWmtsMapData_ReturnWmtsTileSourceLayerConfiguration()
+ {
+ // Setup
+ WmtsMapData mapData = WmtsMapData.CreateDefaultPdokMapData();
+
+ using (new UseCustomTileSourceFactoryConfig(mapData))
+ {
+ // Call
+ IConfiguration configuration = BrutileConfigurationFactory.CreateInitializedConfiguration(mapData);
+
+ // Assert
+ Assert.IsInstanceOf(configuration);
+ Assert.IsTrue(configuration.Initialized);
+ }
+ }
+
+ ///
+ /// Generates containing problematic .
+ ///
+ /// The test-name prefix.
+ /// The data for the test cases.
+ /// Some test runners, like TeamCity, cannot properly deal with reuse of
+ /// sources where the source defines a name of the test,
+ /// as these testrunners to not display tests in hierarchical form.
+ private static IEnumerable GetProblematicTileSourceFactoryTestCaseData(string prefix)
+ {
+ var factoryWithoutRequiredTileSource = MockRepository.GenerateStub();
+ factoryWithoutRequiredTileSource.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull))
+ .Return(Enumerable.Empty());
+
+ var factoryThrowingCannotFindTileSourceException = MockRepository.GenerateStub();
+ factoryThrowingCannotFindTileSourceException.Stub(f => f.GetWmtsTileSources(Arg.Is.NotNull))
+ .Throw(new CannotFindTileSourceException());
+
+ yield return new TestCaseData(factoryWithoutRequiredTileSource)
+ .SetName($"{prefix}: Required tile source not returned by factory.");
+
+ yield return new TestCaseData(factoryThrowingCannotFindTileSourceException)
+ .SetName($"{prefix}: Tile source factory throws CannotFindTileSourceException.");
+ }
+
+ private static IEnumerable GetBackgroundData()
+ {
+ yield return new TestCaseData(new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial))
+ .SetName("WellKnownMapData");
+
+ yield return new TestCaseData(WmtsMapData.CreateDefaultPdokMapData())
+ .SetName("WmtsMapData");
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/test/Core.Components.BruTile.Forms.Test/Core.Components.BruTile.Forms.Test.csproj
===================================================================
diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/test/Core.Components.BruTile.Forms.Test/Core.Components.BruTile.Forms.Test.csproj (.../Core.Components.BruTile.Forms.Test.csproj) (revision 99f9004206bfb9de084275d749b7aeccafd6da18)
+++ Core/Components/test/Core.Components.BruTile.Forms.Test/Core.Components.BruTile.Forms.Test.csproj (.../Core.Components.BruTile.Forms.Test.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -39,31 +39,53 @@
MinimumRecommendedRules.ruleset
+
+ ..\..\..\..\packages\BruTile.0.19.0\lib\net40\BruTile.dll
+ True
+ ..\..\..\..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dllTrue
+
+ ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+ True
+
Properties\GlobalAssembly.cs
+
Copying.Lesser.licenseheader
+ {3bbfd65b-b277-4e50-ae6d-bd24c3434609}Core.Common.Base
+
+ {30e4c2ae-719e-4d70-9fa9-668a9767fbfa}
+ Core.Common.Gui
+
+
+ {26214BD0-DAFB-4CFC-8EB2-80C5D53C859E}
+ Core.Common.Gui.TestUtil
+
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+ {1BA9EBD0-AA64-4BE3-9791-B2EE344EC938}Core.Components.BruTile.Forms
@@ -84,6 +106,10 @@
{1081336C-D919-4249-AB33-9AF15F4D19EC}Core.Components.BruTile.TestUtil
+
+ {F0FB401A-3494-4237-9E6D-02CDF77912A8}
+ Core.Components.Gis.TestUtils
+
-
+
+
\ No newline at end of file
Index: Core/Components/test/Core.Components.BruTile.TestUtil/TestTileSourceFactory.cs
===================================================================
diff -u -r0f778d2d9cc904175274baf4d6a21996ccef8d54 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/test/Core.Components.BruTile.TestUtil/TestTileSourceFactory.cs (.../TestTileSourceFactory.cs) (revision 0f778d2d9cc904175274baf4d6a21996ccef8d54)
+++ Core/Components/test/Core.Components.BruTile.TestUtil/TestTileSourceFactory.cs (.../TestTileSourceFactory.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -33,32 +33,29 @@
///
public class TestTileSourceFactory : ITileSourceFactory
{
- private readonly TestWmtsTileSource wmtsTileSource;
- private readonly TestWellKnownTileSource wellKnownTileSource;
+ private TestWmtsTileSource wmtsTileSource;
+ private TestWellKnownTileSource wellKnownTileSource;
///
/// Initializes a new instance of for a given
- /// .
+ /// .
///
/// The map data to work for.
/// If isn't initialized at construction
/// time, then returns no tile sources.
- public TestTileSourceFactory(WmtsMapData backgroundMapData)
+ public TestTileSourceFactory(ImageBasedMapData backgroundMapData)
{
- if (backgroundMapData.IsConfigured)
+ var wellKnownMapData = backgroundMapData as WellKnownTileSourceMapData;
+ if (wellKnownMapData != null)
{
- wmtsTileSource = new TestWmtsTileSource(backgroundMapData);
+ SetWellKnownTileSource(wellKnownMapData);
}
- }
- ///
- /// Initializes a new instance of for a given
- /// .
- ///
- /// The map data to work for.
- public TestTileSourceFactory(WellKnownTileSourceMapData backgroundMapData)
- {
- wellKnownTileSource = new TestWellKnownTileSource(backgroundMapData);
+ var wmtsMapData = backgroundMapData as WmtsMapData;
+ if (wmtsMapData != null && wmtsMapData.IsConfigured)
+ {
+ SetWmtsTileSource(wmtsMapData);
+ }
}
public IEnumerable GetWmtsTileSources(string capabilitiesUrl)
@@ -77,5 +74,18 @@
}
return wellKnownTileSource;
}
+
+ private void SetWmtsTileSource(WmtsMapData backgroundMapData)
+ {
+ if (backgroundMapData.IsConfigured)
+ {
+ wmtsTileSource = new TestWmtsTileSource(backgroundMapData);
+ }
+ }
+
+ private void SetWellKnownTileSource(WellKnownTileSourceMapData wellKnownMapData)
+ {
+ wellKnownTileSource = new TestWellKnownTileSource(wellKnownMapData);
+ }
}
}
\ No newline at end of file
Index: Core/Components/test/Core.Components.BruTile.TestUtil/UseCustomTileSourceFactoryConfig.cs
===================================================================
diff -u -rfcf14f1da32f6de8d99c7f446ec27fbe30a6abe8 -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/test/Core.Components.BruTile.TestUtil/UseCustomTileSourceFactoryConfig.cs (.../UseCustomTileSourceFactoryConfig.cs) (revision fcf14f1da32f6de8d99c7f446ec27fbe30a6abe8)
+++ Core/Components/test/Core.Components.BruTile.TestUtil/UseCustomTileSourceFactoryConfig.cs (.../UseCustomTileSourceFactoryConfig.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -45,20 +45,12 @@
///
/// Creates a new instance of that
- /// initializes test stubs to work for a instance.
+ /// initializes test stubs to work for a instance.
///
/// The map data to work with.
- public UseCustomTileSourceFactoryConfig(WmtsMapData backgroundMapData)
+ public UseCustomTileSourceFactoryConfig(ImageBasedMapData backgroundMapData)
: this(new TestTileSourceFactory(backgroundMapData)) {}
- ///
- /// Creates a new instance of that
- /// initializes test stubs to work for a instance.
- ///
- /// The map data to work with.
- public UseCustomTileSourceFactoryConfig(WellKnownTileSourceMapData backgroundMapData)
- : this(new TestTileSourceFactory(backgroundMapData)) {}
-
public void Dispose()
{
TileSourceFactory.Instance = originalFactory;
Index: Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj
===================================================================
diff -u -r797872a6e0525f12c0f84b03e996a9d42630ad0b -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076
--- Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 797872a6e0525f12c0f84b03e996a9d42630ad0b)
+++ Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -60,6 +60,7 @@
+
Index: Core/Components/test/Core.Components.Gis.Test/Exceptions/ConfigurationInitializationExceptionTest.cs
===================================================================
diff -u
--- Core/Components/test/Core.Components.Gis.Test/Exceptions/ConfigurationInitializationExceptionTest.cs (revision 0)
+++ Core/Components/test/Core.Components.Gis.Test/Exceptions/ConfigurationInitializationExceptionTest.cs (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076)
@@ -0,0 +1,32 @@
+// 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 Core.Common.TestUtil;
+using Core.Components.Gis.Exceptions;
+using NUnit.Framework;
+
+namespace Core.Components.Gis.Test.Exceptions
+{
+ [TestFixture]
+ public class ConfigurationInitializationExceptionTest :
+ CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file