Index: Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs
===================================================================
diff -u -r935e492135a782b9e63c0924df798ebb358ac7cc -ra7c7037989d2ccfa2d482a1f54f7f9f8bac0b9e7
--- Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs (.../BackgroundDataConverter.cs) (revision 935e492135a782b9e63c0924df798ebb358ac7cc)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs (.../BackgroundDataConverter.cs) (revision a7c7037989d2ccfa2d482a1f54f7f9f8bac0b9e7)
@@ -68,32 +68,45 @@
/// Thrown when
/// contains an
/// invalid value for .
+ /// Thrown when
+ /// doesn't is of a type that can be converted.
public static ImageBasedMapData ConvertFrom(BackgroundData backgroundData)
{
if (backgroundData == null)
{
throw new ArgumentNullException(nameof(backgroundData));
}
- ImageBasedMapData mapData = null;
+ ImageBasedMapData mapData = CreateMapData(backgroundData);
+ mapData.Name = backgroundData.Name;
+ mapData.IsVisible = backgroundData.IsVisible;
+ mapData.Transparency = backgroundData.Transparency;
+
+ return mapData;
+ }
+
+ ///
+ /// Creates the map data with data of the .
+ ///
+ /// The background data to get the configuration from
+ /// and create the data for.
+ /// The created .
+ /// Thrown when
+ /// doesn't is of a type that can be converted.
+ private static ImageBasedMapData CreateMapData(BackgroundData backgroundData)
+ {
var wmtsBackgroundDataConfiguration = backgroundData.Configuration as WmtsBackgroundDataConfiguration;
if (wmtsBackgroundDataConfiguration != null)
{
- mapData = CreateWmtsMapData(wmtsBackgroundDataConfiguration);
+ return CreateWmtsMapData(wmtsBackgroundDataConfiguration);
}
-
var wellKnownBackgroundDataConfiguration = backgroundData.Configuration as WellKnownBackgroundDataConfiguration;
if (wellKnownBackgroundDataConfiguration != null)
{
- mapData = CreateWellKnownMapdata(wellKnownBackgroundDataConfiguration);
+ return CreateWellKnownMapdata(wellKnownBackgroundDataConfiguration);
}
-
- mapData.Name = backgroundData.Name;
- mapData.IsVisible = backgroundData.IsVisible;
- mapData.Transparency = backgroundData.Transparency;
-
- return mapData;
+ throw new NotSupportedException($"Can't create a image based map data for {backgroundData.Configuration.GetType()}.");
}
///
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/TypeConverters/BackgroundDataConverterTest.cs
===================================================================
diff -u -r935e492135a782b9e63c0924df798ebb358ac7cc -ra7c7037989d2ccfa2d482a1f54f7f9f8bac0b9e7
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/TypeConverters/BackgroundDataConverterTest.cs (.../BackgroundDataConverterTest.cs) (revision 935e492135a782b9e63c0924df798ebb358ac7cc)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/TypeConverters/BackgroundDataConverterTest.cs (.../BackgroundDataConverterTest.cs) (revision a7c7037989d2ccfa2d482a1f54f7f9f8bac0b9e7)
@@ -34,7 +34,7 @@
namespace Ringtoets.Common.Utils.Test.TypeConverters
{
[TestFixture]
- public class BackgroundDataConverterTest
+ public class BackgroundDataConverterTestW
{
private static IEnumerable WmtsMapDatas
{
@@ -69,7 +69,7 @@
// Assert
var exception = Assert.Throws(call);
- string expectedMessage = $"Can't create a background data configuration for {unsupportedImageBasedMapData.GetType()}.";
+ string expectedMessage = $"Can't create a background data configuration for {typeof(TestImageBasedMapData)}.";
Assert.AreEqual(expectedMessage, exception.Message);
}
@@ -130,6 +130,21 @@
}
[Test]
+ public void ConvertFrom_ConfigurationTypeNotSupportedForConversion_ThrowNotSupportedException()
+ {
+ // Setup
+ var backgroundData = new BackgroundData(new TestBackgroundDataConfiguration());
+
+ // Call
+ TestDelegate test = () => BackgroundDataConverter.ConvertFrom(backgroundData);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ string expectedMessage = $"Can't create a image based map data for {typeof(TestBackgroundDataConfiguration)}.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ [Test]
[TestCaseSource(nameof(WmtsMapDatas))]
public void ConvertFrom_BackgroundData_ReturnWmtsMapData(WmtsMapData mapData)
{