From f75964db20a54291e130ea7e1750afef8db5f6e7 Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 26 Aug 2016 12:58:26 +0200 Subject: [PATCH] Some more refactoring in the Guard class. Former-commit-id: a13359d3b5bb3984fdd55804226e54f0e25e9626 Former-commit-id: 2efc5aa9f7e6badd2287ae70743909023c0fb92b Former-commit-id: 049d5e9f2ff17f48f8f503cc6c34b900507a2ddc --- .../Common/Helpers/Guard.cs | 22 +++++-------------- .../Helpers/GuardTests.cs | 8 +++---- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/ImageProcessorCore/Common/Helpers/Guard.cs b/src/ImageProcessorCore/Common/Helpers/Guard.cs index c5efb01ea..1e9b3ea23 100644 --- a/src/ImageProcessorCore/Common/Helpers/Guard.cs +++ b/src/ImageProcessorCore/Common/Helpers/Guard.cs @@ -174,18 +174,13 @@ namespace ImageProcessorCore /// The error message, if any to add to the exception. /// /// - /// is null + /// is false /// - public static void IsTrue(bool target, string parameterName, string message = "") + public static void IsTrue(bool target, string parameterName, string message) { if (!target) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(parameterName, message); - } - - throw new ArgumentException(parameterName); + throw new ArgumentException(message, parameterName); } } @@ -197,18 +192,13 @@ namespace ImageProcessorCore /// The name of the parameter that is to be checked. /// The error message, if any to add to the exception. /// - /// is null + /// is true /// - public static void IsFalse(bool target, string parameterName, string message = "") + public static void IsFalse(bool target, string parameterName, string message) { if (target) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(parameterName, message); - } - - throw new ArgumentException(parameterName); + throw new ArgumentException(message, parameterName); } } } diff --git a/tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs b/tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs index 7c33470c3..b92c4e0a8 100644 --- a/tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs +++ b/tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs @@ -207,7 +207,7 @@ namespace ImageProcessorCore.Tests.Helpers [Fact] public void IsTrueThrowsWhenArgIsFalse() { - Assert.Throws(() => Guard.IsTrue(false, "foo")); + Assert.Throws(() => Guard.IsTrue(false, "foo", "message")); } /// @@ -216,7 +216,7 @@ namespace ImageProcessorCore.Tests.Helpers [Fact] public void IsTrueDoesThrowsWhenArgIsTrue() { - Exception ex = Record.Exception(() => Guard.IsTrue(true, "foo")); + Exception ex = Record.Exception(() => Guard.IsTrue(true, "foo", "message")); Assert.Null(ex); } @@ -226,7 +226,7 @@ namespace ImageProcessorCore.Tests.Helpers [Fact] public void IsFalseThrowsWhenArgIsFalse() { - Assert.Throws(() => Guard.IsFalse(true, "foo")); + Assert.Throws(() => Guard.IsFalse(true, "foo", "message")); } /// @@ -235,7 +235,7 @@ namespace ImageProcessorCore.Tests.Helpers [Fact] public void IsFalseDoesThrowsWhenArgIsTrue() { - Exception ex = Record.Exception(() => Guard.IsFalse(false, "foo")); + Exception ex = Record.Exception(() => Guard.IsFalse(false, "foo", "message")); Assert.Null(ex); } }