Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapDataHelper.cs
===================================================================
diff -u -r2c5e077a0f546af6d6379eb93111fd8366fc2224 -rd500058ffe5b6cf9eed5849e8de4a168e8fa28e1
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapDataHelper.cs (.../MapDataHelper.cs) (revision 2c5e077a0f546af6d6379eb93111fd8366fc2224)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapDataHelper.cs (.../MapDataHelper.cs) (revision d500058ffe5b6cf9eed5849e8de4a168e8fa28e1)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using Core.Components.Gis.Data;
@@ -38,9 +39,18 @@
/// The symbol to convert.
/// The converted .
/// Thrown when
- /// cannot be converted.
+ /// is not a valid enum value of .
+ /// Thrown when
+ /// is not supported for the conversion.
public static PointShape Convert(PointSymbol symbol)
{
+ if (!Enum.IsDefined(typeof(PointSymbol), symbol))
+ {
+ throw new InvalidEnumArgumentException(nameof(symbol),
+ (int) symbol,
+ typeof(PointSymbol));
+ }
+
PointShape shape;
switch (symbol)
{
@@ -66,9 +76,7 @@
shape = PointShape.Pentagon;
break;
default:
- throw new InvalidEnumArgumentException(nameof(symbol),
- (int) symbol,
- typeof(PointShape));
+ throw new NotSupportedException($"The enum value {nameof(PointShape)}.{symbol} is not supported.");
}
return shape;
}
@@ -79,9 +87,18 @@
/// The to convert.
/// The converted .
/// Thrown when
- /// cannot be converted.
+ /// is not a valid enum value of .
+ /// Thrown when
+ /// is not supported for the conversion.
public static DashStyle Convert(LineDashStyle dashStyle)
{
+ if (!Enum.IsDefined(typeof(LineDashStyle), dashStyle))
+ {
+ throw new InvalidEnumArgumentException(nameof(dashStyle),
+ (int) dashStyle,
+ typeof(LineDashStyle));
+ }
+
var lineStyle = DashStyle.Solid;
switch (dashStyle)
{
@@ -100,9 +117,7 @@
lineStyle = DashStyle.DashDotDot;
break;
default:
- throw new InvalidEnumArgumentException(nameof(dashStyle),
- (int) dashStyle,
- typeof(LineDashStyle));
+ throw new NotSupportedException($"The enum value {nameof(LineDashStyle)}.{dashStyle} is not supported.");
}
return lineStyle;
}
Index: Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataHelper.cs
===================================================================
diff -u -r2c5e077a0f546af6d6379eb93111fd8366fc2224 -rd500058ffe5b6cf9eed5849e8de4a168e8fa28e1
--- Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataHelper.cs (.../ChartDataHelper.cs) (revision 2c5e077a0f546af6d6379eb93111fd8366fc2224)
+++ Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataHelper.cs (.../ChartDataHelper.cs) (revision d500058ffe5b6cf9eed5849e8de4a168e8fa28e1)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.ComponentModel;
using System.Drawing;
using Core.Components.Chart.Data;
@@ -38,9 +39,19 @@
/// The to convert.
/// The converted .
/// Thrown when
- /// cannot be converted.
+ /// is not a valid enum value of .
+ /// Thrown when
+ /// is not supported for the conversion.
public static LineStyle Convert(ChartLineDashStyle dashStyle)
{
+ if (!Enum.IsDefined(typeof(ChartLineDashStyle), dashStyle))
+ {
+ throw new InvalidEnumArgumentException(nameof(dashStyle),
+ (int)dashStyle,
+ typeof(ChartLineDashStyle));
+ }
+
+
var lineStyle = LineStyle.Solid;
switch (dashStyle)
{
@@ -59,9 +70,7 @@
lineStyle = LineStyle.DashDotDot;
break;
default:
- throw new InvalidEnumArgumentException(nameof(dashStyle),
- (int) dashStyle,
- typeof(ChartLineDashStyle));
+ throw new NotSupportedException($"The enum value {nameof(ChartLineDashStyle)}.{dashStyle} is not supported.");
}
return lineStyle;
}
@@ -72,9 +81,18 @@
/// The to convert.
/// The converted .
/// Thrown when
- /// cannot be converted.
+ /// is not a valid enum value of .
+ /// Thrown when
+ /// is not supported for the conversion.
public static MarkerType Convert(ChartPointSymbol symbol)
{
+ if (!Enum.IsDefined(typeof(ChartPointSymbol), symbol))
+ {
+ throw new InvalidEnumArgumentException(nameof(symbol),
+ (int)symbol,
+ typeof(ChartPointSymbol));
+ }
+
MarkerType markerType;
switch (symbol)
{
@@ -100,9 +118,7 @@
markerType = MarkerType.Plus;
break;
default:
- throw new InvalidEnumArgumentException(nameof(symbol),
- (int) symbol,
- typeof(ChartPointSymbol));
+ throw new NotSupportedException($"The enum value {nameof(ChartPointSymbol)}.{symbol} is not supported.");
}
return markerType;
}
Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataHelperTest.cs
===================================================================
diff -u -r6237af4606598e43ebf0b3815a12677277c6eda0 -rd500058ffe5b6cf9eed5849e8de4a168e8fa28e1
--- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataHelperTest.cs (.../MapDataHelperTest.cs) (revision 6237af4606598e43ebf0b3815a12677277c6eda0)
+++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataHelperTest.cs (.../MapDataHelperTest.cs) (revision d500058ffe5b6cf9eed5849e8de4a168e8fa28e1)
@@ -21,6 +21,7 @@
using System.ComponentModel;
using System.Drawing.Drawing2D;
+using Core.Common.TestUtil;
using Core.Components.DotSpatial.Converter;
using Core.Components.Gis.Style;
using DotSpatial.Symbology;
@@ -52,11 +53,16 @@
[Test]
public void Convert_InvalidPointSymbol_ThrowsInvalidEnumArgumentException()
{
+ // Setup
+ const int invalidValue = 100;
+
// Call
- TestDelegate test = () => MapDataHelper.Convert((PointSymbol) 100);
+ TestDelegate call = () => MapDataHelper.Convert((PointSymbol) invalidValue);
// Assert
- Assert.Throws(test);
+ string expectedMessage = $"The value of argument 'symbol' ({invalidValue}) is invalid for Enum type '{nameof(PointSymbol)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName;
+ Assert.AreEqual("symbol", parameterName);
}
[Test]
@@ -78,11 +84,16 @@
[Test]
public void Convert_InvalidLineDashStyle_ThrowsInvalidEnumArgumentException()
{
+ // Setup
+ const int invalidValue = 100;
+
// Call
- TestDelegate call = () => MapDataHelper.Convert((LineDashStyle) 100);
+ TestDelegate call = () => MapDataHelper.Convert((LineDashStyle) invalidValue);
// Assert
- Assert.Throws(call);
+ string expectedMessage = $"The value of argument 'dashStyle' ({invalidValue}) is invalid for Enum type '{nameof(LineDashStyle)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName;
+ Assert.AreEqual("dashStyle", parameterName);
}
}
}
\ No newline at end of file
Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataHelperTest.cs
===================================================================
diff -u -r6237af4606598e43ebf0b3815a12677277c6eda0 -rd500058ffe5b6cf9eed5849e8de4a168e8fa28e1
--- Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataHelperTest.cs (.../ChartDataHelperTest.cs) (revision 6237af4606598e43ebf0b3815a12677277c6eda0)
+++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataHelperTest.cs (.../ChartDataHelperTest.cs) (revision d500058ffe5b6cf9eed5849e8de4a168e8fa28e1)
@@ -21,6 +21,7 @@
using System.ComponentModel;
using System.Drawing;
+using Core.Common.TestUtil;
using Core.Components.Chart.Styles;
using Core.Components.OxyPlot.Converter;
using NUnit.Framework;
@@ -67,11 +68,16 @@
[Test]
public void Convert_InvalidChartLineDashStyle_ThrowsInvalidEnumArgumentException()
{
+ // Setup
+ const int invalidValue = 100;
+
// Call
- TestDelegate call = () => ChartDataHelper.Convert((ChartLineDashStyle) 100);
+ TestDelegate call = () => ChartDataHelper.Convert((ChartLineDashStyle) invalidValue);
// Assert
- Assert.Throws(call);
+ string expectedMessage = $"The value of argument 'dashStyle' ({invalidValue}) is invalid for Enum type '{nameof(ChartLineDashStyle)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName;
+ Assert.AreEqual("dashStyle", parameterName);
}
[Test]
@@ -95,11 +101,16 @@
[Test]
public void Convert_InvalidChartPointSymbol_ThrowsInvalidEnumArgumentException()
{
+ // Setup
+ const int invalidValue = 10;
+
// Call
- TestDelegate call = () => ChartDataHelper.Convert((ChartPointSymbol) 10);
+ TestDelegate call = () => ChartDataHelper.Convert((ChartPointSymbol) invalidValue);
// Assert
- Assert.Throws(call);
+ string expectedMessage = $"The value of argument 'symbol' ({invalidValue}) is invalid for Enum type '{nameof(ChartPointSymbol)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName;
+ Assert.AreEqual("symbol", parameterName);
}
}
}
\ No newline at end of file