mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
15 changed files with 52 additions and 784 deletions
@ -1,294 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Diagnostics; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Provides methods to protect against invalid parameters.
|
|
||||
/// </summary>
|
|
||||
[DebuggerStepThrough] |
|
||||
internal static class Guard |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Ensures that the value is not null.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target object, which cannot be null.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null</exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void NotNull<T>(T value, string parameterName) |
|
||||
where T : class |
|
||||
{ |
|
||||
if (value is null) |
|
||||
{ |
|
||||
ThrowArgumentNullException(parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Ensures that the target value is not null, empty, or whitespace.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target string, which should be checked against being null or empty.</param>
|
|
||||
/// <param name="parameterName">Name of the parameter.</param>
|
|
||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
|
|
||||
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or contains only blanks.</exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void NotNullOrWhiteSpace(string value, string parameterName) |
|
||||
{ |
|
||||
if (value is null) |
|
||||
{ |
|
||||
ThrowArgumentNullException(parameterName); |
|
||||
} |
|
||||
|
|
||||
if (string.IsNullOrWhiteSpace(value)) |
|
||||
{ |
|
||||
ThrowArgumentException("Must not be empty or whitespace.", parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Ensures that the specified value is less than a maximum value.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target value, which should be validated.</param>
|
|
||||
/// <param name="max">The maximum value.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="value"/> is greater than the maximum value.
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) |
|
||||
where TValue : IComparable<TValue> |
|
||||
{ |
|
||||
if (value.CompareTo(max) >= 0) |
|
||||
{ |
|
||||
ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than {max}."); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the specified value is less than or equal to a maximum value
|
|
||||
/// and throws an exception if it is not.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target value, which should be validated.</param>
|
|
||||
/// <param name="max">The maximum value.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="value"/> is greater than the maximum value.
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) |
|
||||
where TValue : IComparable<TValue> |
|
||||
{ |
|
||||
if (value.CompareTo(max) > 0) |
|
||||
{ |
|
||||
ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than or equal to {max}."); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the specified value is greater than a minimum value
|
|
||||
/// and throws an exception if it is not.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target value, which should be validated.</param>
|
|
||||
/// <param name="min">The minimum value.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="value"/> is less than the minimum value.
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) |
|
||||
where TValue : IComparable<TValue> |
|
||||
{ |
|
||||
if (value.CompareTo(min) <= 0) |
|
||||
{ |
|
||||
ThrowArgumentOutOfRangeException( |
|
||||
parameterName, |
|
||||
$"Value {value} must be greater than {min}."); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the specified value is greater than or equal to a minimum value
|
|
||||
/// and throws an exception if it is not.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target value, which should be validated.</param>
|
|
||||
/// <param name="min">The minimum value.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="value"/> is less than the minimum value.
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) |
|
||||
where TValue : IComparable<TValue> |
|
||||
{ |
|
||||
if (value.CompareTo(min) < 0) |
|
||||
{ |
|
||||
ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min}."); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the specified value is greater than or equal to a minimum value and less than
|
|
||||
/// or equal to a maximum value and throws an exception if it is not.
|
|
||||
/// </summary>
|
|
||||
/// <param name="value">The target value, which should be validated.</param>
|
|
||||
/// <param name="min">The minimum value.</param>
|
|
||||
/// <param name="max">The maximum value.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="value"/> is less than the minimum value of greater than the maximum value.
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) |
|
||||
where TValue : IComparable<TValue> |
|
||||
{ |
|
||||
if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) |
|
||||
{ |
|
||||
ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}."); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies, that the method parameter with specified target value is true
|
|
||||
/// and throws an exception if it is found to be so.
|
|
||||
/// </summary>
|
|
||||
/// <param name="target">The target value, which cannot be false.</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="ArgumentException">
|
|
||||
/// <paramref name="target"/> is false
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void IsTrue(bool target, string parameterName, string message) |
|
||||
{ |
|
||||
if (!target) |
|
||||
{ |
|
||||
ThrowArgumentException(message, parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies, that the method parameter with specified target value is false
|
|
||||
/// and throws an exception if it is found to be so.
|
|
||||
/// </summary>
|
|
||||
/// <param name="target">The target value, which cannot be true.</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="ArgumentException">
|
|
||||
/// <paramref name="target"/> is true
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void IsFalse(bool target, string parameterName, string message) |
|
||||
{ |
|
||||
if (target) |
|
||||
{ |
|
||||
ThrowArgumentException(message, parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies, that the `source` span has the length of 'minLength', or longer.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="T">The element type of the spans</typeparam>
|
|
||||
/// <param name="source">The source span.</param>
|
|
||||
/// <param name="minLength">The minimum length.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="source"/> has less than <paramref name="minLength"/> items
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength, string parameterName) |
|
||||
{ |
|
||||
if (source.Length < minLength) |
|
||||
{ |
|
||||
ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the 'destination' span is not shorter than 'source'.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TSource">The source element type</typeparam>
|
|
||||
/// <typeparam name="TDest">The destination element type</typeparam>
|
|
||||
/// <param name="source">The source span</param>
|
|
||||
/// <param name="destination">The destination span</param>
|
|
||||
/// <param name="destinationParamName">The name of the argument for 'destination'</param>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void DestinationShouldNotBeTooShort<TSource, TDest>( |
|
||||
ReadOnlySpan<TSource> source, |
|
||||
Span<TDest> destination, |
|
||||
string destinationParamName) |
|
||||
{ |
|
||||
if (destination.Length < source.Length) |
|
||||
{ |
|
||||
ThrowArgumentException("Destination span is too short!", destinationParamName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies that the 'destination' span is not shorter than 'source'.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TSource">The source element type</typeparam>
|
|
||||
/// <typeparam name="TDest">The destination element type</typeparam>
|
|
||||
/// <param name="source">The source span</param>
|
|
||||
/// <param name="destination">The destination span</param>
|
|
||||
/// <param name="destinationParamName">The name of the argument for 'destination'</param>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void DestinationShouldNotBeTooShort<TSource, TDest>( |
|
||||
Span<TSource> source, |
|
||||
Span<TDest> destination, |
|
||||
string destinationParamName) |
|
||||
{ |
|
||||
if (destination.Length < source.Length) |
|
||||
{ |
|
||||
ThrowArgumentException("Destination span is too short!", destinationParamName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Verifies, that the `source` span has the length of 'minLength', or longer.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="T">The element type of the spans</typeparam>
|
|
||||
/// <param name="source">The target span.</param>
|
|
||||
/// <param name="minLength">The minimum length.</param>
|
|
||||
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
||||
/// <exception cref="ArgumentException">
|
|
||||
/// <paramref name="source"/> has less than <paramref name="minLength"/> items
|
|
||||
/// </exception>
|
|
||||
[MethodImpl(InliningOptions.ShortMethod)] |
|
||||
public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string parameterName) |
|
||||
{ |
|
||||
if (source.Length < minLength) |
|
||||
{ |
|
||||
ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[MethodImpl(InliningOptions.ColdPath)] |
|
||||
private static void ThrowArgumentException(string message, string parameterName) |
|
||||
{ |
|
||||
throw new ArgumentException(message, parameterName); |
|
||||
} |
|
||||
|
|
||||
[MethodImpl(InliningOptions.ColdPath)] |
|
||||
private static void ThrowArgumentOutOfRangeException(string parameterName, string message) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException(parameterName, message); |
|
||||
} |
|
||||
|
|
||||
[MethodImpl(InliningOptions.ColdPath)] |
|
||||
private static void ThrowArgumentNullException(string parameterName) |
|
||||
{ |
|
||||
throw new ArgumentNullException(parameterName); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
{ |
|
||||
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", |
|
||||
"settings": { |
|
||||
"orderingRules": { |
|
||||
"usingDirectivesPlacement": "outsideNamespace", |
|
||||
"elementOrder": [ |
|
||||
"kind" |
|
||||
] |
|
||||
}, |
|
||||
"documentationRules": { |
|
||||
"xmlHeader": false, |
|
||||
"documentInternalElements": false, |
|
||||
"copyrightText": "Copyright (c) Six Labors and contributors.\nLicensed under the Apache License, Version 2.0." |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,274 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Diagnostics.CodeAnalysis; |
|
||||
|
|
||||
using Xunit; |
|
||||
// ReSharper disable InconsistentNaming
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Helpers |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Tests the <see cref="Guard"/> helper.
|
|
||||
/// </summary>
|
|
||||
public class GuardTests |
|
||||
{ |
|
||||
class Test |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(0, 0)] |
|
||||
[InlineData(0, 1)] |
|
||||
[InlineData(0, 42)] |
|
||||
[InlineData(1, 1)] |
|
||||
[InlineData(10, 42)] |
|
||||
[InlineData(42, 42)] |
|
||||
public void DestinationShouldNotBeTooShort_WhenOk(int sourceLength, int destLength) |
|
||||
{ |
|
||||
ReadOnlySpan<int> source = new int[sourceLength]; |
|
||||
Span<float> dest = new float[destLength]; |
|
||||
|
|
||||
Guard.DestinationShouldNotBeTooShort(source, dest, nameof(dest)); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(1, 0)] |
|
||||
[InlineData(42, 41)] |
|
||||
public void DestinationShouldNotBeTooShort_WhenThrows(int sourceLength, int destLength) |
|
||||
{ |
|
||||
Assert.ThrowsAny<ArgumentException>( |
|
||||
() => |
|
||||
{ |
|
||||
ReadOnlySpan<int> source = new int[sourceLength]; |
|
||||
Span<float> dest = new float[destLength]; |
|
||||
Guard.DestinationShouldNotBeTooShort(source, dest, nameof(dest)); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.NotNull"/> method throws when the argument is null.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void NotNullThrowsWhenArgIsNull() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => Guard.NotNull((Test)null, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.NotNull"/> method throws when the argument name is empty.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void NotNullThrowsWhenArgNameEmpty() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => Guard.NotNull((Test)null, string.Empty)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument is empty.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed. Suppression is OK here.")] |
|
||||
public void NotEmptyOrWhiteSpaceThrowsWhenEmpty() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentException>(() => Guard.NotNullOrWhiteSpace("", string.Empty)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument is whitespace.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void NotEmptyOrWhiteSpaceThrowsOnWhitespace() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentException>(() => Guard.NotNullOrWhiteSpace(" ", string.Empty)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument name is null.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void NotEmptyOrWhiteSpaceThrowsWhenParameterNameNull() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => Guard.NotNullOrWhiteSpace(null, null)); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void LessThanThrowsWhenArgIsGreater() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThan(1, 0, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is equal.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void LessThanThrowsWhenArgIsEqual() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThan(1, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method throws when the argument is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void LessThanOrEqualToThrowsWhenArgIsGreater() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThanOrEqualTo(1, 0, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|
||||
/// is less.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void LessThanOrEqualToDoesNotThrowWhenArgIsLess() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(0, 1, "foo")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|
||||
/// is equal.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void LessThanOrEqualToDoesNotThrowWhenArgIsEqual() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(1, 1, "foo")); |
|
||||
Assert.Equal(1, 1); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void GreaterThanThrowsWhenArgIsLess() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThan(0, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void GreaterThanThrowsWhenArgIsEqual() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThan(1, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument name is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void GreaterThanOrEqualToThrowsWhenArgIsLess() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThanOrEqualTo(0, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|
||||
/// is less.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void GreaterThanOrEqualToDoesNotThrowWhenArgIsGreater() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 0, "foo")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|
||||
/// is equal.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void GreaterThanOrEqualToDoesNotThrowWhenArgIsEqual() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 1, "foo")); |
|
||||
Assert.Equal(1, 1); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method throws when the argument is less.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void BetweenOrEqualToThrowsWhenArgIsLess() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeBetweenOrEqualTo(-2, -1, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method throws when the argument is greater.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void BetweenOrEqualToThrowsWhenArgIsGreater() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeBetweenOrEqualTo(2, -1, 1, "foo")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method does not throw when the argument
|
|
||||
/// is equal.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void BetweenOrEqualToDoesNotThrowWhenArgIsEqual() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(1, 1, 1, "foo")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method does not throw when the argument
|
|
||||
/// is equal.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void BetweenOrEqualToDoesNotThrowWhenArgIsBetween() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(0, -1, 1, "foo")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.IsTrue"/> method throws when the argument is false.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void IsTrueThrowsWhenArgIsFalse() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentException>(() => Guard.IsTrue(false, "foo", "message")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.IsTrue"/> method does not throw when the argument is true.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void IsTrueDoesThrowsWhenArgIsTrue() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.IsTrue(true, "foo", "message")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.IsFalse"/> method throws when the argument is true.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void IsFalseThrowsWhenArgIsFalse() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentException>(() => Guard.IsFalse(true, "foo", "message")); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Tests that the <see cref="M:Guard.IsFalse"/> method does not throw when the argument is false.
|
|
||||
/// </summary>
|
|
||||
[Fact] |
|
||||
public void IsFalseDoesThrowsWhenArgIsTrue() |
|
||||
{ |
|
||||
Exception ex = Record.Exception(() => Guard.IsFalse(false, "foo", "message")); |
|
||||
Assert.Null(ex); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue