if (!IsSupported)
throw new NotSupportedException(SR.NotSupported_CppCli);
- if (loadContext != IntPtr.Zero)
- throw new ArgumentOutOfRangeException(nameof(loadContext));
+ ArgumentOutOfRangeException.ThrowIfNotEqual(loadContext, IntPtr.Zero);
LoadInMemoryAssemblyInContextImpl(moduleHandle, assemblyPath, AssemblyLoadContext.Default);
}
<data name="ArgumentCannotBeOfTypeVoid" xml:space="preserve">
<value>Argument type cannot be System.Void.</value>
</data>
- <data name="OutOfRange" xml:space="preserve">
- <value>{0} must be greater than or equal to {1}</value>
- </data>
<data name="LabelTargetAlreadyDefined" xml:space="preserve">
<value>Cannot redefine label '{0}' in an inner block.</value>
</data>
ArgumentNullException.ThrowIfNull(args);
ArgumentNullException.ThrowIfNull(parameters);
ArgumentNullException.ThrowIfNull(returnLabel);
- if (args.Length == 0)
- {
- throw System.Linq.Expressions.Error.OutOfRange("args.Length", 1);
- }
- if (parameters.Count == 0)
- {
- throw System.Linq.Expressions.Error.OutOfRange("parameters.Count", 1);
- }
- if (args.Length != parameters.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(args));
- }
+ ArgumentOutOfRangeException.ThrowIfZero(args.Length);
+ ArgumentOutOfRangeException.ThrowIfZero(parameters.Count);
+ ArgumentOutOfRangeException.ThrowIfNotEqual(args.Length, parameters.Count);
// Ensure that the binder's ReturnType matches CallSite's return
// type. We do this so meta objects and language binders can
private static void ValidateSpan(int startLine, int startColumn, int endLine, int endColumn)
{
- if (startLine < 1)
- {
- throw Error.OutOfRange(nameof(startLine), 1);
- }
- if (startColumn < 1)
- {
- throw Error.OutOfRange(nameof(startColumn), 1);
- }
- if (endLine < 1)
- {
- throw Error.OutOfRange(nameof(endLine), 1);
- }
- if (endColumn < 1)
- {
- throw Error.OutOfRange(nameof(endColumn), 1);
- }
+ ArgumentOutOfRangeException.ThrowIfNegativeOrZero(startLine);
+ ArgumentOutOfRangeException.ThrowIfNegativeOrZero(startColumn);
+ ArgumentOutOfRangeException.ThrowIfNegativeOrZero(endLine);
+ ArgumentOutOfRangeException.ThrowIfNegativeOrZero(endColumn);
if (startLine > endLine)
{
throw Error.StartEndMustBeOrdered();
return new ArgumentException(Strings.ArgumentCannotBeOfTypeVoid, paramName);
}
/// <summary>
- /// ArgumentOutOfRangeException with message like "{0} must be greater than or equal to {1}"
- /// </summary>
- internal static ArgumentException OutOfRange(string? paramName, object? p1)
- {
- return new ArgumentOutOfRangeException(paramName, Strings.OutOfRange(paramName, p1));
- }
- /// <summary>
/// InvalidOperationException with message like "Cannot redefine label '{0}' in an inner block."
/// </summary>
internal static InvalidOperationException LabelTargetAlreadyDefined(object? p0)
internal static string ArgumentCannotBeOfTypeVoid => SR.ArgumentCannotBeOfTypeVoid;
/// <summary>
- /// A string like "{0} must be greater than or equal to {1}"
- /// </summary>
- internal static string OutOfRange(object? p0, object? p1) => SR.Format(SR.OutOfRange, p0, p1);
-
- /// <summary>
/// A string like "Cannot redefine label '{0}' in an inner block."
/// </summary>
internal static string LabelTargetAlreadyDefined(object? p0) => SR.Format(SR.LabelTargetAlreadyDefined, p0);
{
get
{
- if (index != 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
-
+ ArgumentOutOfRangeException.ThrowIfNotEqual(index, 0);
return _item;
}
set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
string typeName = MarshalToString(typeNameNative, nameof(typeNameNative));
string methodName = MarshalToString(methodNameNative, nameof(methodNameNative));
- if (reserved != IntPtr.Zero)
- {
- throw new ArgumentOutOfRangeException(nameof(reserved));
- }
-
+ ArgumentOutOfRangeException.ThrowIfNotEqual(reserved, IntPtr.Zero);
ArgumentNullException.ThrowIfNull(functionHandle);
// Set up the AssemblyLoadContext for this delegate.
{
string assemblyPath = MarshalToString(assemblyPathNative, nameof(assemblyPathNative));
- if (loadContext != IntPtr.Zero)
- {
- throw new ArgumentOutOfRangeException(nameof(loadContext));
- }
-
- if (reserved != IntPtr.Zero)
- {
- throw new ArgumentOutOfRangeException(nameof(reserved));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(loadContext, IntPtr.Zero);
+ ArgumentOutOfRangeException.ThrowIfNotEqual(reserved, IntPtr.Zero);
LoadAssemblyLocal(assemblyPath);
}
string typeName = MarshalToString(typeNameNative, nameof(typeNameNative));
string methodName = MarshalToString(methodNameNative, nameof(methodNameNative));
- if (loadContext != IntPtr.Zero)
- {
- throw new ArgumentOutOfRangeException(nameof(loadContext));
- }
-
- if (reserved != IntPtr.Zero)
- {
- throw new ArgumentOutOfRangeException(nameof(reserved));
- }
-
+ ArgumentOutOfRangeException.ThrowIfNotEqual(loadContext, IntPtr.Zero);
+ ArgumentOutOfRangeException.ThrowIfNotEqual(reserved, IntPtr.Zero);
ArgumentNullException.ThrowIfNull(functionHandle);
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
<value>Year must be between 1 and 9999.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeNonZero" xml:space="preserve">
- <value>'{0}' must be a non-zero value.</value>
+ <value>{0} ('{1}') must be a non-zero value.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeNonNegative" xml:space="preserve">
- <value>'{0}' must be a non-negative value.</value>
+ <value>{0} ('{1}') must be a non-negative value.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeNonNegativeNonZero" xml:space="preserve">
- <value>'{0}' must be a non-negative and non-zero value.</value>
+ <value>{0} ('{1}') must be a non-negative and non-zero value.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeLessOrEqual" xml:space="preserve">
- <value>'{0}' must be less than or equal to '{1}'.</value>
+ <value>{0} ('{1}') must be less than or equal to '{2}'.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeLess" xml:space="preserve">
- <value>'{0}' must be less than '{1}'.</value>
+ <value>{0} ('{1}') must be less than '{2}'.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeGreaterOrEqual" xml:space="preserve">
- <value>'{0}' must be greater than or equal to '{1}'.</value>
+ <value>{0} ('{1}') must be greater than or equal to '{2}'.</value>
</data>
<data name="ArgumentOutOfRange_Generic_MustBeGreater" xml:space="preserve">
- <value>'{0}' must be greater than '{1}'.</value>
+ <value>{0} ('{1}') must be greater than '{2}'.</value>
+ </data>
+ <data name="ArgumentOutOfRange_Generic_MustBeEqual" xml:space="preserve">
+ <value>{0} ('{1}') must be equal to '{2}'.</value>
+ </data>
+ <data name="ArgumentOutOfRange_Generic_MustBeNotEqual" xml:space="preserve">
+ <value>{0} ('{1}') must not be equal to '{2}'.</value>
</data>
<data name="Arithmetic_NaN" xml:space="preserve">
<value>Function does not accept floating point Not-a-Number values.</value>
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
+using System.Collections.Generic;
namespace System
{
public virtual object? ActualValue => _actualValue;
[DoesNotReturn]
- private static void ThrowZero<T>(string? paramName, T value)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonZero, paramName));
- }
+ private static void ThrowZero<T>(string? paramName, T value) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonZero, paramName, value));
[DoesNotReturn]
- private static void ThrowNegative<T>(string? paramName, T value)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegative, paramName));
- }
+ private static void ThrowNegative<T>(string? paramName, T value) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegative, paramName, value));
[DoesNotReturn]
- private static void ThrowNegativeOrZero<T>(string? paramName, T value)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegativeNonZero, paramName));
- }
+ private static void ThrowNegativeOrZero<T>(string? paramName, T value) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegativeNonZero, paramName, value));
[DoesNotReturn]
- private static void ThrowGreater<T>(string? paramName, T value, T other)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLessOrEqual, paramName, other));
- }
+ private static void ThrowGreater<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLessOrEqual, paramName, value, other));
[DoesNotReturn]
- private static void ThrowGreaterEqual<T>(string? paramName, T value, T other)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLess, paramName, other));
- }
+ private static void ThrowGreaterEqual<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLess, paramName, value, other));
[DoesNotReturn]
- private static void ThrowLess<T>(string? paramName, T value, T other)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreaterOrEqual, paramName, other));
- }
+ private static void ThrowLess<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreaterOrEqual, paramName, value, other));
[DoesNotReturn]
- private static void ThrowLessEqual<T>(string? paramName, T value, T other)
- {
- throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreater, paramName, other));
- }
+ private static void ThrowLessEqual<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreater, paramName, value, other));
+
+ [DoesNotReturn]
+ private static void ThrowEqual<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNotEqual, paramName, (object?)value ?? "null", (object?)other ?? "null"));
+
+ [DoesNotReturn]
+ private static void ThrowNotEqual<T>(string? paramName, T value, T other) =>
+ throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeEqual, paramName, (object?)value ?? "null", (object?)other ?? "null"));
/// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is zero.</summary>
/// <param name="value">The argument to validate as non-zero.</param>
ThrowNegativeOrZero(paramName, value);
}
+ /// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is equal to <paramref name="other"/>.</summary>
+ /// <param name="value">The argument to validate as not equal to <paramref name="other"/>.</param>
+ /// <param name="other">The value to compare with <paramref name="value"/>.</param>
+ /// <param name="paramName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
+ public static void ThrowIfEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) where T : IEquatable<T>?
+ {
+ if (EqualityComparer<T>.Default.Equals(value, other))
+ ThrowEqual(paramName, value, other);
+ }
+
+ /// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is not equal to <paramref name="other"/>.</summary>
+ /// <param name="value">The argument to validate as equal to <paramref name="other"/>.</param>
+ /// <param name="other">The value to compare with <paramref name="value"/>.</param>
+ /// <param name="paramName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
+ public static void ThrowIfNotEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) where T : IEquatable<T>?
+ {
+ if (!EqualityComparer<T>.Default.Equals(value, other))
+ ThrowNotEqual(paramName, value, other);
+ }
+
/// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is greater than <paramref name="other"/>.</summary>
/// <param name="value">The argument to validate as less or equal than <paramref name="other"/>.</param>
/// <param name="other">The value to compare with <paramref name="value"/>.</param>
ArgumentNullException.ThrowIfNull(uriParser);
ArgumentNullException.ThrowIfNull(schemeName);
- if (schemeName.Length == 1)
- throw new ArgumentOutOfRangeException(nameof(schemeName));
+ ArgumentOutOfRangeException.ThrowIfEqual(schemeName.Length, 1);
if (!Uri.CheckSchemeName(schemeName))
throw new ArgumentOutOfRangeException(nameof(schemeName));
- if ((defaultPort > 0xFFFF || defaultPort < 0) && defaultPort != -1)
+ if ((uint)defaultPort > 0xFFFF && defaultPort != -1)
throw new ArgumentOutOfRangeException(nameof(defaultPort));
schemeName = schemeName.ToLowerInvariant();
if (list != null)
return list[index];
- if (index != 0)
- throw new ArgumentOutOfRangeException(nameof(index));
+ ArgumentOutOfRangeException.ThrowIfNotEqual(index, 0);
return _field;
}
return;
}
- if (index != 0)
- throw new ArgumentOutOfRangeException(nameof(index));
+ ArgumentOutOfRangeException.ThrowIfNotEqual(index, 0);
_field = null;
}
{
if (_field == null)
{
- if (index != 0)
- throw new ArgumentOutOfRangeException(nameof(index));
+ ArgumentOutOfRangeException.ThrowIfNotEqual(index, 0);
Add(value);
return;
}
void ICollection.CopyTo(Array array, int index)
{
ArgumentNullException.ThrowIfNull(array);
-
ArgumentOutOfRangeException.ThrowIfNegative(index);
+
for (XmlSchemaCollectionEnumerator e = this.GetEnumerator(); e.MoveNext();)
{
- if (index == array.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
+ ArgumentOutOfRangeException.ThrowIfEqual(index, array.Length);
array.SetValue(e.Current, index++);
}
}
public void CopyTo(XmlSchema[] array, int index)
{
ArgumentNullException.ThrowIfNull(array);
-
ArgumentOutOfRangeException.ThrowIfNegative(index);
+
for (XmlSchemaCollectionEnumerator e = this.GetEnumerator(); e.MoveNext();)
{
XmlSchema? schema = e.Current;
if (schema != null)
{
- if (index == array.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
-
+ ArgumentOutOfRangeException.ThrowIfEqual(index, array.Length);
array[index++] = e.Current!;
}
}
public virtual object? ActualValue { get { throw null; } }
public override string Message { get { throw null; } }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
- public static void ThrowIfZero<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
- public static void ThrowIfNegative<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
- public static void ThrowIfNegativeOrZero<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
+ public static void ThrowIfEqual<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpression(nameof(value))] string? paramName = null) where T : System.IEquatable<T>? { throw null; }
public static void ThrowIfGreaterThan<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.IComparable<T> { throw null; }
public static void ThrowIfGreaterThanOrEqual<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.IComparable<T> { throw null; }
public static void ThrowIfLessThan<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.IComparable<T> { throw null; }
public static void ThrowIfLessThanOrEqual<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.IComparable<T> { throw null; }
+ public static void ThrowIfNegative<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
+ public static void ThrowIfNegativeOrZero<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
+ public static void ThrowIfNotEqual<T>(T value, T other, [System.Runtime.CompilerServices.CallerArgumentExpression(nameof(value))] string? paramName = null) where T : System.IEquatable<T>? { throw null; }
+ public static void ThrowIfZero<T>(T value, [System.Runtime.CompilerServices.CallerArgumentExpressionAttribute(nameof(value))] string? paramName = null) where T : System.Numerics.INumberBase<T> { throw null; }
}
public partial class ArithmeticException : System.SystemException
{
private static Action GreaterThanOrEqualHelper<T>(T value, T other) where T : IComparable<T> => () => ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(value, other);
private static Action LessThanHelper<T>(T value, T other) where T : IComparable<T> => () => ArgumentOutOfRangeException.ThrowIfLessThan(value, other);
private static Action LessThanOrEqualHelper<T>(T value, T other) where T : IComparable<T> => () => ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, other);
+ private static Action EqualHelper<T>(T value, T other) where T : IEquatable<T> => () => ArgumentOutOfRangeException.ThrowIfEqual(value, other);
+ private static Action NotEqualHelper<T>(T value, T other) where T : IEquatable<T> => () => ArgumentOutOfRangeException.ThrowIfNotEqual(value, other);
[Fact]
public static void GenericHelpers_ThrowIfZero_Throws()
Assert.Equal((double)0, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, ZeroHelper<double>(0)).ActualValue);
Assert.Equal(+0.0, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, ZeroHelper<double>(+0.0)).ActualValue);
Assert.Equal(-0.0, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, ZeroHelper<double>(-0.0)).ActualValue);
+
+ ZeroHelper(1)();
}
[Fact]
Assert.Equal(-1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NegativeOrZeroHelper<int>(-1)).ActualValue);
Assert.Equal(-0.0f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NegativeOrZeroHelper<float>(-0.0f)).ActualValue);
Assert.Equal(-0.0, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NegativeOrZeroHelper<double>(-0.0)).ActualValue);
+
+ NegativeOrZeroHelper(1)();
}
[Fact]
Assert.Equal(1u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanHelper<uint>(1, 0)).ActualValue);
Assert.Equal(1.000000001, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanHelper<double>(1.000000001, 1)).ActualValue);
Assert.Equal(1.00001f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanHelper<float>(1.00001f, 1)).ActualValue);
+
+ GreaterThanHelper(1, 2)();
}
[Fact]
Assert.Equal(1u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<uint>(1, 1)).ActualValue);
Assert.Equal((double)1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<double>(1, 1)).ActualValue);
Assert.Equal(1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<float>(1, 1)).ActualValue);
+
+ Assert.Equal(3, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<int>(3, 1)).ActualValue);
+ Assert.Equal(4u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<uint>(4, 1)).ActualValue);
+ Assert.Equal((double)1.1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<double>(1.1, 1)).ActualValue);
+ Assert.Equal(2.1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, GreaterThanOrEqualHelper<float>(2.1f, 1)).ActualValue);
+
+ GreaterThanOrEqualHelper(1, 2)();
}
[Fact]
Assert.Equal(0u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanHelper<uint>(0, 1)).ActualValue);
Assert.Equal((double)1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanHelper<double>(1, 1.000000001)).ActualValue);
Assert.Equal(1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanHelper<float>(1, 1.00001f)).ActualValue);
+
+ LessThanHelper(2, 1)();
}
[Fact]
public static void GenericHelpers_ThrowIfLessThanOrEqual_Throws()
{
+ Assert.Equal(-1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<int>(-1, 1)).ActualValue);
+ Assert.Equal(0u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<uint>(0, 1)).ActualValue);
+ Assert.Equal((double)0.9, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<double>(0.9, 1)).ActualValue);
+ Assert.Equal(-0.1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<float>(-0.1f, 1)).ActualValue);
+
Assert.Equal(1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<int>(1, 1)).ActualValue);
Assert.Equal(1u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<uint>(1, 1)).ActualValue);
Assert.Equal((double)1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<double>(1, 1)).ActualValue);
Assert.Equal(1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, LessThanOrEqualHelper<float>(1, 1)).ActualValue);
+
+ LessThanHelper(2, 1)();
+ }
+
+ [Fact]
+ public static void GenericHelpers_ThrowIfEqual_Throws()
+ {
+ Assert.Equal(1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, EqualHelper<int>(1, 1)).ActualValue);
+ Assert.Equal(1u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, EqualHelper<uint>(1, 1)).ActualValue);
+ Assert.Equal((double)1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, EqualHelper<double>(1, 1)).ActualValue);
+ Assert.Equal(1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, EqualHelper<float>(1, 1)).ActualValue);
+ Assert.Null(AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, EqualHelper<string>(null, null)).ActualValue);
+
+ EqualHelper(1, 2)();
+ EqualHelper("test1", "test2")();
+ EqualHelper("test1", null)();
+ EqualHelper(null, "test2")();
+ }
+
+ [Fact]
+ public static void GenericHelpers_ThrowIfNotEqual_Throws()
+ {
+ Assert.Equal(-1, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<int>(-1, 1)).ActualValue);
+ Assert.Equal(2u, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<uint>(2, 1)).ActualValue);
+ Assert.Equal((double)2, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<double>(2, 1)).ActualValue);
+ Assert.Equal(1f, AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<float>(1, 2)).ActualValue);
+ Assert.Equal("test", AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<string>("test", null)).ActualValue);
+ Assert.Null(AssertExtensions.Throws<ArgumentOutOfRangeException>(HelpersParamName, NotEqualHelper<string>(null, "test")).ActualValue);
+
+ NotEqualHelper(2, 2)();
+ NotEqualHelper("test", "test")();
}
}
}