Browse Source

[SL.Core] Remove unused Gaurd overloads

af/octree-no-pixelmap
Jason Nelson 8 years ago
parent
commit
89ab204a54
  1. 32
      src/SixLabors.Core/Helpers/Guard.cs
  2. 37
      tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

32
src/SixLabors.Core/Helpers/Guard.cs

@ -20,19 +20,13 @@ namespace SixLabors
/// </summary> /// </summary>
/// <param name="target">The target object, which cannot be null.</param> /// <param name="target">The target object, which cannot be null.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param> /// <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="ArgumentNullException"><paramref name="target"/> is null</exception> /// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
/// <typeparam name="T">The type of the object to verify</typeparam> /// <typeparam name="T">The type of the object to verify</typeparam>
public static void NotNull<T>(T target, string parameterName, string message = "") public static void NotNull<T>(T target, string parameterName)
where T : class where T : class
{ {
if (target == null) if (target is null)
{ {
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentNullException(parameterName, message);
}
throw new ArgumentNullException(parameterName); throw new ArgumentNullException(parameterName);
} }
} }
@ -44,20 +38,14 @@ namespace SixLabors
/// </summary> /// </summary>
/// <param name="target">The target string, which should be checked against being null or empty.</param> /// <param name="target">The target string, which should be checked against being null or empty.</param>
/// <param name="parameterName">Name of the parameter.</param> /// <param name="parameterName">Name of the parameter.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception> /// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception>
public static void NotNullOrEmpty(string target, string parameterName, string message = "") public static void NotNullOrEmpty(string target, string parameterName)
{ {
NotNull(target, parameterName, message); NotNull(target, parameterName);
if (string.IsNullOrWhiteSpace(target)) if (string.IsNullOrWhiteSpace(target))
{ {
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentException(message, parameterName);
}
throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName); throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName);
} }
} }
@ -68,20 +56,14 @@ namespace SixLabors
/// <typeparam name="T">The type of objects in the <paramref name="target"/></typeparam> /// <typeparam name="T">The type of objects in the <paramref name="target"/></typeparam>
/// <param name="target">The target enumeration, which should be checked against being null or empty.</param> /// <param name="target">The target enumeration, which should be checked against being null or empty.</param>
/// <param name="parameterName">Name of the parameter.</param> /// <param name="parameterName">Name of the parameter.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="target"/> is empty.</exception> /// <exception cref="ArgumentException"><paramref name="target"/> is empty.</exception>
public static void NotNullOrEmpty<T>(IEnumerable<T> target, string parameterName, string message = "") public static void NotNullOrEmpty<T>(IEnumerable<T> target, string parameterName)
{ {
NotNull(target, parameterName, message); NotNull(target, parameterName);
if (!target.Any()) if (!target.Any())
{ {
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentException(message, parameterName);
}
throw new ArgumentException("Value cannot be empty.", parameterName); throw new ArgumentException("Value cannot be empty.", parameterName);
} }
} }
@ -247,4 +229,4 @@ namespace SixLabors
} }
} }
} }
} }

37
tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Xunit; using Xunit;
namespace SixLabors.Helpers.Tests namespace SixLabors.Helpers.Tests
@ -25,18 +24,6 @@ namespace SixLabors.Helpers.Tests
}); });
} }
[Fact]
public void NotNull_TargetNullWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNull((object)null, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact] [Fact]
public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException() public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException()
{ {
@ -73,18 +60,6 @@ namespace SixLabors.Helpers.Tests
Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace.")); Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace."));
} }
[Fact]
public void NotNullOrEmpty_TargetEmptyWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(string.Empty, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact] [Fact]
public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException() public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException()
{ {
@ -112,18 +87,6 @@ namespace SixLabors.Helpers.Tests
Assert.True(exception.Message.Contains("Value cannot be empty.")); Assert.True(exception.Message.Contains("Value cannot be empty."));
} }
[Fact]
public void NotNullOrEmptyIEnumerable_TargetEmptyWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(new string[] { }, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact] [Fact]
public void MustBeLessThan_IsLess_ThrowsNoException() public void MustBeLessThan_IsLess_ThrowsNoException()
{ {

Loading…
Cancel
Save