Skip to content

Commit

Permalink
Merge branch 'release/2.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
eoehen committed Oct 1, 2022
2 parents 7308a67 + 28b63d7 commit f8fbe19
Show file tree
Hide file tree
Showing 27 changed files with 279 additions and 21 deletions.
40 changes: 40 additions & 0 deletions src/oehen.arguard.Tests/Between/ArgumentDecimalBetweenGuardTest.cs
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 src/oehen.arguard.Tests/Between/ArgumentIntBetweenGuardTest.cs
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 src/oehen.arguard.Tests/Between/ArgumentLongBetweenGuardTest.cs
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.Filesystem
{
public class ArgumentDirectoryPathGuardTest
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public void
Action act = () => argument.ThrowIfDirectoryNotExists(nameof(argument));
act.Should().NotThrow<DirectoryNotFoundException>();
}

[Fact]
public void
ArgumentDirectoryPathGuardTest_ThrowIfDirectoryNotExists_When_DirectoryPath_Exists_Then_Should_Return_ArgumentValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.Filesystem
{
public class ArgumentFilePathGuardTest
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public void
Action act = () => argument.ThrowIfFileNotExists(nameof(argument));
act.Should().NotThrow<FileNotFoundException>();
}

[Fact]
public void
ArgumentFilePathGuardTest_ThrowIfFileNotExists_When_FilePath_Exists_Then_Should_Return_ArgumentValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentDecimalLessOrEqualThanZeroGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentDecimalLessThanGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentDecimalLessThanZeroGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentIntLessOrEqualThanZeroGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentIntLessThanGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentIntLessThanZeroGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentLongLessOrEqualThanZeroGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentLongLessThanGuardTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Xunit;

namespace oehen.arguard
namespace oehen.arguard.LessThan
{
[UseCulture("en-US")]
public class ArgumentLongLessThanZeroGuardTest
Expand Down
2 changes: 1 addition & 1 deletion src/oehen.arguard.Tests/oehen.arguard.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
41 changes: 41 additions & 0 deletions src/oehen.arguard/Between/ArgumentDecimalBetweenGuard.cs
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;
}
}
}
41 changes: 41 additions & 0 deletions src/oehen.arguard/Between/ArgumentIntBetweenGuard.cs
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;
}
}
}
41 changes: 41 additions & 0 deletions src/oehen.arguard/Between/ArgumentLongBetweenGuard.cs
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;
}
}
}
Loading

0 comments on commit f8fbe19

Please sign in to comment.