Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs
===================================================================
diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -48,6 +48,10 @@
/// Thrown when any input parameter is null.
/// Thrown when
/// of is empty.
+ /// Thrown when the
+ /// contains an invalid type of characteristic point.
+ /// Thrown when the contains a
+ /// characteristic point that is not supported.
public static PipingSurfaceLine ReadAsPipingSurfaceLine(this SurfaceLineEntity entity,
ReadConversionCollector collector)
{
@@ -89,6 +93,10 @@
/// Thrown when any input parameter is null.
/// Thrown when
/// of is empty.
+ /// Thrown when the
+ /// contains an invalid type of characteristic point.
+ /// Thrown when the contains a
+ /// characteristic point that is not supported.
public static MacroStabilityInwardsSurfaceLine ReadAsMacroStabilityInwardsSurfaceLine(
this SurfaceLineEntity entity,
ReadConversionCollector collector)
@@ -126,6 +134,16 @@
entity.ReferenceLineIntersectionY.ToNullAsNaN());
}
+ ///
+ /// Reads the characteristic points from the and sets these
+ /// to the .
+ ///
+ /// The entity to read.
+ /// The surface line to set the characteristic point on.
+ /// Thrown when the
+ /// contains an invalid type of characteristic point.
+ /// Thrown when the contains a
+ /// characteristic point that is not supported.
private static void ReadCharacteristicPoints(this SurfaceLineEntity entity, PipingSurfaceLine surfaceLine)
{
var characteristicPoints = new Dictionary();
@@ -139,6 +157,16 @@
characteristicPoints.ForEachElementDo(cp => SetCharacteristicPoint(surfaceLine, cp.Key, cp.Value));
}
+ ///
+ /// Reads the characteristic points from the and sets these
+ /// to the .
+ ///
+ /// The entity to read.
+ /// The surface line to set the characteristic point on.
+ /// Thrown when the
+ /// contains an invalid type of characteristic point.
+ /// Thrown when the contains a
+ /// characteristic point that is not supported.
private static void ReadCharacteristicPoints(this SurfaceLineEntity entity, MacroStabilityInwardsSurfaceLine surfaceLine)
{
var characteristicPoints = new Dictionary();
@@ -152,10 +180,27 @@
characteristicPoints.ForEachElementDo(cp => SetCharacteristicPoint(surfaceLine, cp.Key, cp.Value));
}
+
+ ///
+ /// Sets the characteristic point and its coordinate to the .
+ ///
+ /// The surface line to set the characteristic point on.
+ /// The type of characteristic point.
+ /// The point associated with the characteristic point.
+ /// Thrown when is not
+ /// a valid .
+ /// Thrown when is not supported.
private static void SetCharacteristicPoint(PipingSurfaceLine surfaceLine,
PipingCharacteristicPointType type,
Point3D geometryPoint)
{
+ if (!Enum.IsDefined(typeof(PipingCharacteristicPointType), type))
+ {
+ throw new InvalidEnumArgumentException(nameof(type),
+ (int) type,
+ typeof(PipingCharacteristicPointType));
+ }
+
switch (type)
{
case PipingCharacteristicPointType.DikeToeAtRiver:
@@ -177,16 +222,30 @@
surfaceLine.SetDitchPolderSideAt(geometryPoint);
break;
default:
- throw new InvalidEnumArgumentException(nameof(type),
- (int) type,
- typeof(PipingCharacteristicPointType));
+ throw new NotSupportedException($"The enum value {nameof(PipingCharacteristicPointType)}.{type} is not supported.");
}
}
+ ///
+ /// Sets the characteristic point and its coordinate to the .
+ ///
+ /// The surface line to set the characteristic point on.
+ /// The type of characteristic point.
+ /// The point associated with the characteristic point.
+ /// Thrown when is not
+ /// a valid .
+ /// Thrown when is not supported.
private static void SetCharacteristicPoint(MacroStabilityInwardsSurfaceLine surfaceLine,
MacroStabilityInwardsCharacteristicPointType type,
Point3D geometryPoint)
{
+ if (!Enum.IsDefined(typeof(MacroStabilityInwardsCharacteristicPointType), type))
+ {
+ throw new InvalidEnumArgumentException(nameof(type),
+ (int) type,
+ typeof(MacroStabilityInwardsCharacteristicPointType));
+ }
+
switch (type)
{
case MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside:
@@ -226,9 +285,7 @@
surfaceLine.SetDitchPolderSideAt(geometryPoint);
break;
default:
- throw new InvalidEnumArgumentException(nameof(type),
- (int) type,
- typeof(MacroStabilityInwardsCharacteristicPointType));
+ throw new NotSupportedException($"The enum value {nameof(MacroStabilityInwardsCharacteristicPointType)}.{type} is not supported.");
}
}
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs
===================================================================
diff -u -r39e941a3f116d264000cd6f46a61f64674063933 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 39e941a3f116d264000cd6f46a61f64674063933)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -20,11 +20,13 @@
// All rights reserved.
using System;
+using System.ComponentModel;
using System.Linq;
using Application.Ringtoets.Storage.DbContext;
using Application.Ringtoets.Storage.Read;
using Application.Ringtoets.Storage.Serializers;
using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.Primitives;
using Ringtoets.Piping.Primitives;
@@ -297,6 +299,39 @@
}
[Test]
+ public void ReadAsPipingSurfaceLine_WithInvalidPipingCharacteristicPointType_ThrowsInvalidEnumArgumentException()
+ {
+ // Setup
+ var random = new Random(31);
+
+ var points = new[]
+ {
+ CreatePoint3D(random)
+ };
+
+ const byte invalidCharacteristicPointType = 37;
+ var entity = new SurfaceLineEntity
+ {
+ Name = "Better name.",
+ ReferenceLineIntersectionX = random.NextDouble(),
+ ReferenceLineIntersectionY = random.NextDouble(),
+ PointsXml = new Point3DXmlSerializer().ToXml(points),
+ PipingCharacteristicPointEntities =
+ {
+ CreatePipingCharacteristicPointEntity(points[0], (PipingCharacteristicPointType) invalidCharacteristicPointType)
+ }
+ };
+
+ // Call
+ TestDelegate call = () => entity.ReadAsPipingSurfaceLine(new ReadConversionCollector());
+
+ // Assert
+ string exoectedMessage = $"The value of argument 'type' ({invalidCharacteristicPointType}) is invalid for Enum type '{nameof(PipingCharacteristicPointType)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName;
+ Assert.AreEqual("type", parameterName);
+ }
+
+ [Test]
public void ReadAsPipingSurfaceLine_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine()
{
// Setup
@@ -618,6 +653,39 @@
}
[Test]
+ public void ReadAsMacroStabilityInwardsSurfaceLine_WithInvalidMacroStabilityCharacteristicPointType_ThrowsInvalidEnumArgumentException()
+ {
+ // Setup
+ var random = new Random(31);
+
+ var points = new[]
+ {
+ CreatePoint3D(random)
+ };
+
+ const byte invalidCharacteristicPointType = 37;
+ var entity = new SurfaceLineEntity
+ {
+ Name = "Better name.",
+ ReferenceLineIntersectionX = random.NextDouble(),
+ ReferenceLineIntersectionY = random.NextDouble(),
+ PointsXml = new Point3DXmlSerializer().ToXml(points),
+ MacroStabilityInwardsCharacteristicPointEntities =
+ {
+ CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], (MacroStabilityInwardsCharacteristicPointType) invalidCharacteristicPointType)
+ }
+ };
+
+ // Call
+ TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(new ReadConversionCollector());
+
+ // Assert
+ string exoectedMessage = $"The value of argument 'type' ({invalidCharacteristicPointType}) is invalid for Enum type '{nameof(MacroStabilityInwardsCharacteristicPointType)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName;
+ Assert.AreEqual("type", parameterName);
+ }
+
+ [Test]
public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine()
{
// Setup
Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs
===================================================================
diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -418,6 +418,11 @@
private void AddLayoutAnchorable(LayoutAnchorable layoutAnchorable, ToolViewLocation toolViewLocation)
{
LayoutAnchorablePaneGroup layoutAnchorablePaneGroup;
+ if (!Enum.IsDefined(typeof(ToolViewLocation), toolViewLocation))
+ {
+ throw new InvalidEnumArgumentException(nameof(toolViewLocation), (int)toolViewLocation, typeof(ToolViewLocation));
+ }
+
switch (toolViewLocation)
{
case ToolViewLocation.Left:
@@ -445,7 +450,7 @@
layoutAnchorablePaneGroup = RightLayoutAnchorablePaneGroup;
break;
default:
- throw new InvalidEnumArgumentException(nameof(toolViewLocation), (int) toolViewLocation, typeof(ToolViewLocation));
+ throw new NotSupportedException($"The enum value {nameof(ToolViewLocation)}.{toolViewLocation} is not supported.");
}
layoutAnchorablePaneGroup.Descendents()
Index: Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj
===================================================================
diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj (.../Core.Common.TestUtil.Test.csproj) (revision ac96d7c315129af851634ed5a4a6800b59ede718)
+++ Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj (.../Core.Common.TestUtil.Test.csproj) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -35,6 +35,7 @@
+
True
Index: Core/Common/test/Core.Common.TestUtil.Test/LogLevelConstantExtensionsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.TestUtil.Test/LogLevelConstantExtensionsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.TestUtil.Test/LogLevelConstantExtensionsTest.cs (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -0,0 +1,70 @@
+// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic;
+using System.ComponentModel;
+using log4net.Core;
+using NUnit.Framework;
+
+namespace Core.Common.TestUtil.Test
+{
+ [TestFixture]
+ public class LogLevelConstantExtensionsTest
+ {
+ [Test]
+ [TestCaseSource(nameof(GetMappedLogLevelConstants))]
+ public void ToLog4NetLevel_SupportedLogLevelConstants_ReturnsExpectedLevel(LogLevelConstant logLevelConstant,
+ Level expectedLevel)
+ {
+ // Call
+ Level level = logLevelConstant.ToLog4NetLevel();
+
+ // Assert
+ Assert.AreEqual(expectedLevel, level);
+ }
+
+ [Test]
+ public void ToLog4NetLevel_InvalidLogLevelConstant_ThrowsInvalidEnumArgumentException()
+ {
+ // Setup
+ const int invalidValue = 9999;
+ const LogLevelConstant invalidLogLevelConstant = (LogLevelConstant) invalidValue;
+
+ // Call
+ TestDelegate call = () => invalidLogLevelConstant.ToLog4NetLevel();
+
+ // Assert
+ string exoectedMessage = $"The value of argument 'level' ({invalidValue}) is invalid for Enum type '{nameof(LogLevelConstant)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName;
+ Assert.AreEqual("level", parameterName);
+ }
+
+ private static IEnumerable GetMappedLogLevelConstants()
+ {
+ yield return new TestCaseData(LogLevelConstant.Off, Level.Off);
+ yield return new TestCaseData(LogLevelConstant.Fatal, Level.Fatal);
+ yield return new TestCaseData(LogLevelConstant.Error, Level.Error);
+ yield return new TestCaseData(LogLevelConstant.Warn, Level.Warn);
+ yield return new TestCaseData(LogLevelConstant.Info, Level.Info);
+ yield return new TestCaseData(LogLevelConstant.Debug, Level.Debug);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs
===================================================================
diff -u -r569a286badd9b3494f5465cc2767a8cf6a77f618 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs (.../LogLevelConstant.cs) (revision 569a286badd9b3494f5465cc2767a8cf6a77f618)
+++ Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs (.../LogLevelConstant.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -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 log4net.Core;
@@ -36,8 +37,22 @@
public static class LogLevelConstantExtensions
{
+ ///
+ /// Converts a to a .
+ ///
+ /// The to convert.
+ /// The based on the .
+ /// Thrown when
+ /// is not a valid value for .
+ /// Thrown when
+ /// is not a supported member.
public static Level ToLog4NetLevel(this LogLevelConstant level)
{
+ if (!Enum.IsDefined(typeof(LogLevelConstant), level))
+ {
+ throw new InvalidEnumArgumentException(nameof(level), (int)level, typeof(LogLevelConstant));
+ }
+
switch (level)
{
case LogLevelConstant.Off:
@@ -53,7 +68,7 @@
case LogLevelConstant.Debug:
return Level.Debug;
default:
- throw new InvalidEnumArgumentException(nameof(level), (int) level, typeof(LogLevelConstant));
+ throw new NotSupportedException($"The enum value {nameof(LogLevelConstant)}.{level} is not supported.");
}
}
}
Index: Core/Components/src/Core.Components.BruTile/Configurations/WellKnownTileSourceLayerConfiguration.cs
===================================================================
diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Core/Components/src/Core.Components.BruTile/Configurations/WellKnownTileSourceLayerConfiguration.cs (.../WellKnownTileSourceLayerConfiguration.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a)
+++ Core/Components/src/Core.Components.BruTile/Configurations/WellKnownTileSourceLayerConfiguration.cs (.../WellKnownTileSourceLayerConfiguration.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.ComponentModel;
using System.IO;
using BruTile;
using BruTile.Predefined;
@@ -107,10 +108,19 @@
///
/// The tile provider to be used.
/// The equivalent of the .
+ /// Thrown when
+ /// is not a valid enum value of .
/// Thrown when
/// is not a supported member.
private static KnownTileSource WellKnownTileSourceToKnownTileSource(WellKnownTileSource wellKnownTileSource)
{
+ if (!Enum.IsDefined(typeof(WellKnownTileSource), wellKnownTileSource))
+ {
+ throw new InvalidEnumArgumentException(nameof(wellKnownTileSource),
+ (int) wellKnownTileSource,
+ typeof(WellKnownTileSource));
+ }
+
switch (wellKnownTileSource)
{
case WellKnownTileSource.BingAerial:
Index: Core/Components/test/Core.Components.BruTile.Test/Configurations/WellKnownTileSourceLayerConfigurationTest.cs
===================================================================
diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4
--- Core/Components/test/Core.Components.BruTile.Test/Configurations/WellKnownTileSourceLayerConfigurationTest.cs (.../WellKnownTileSourceLayerConfigurationTest.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718)
+++ Core/Components/test/Core.Components.BruTile.Test/Configurations/WellKnownTileSourceLayerConfigurationTest.cs (.../WellKnownTileSourceLayerConfigurationTest.cs) (revision 7f82fd637dc8796f3d270cb0fa6d9ab18548c6f4)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.ComponentModel;
using Core.Common.TestUtil;
using Core.Common.Util.TestUtil.Settings;
using Core.Components.BruTile.Configurations;
@@ -37,16 +38,18 @@
private TestSettingsHelper testSettingsHelper;
[Test]
- public void CreateInitializedConfiguration_InvalidWellKnownTileSource_ThrowNotSupportedException()
+ public void CreateInitializedConfiguration_InvalidWellKnownTileSource_ThenThrowsInvalidEnumArgumentException()
{
// Setup
- const WellKnownTileSource invalidValue = (WellKnownTileSource) 9999;
-
+ const int invalidTileSource = 9999;
+
// Call
- TestDelegate call = () => WellKnownTileSourceLayerConfiguration.CreateInitializedConfiguration(invalidValue);
+ TestDelegate call = () => WellKnownTileSourceLayerConfiguration.CreateInitializedConfiguration((WellKnownTileSource) invalidTileSource);
// Assert
- Assert.Throws(call);
+ string exoectedMessage = $"The value of argument 'wellKnownTileSource' ({invalidTileSource}) is invalid for Enum type '{nameof(WellKnownTileSource)}'.";
+ string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, exoectedMessage).ParamName;
+ Assert.AreEqual("wellKnownTileSource", parameterName);
}
[Test]