-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
279 additions
and
21 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/oehen.arguard.Tests/Between/ArgumentDecimalBetweenGuardTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
[UseCulture("en-US")] | ||
public class ArgumentDecimalBetweenGuardTest | ||
{ | ||
[Theory] | ||
[InlineData(4, 3, 8)] | ||
[InlineData(5, 3, 8)] | ||
[InlineData(7, 3, 8)] | ||
public void | ||
Decimal_ThrowIfIsBetween_Should_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value(decimal argument, decimal compareValueStart, decimal compareValueEnd) | ||
{ | ||
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
exception.Message.Should().Be($"Argument is between {compareValueStart} and {compareValueEnd}. (Parameter 'argument')" + | ||
Environment.NewLine + $"Actual value was {argument}."); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, 3, 8)] | ||
[InlineData(1, 3, 8)] | ||
[InlineData(9, 3, 8)] | ||
[InlineData(10, 3, 8)] | ||
public void | ||
Decimal_ThrowIfIsBetween_Should_Not_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value(decimal argument, decimal compareValueStart, decimal compareValueEnd) | ||
{ | ||
var exception = Record.Exception(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
Assert.Null(exception); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/oehen.arguard.Tests/Between/ArgumentIntBetweenGuardTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
[UseCulture("en-US")] | ||
public class ArgumentIntBetweenGuardTest | ||
{ | ||
[Theory] | ||
[InlineData(4, 3, 8)] | ||
[InlineData(5, 3, 8)] | ||
[InlineData(7, 3, 8)] | ||
public void | ||
Int_ThrowIfIsBetween_Should_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value( | ||
int argument, int compareValueStart, int compareValueEnd) | ||
{ | ||
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
exception.Message.Should().Be($"Argument is between {compareValueStart} and {compareValueEnd}. (Parameter 'argument')" + | ||
Environment.NewLine + $"Actual value was {argument}."); | ||
} | ||
[Theory] | ||
[InlineData(2, 3, 8)] | ||
[InlineData(1, 3, 8)] | ||
[InlineData(9, 3, 8)] | ||
[InlineData(10, 3, 8)] | ||
public void | ||
Int_ThrowIfIsBetween_Should_Not_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value(int argument, int compareValueStart, int compareValueEnd) | ||
{ | ||
var exception = Record.Exception(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
Assert.Null(exception); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/oehen.arguard.Tests/Between/ArgumentLongBetweenGuardTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
[UseCulture("en-US")] | ||
public class ArgumentLongBetweenGuardTest | ||
{ | ||
[Theory] | ||
[InlineData(4, 3, 8)] | ||
[InlineData(5, 3, 8)] | ||
[InlineData(7, 3, 8)] | ||
public void | ||
Long_ThrowIfIsBetween_Should_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value(long argument, long compareValueStart, long compareValueEnd) | ||
{ | ||
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
exception.Message.Should().Be($"Argument is between {compareValueStart} and {compareValueEnd}. (Parameter 'argument')" + | ||
Environment.NewLine + $"Actual value was {argument}."); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, 3, 8)] | ||
[InlineData(1, 3, 8)] | ||
[InlineData(9, 3, 8)] | ||
[InlineData(10, 3, 8)] | ||
public void | ||
Long_ThrowIfIsBetween_Should_Not_Throw_Exception_When_Argument_Is_Between_Start_And_End_Value(long argument, long compareValueStart, long compareValueEnd) | ||
{ | ||
var exception = Record.Exception(() => | ||
{ | ||
argument.ThrowIfIsBetween(compareValueStart, compareValueEnd, nameof(argument)); | ||
}); | ||
Assert.Null(exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
/// <summary> | ||
/// <see cref="decimal" /> argument between validator. | ||
/// </summary> | ||
public static class ArgumentDecimalBetweenGuard | ||
{ | ||
/// <summary> | ||
/// Throws an <see cref="ArgumentOutOfRangeException" /> exception if the <paramref name="argument" /> is between | ||
/// <paramref name="compareValueStart" /> and <paramref name="compareValueEnd"/>. | ||
/// </summary> | ||
/// <param name="argument">Argument value.</param> | ||
/// <param name="compareValueStart">Start range to compare.</param> | ||
/// <param name="compareValueEnd">End range to compare.</param> | ||
/// <param name="nameOfArgument">Name of the argument.</param> | ||
/// <example> | ||
/// <para>Throws when the argument `decimalArgument` is between 5 and 10.</para> | ||
/// <code> | ||
/// <![CDATA[ | ||
/// var localVar = decimalArgument.ThrowIfIsBetween(5, 10, nameof(intArgument)); | ||
/// ]]> | ||
/// </code> | ||
/// </example> | ||
public static decimal ThrowIfIsBetween(this decimal argument, decimal compareValueStart, decimal compareValueEnd, string nameOfArgument) | ||
{ | ||
if (argument > compareValueStart && argument < compareValueEnd) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameOfArgument, | ||
argument, | ||
string.Format(CultureInfo.CurrentCulture, | ||
ArgumentExceptionMessageResourceManager.GetMessage("ThrowIfIsBetween"), | ||
compareValueStart, compareValueEnd)); | ||
} | ||
return argument; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
/// <summary> | ||
/// <see cref="int" /> argument between validator. | ||
/// </summary> | ||
public static class ArgumentIntBetweenGuard | ||
{ | ||
/// <summary> | ||
/// Throws an <see cref="ArgumentOutOfRangeException" /> exception if the <paramref name="argument" /> is between | ||
/// <paramref name="compareValueStart" /> and <paramref name="compareValueEnd"/>. | ||
/// </summary> | ||
/// <param name="argument">Argument value.</param> | ||
/// <param name="compareValueStart">Start range to compare.</param> | ||
/// <param name="compareValueEnd">End range to compare.</param> | ||
/// <param name="nameOfArgument">Name of the argument.</param> | ||
/// <example> | ||
/// <para>Throws when the argument `intArgument` is between 5 and 10.</para> | ||
/// <code> | ||
/// <![CDATA[ | ||
/// var localVar = intArgument.ThrowIfIsBetween(5, 10, nameof(intArgument)); | ||
/// ]]> | ||
/// </code> | ||
/// </example> | ||
public static int ThrowIfIsBetween(this int argument, int compareValueStart, int compareValueEnd, string nameOfArgument) | ||
{ | ||
if (argument > compareValueStart && argument < compareValueEnd) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameOfArgument, | ||
argument, | ||
string.Format(CultureInfo.CurrentCulture, | ||
ArgumentExceptionMessageResourceManager.GetMessage("ThrowIfIsBetween"), | ||
compareValueStart, compareValueEnd)); | ||
} | ||
return argument; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace oehen.arguard.Between | ||
{ | ||
/// <summary> | ||
/// <see cref="long" /> argument between validator. | ||
/// </summary> | ||
public static class ArgumentLongBetweenGuard | ||
{ | ||
/// <summary> | ||
/// Throws an <see cref="ArgumentOutOfRangeException" /> exception if the <paramref name="argument" /> is between | ||
/// <paramref name="compareValueStart" /> and <paramref name="compareValueEnd"/>. | ||
/// </summary> | ||
/// <param name="argument">Argument value.</param> | ||
/// <param name="compareValueStart">Start range to compare.</param> | ||
/// <param name="compareValueEnd">End range to compare.</param> | ||
/// <param name="nameOfArgument">Name of the argument.</param> | ||
/// <example> | ||
/// <para>Throws when the argument `longArgument` is between 5 and 10.</para> | ||
/// <code> | ||
/// <![CDATA[ | ||
/// var localVar = longArgument.ThrowIfIsBetween(5, 10, nameof(intArgument)); | ||
/// ]]> | ||
/// </code> | ||
/// </example> | ||
public static long ThrowIfIsBetween(this long argument, long compareValueStart, long compareValueEnd, string nameOfArgument) | ||
{ | ||
if (argument > compareValueStart && argument < compareValueEnd) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameOfArgument, | ||
argument, | ||
string.Format(CultureInfo.CurrentCulture, | ||
ArgumentExceptionMessageResourceManager.GetMessage("ThrowIfIsBetween"), | ||
compareValueStart, compareValueEnd)); | ||
} | ||
return argument; | ||
} | ||
} | ||
} |
Oops, something went wrong.