Browse Source

Some more refactoring in the Guard class.

Former-commit-id: a13359d3b5bb3984fdd55804226e54f0e25e9626
Former-commit-id: 2efc5aa9f7e6badd2287ae70743909023c0fb92b
Former-commit-id: 049d5e9f2ff17f48f8f503cc6c34b900507a2ddc
af/merge-core
dirk 10 years ago
parent
commit
f75964db20
  1. 22
      src/ImageProcessorCore/Common/Helpers/Guard.cs
  2. 8
      tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs

22
src/ImageProcessorCore/Common/Helpers/Guard.cs

@ -174,18 +174,13 @@ namespace ImageProcessorCore
/// The error message, if any to add to the exception.
/// </param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is null
/// <paramref name="target"/> is false
/// </exception>
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
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is null
/// <paramref name="target"/> is true
/// </exception>
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);
}
}
}

8
tests/ImageProcessorCore.Tests/Helpers/GuardTests.cs

@ -207,7 +207,7 @@ namespace ImageProcessorCore.Tests.Helpers
[Fact]
public void IsTrueThrowsWhenArgIsFalse()
{
Assert.Throws<ArgumentException>(() => Guard.IsTrue(false, "foo"));
Assert.Throws<ArgumentException>(() => Guard.IsTrue(false, "foo", "message"));
}
/// <summary>
@ -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<ArgumentException>(() => Guard.IsFalse(true, "foo"));
Assert.Throws<ArgumentException>(() => Guard.IsFalse(true, "foo", "message"));
}
/// <summary>
@ -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);
}
}

Loading…
Cancel
Save