Skip to content

Commit

Permalink
Merge branch 'release/2.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
eoehen committed Dec 23, 2022
2 parents cbfa50f + 5cd0195 commit 961c22c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
42 changes: 42 additions & 0 deletions src/oehen.arguard.Tests/ArgumentNullGuardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,48 @@ namespace oehen.arguard
{
public class ArgumentNullGuardTest
{
enum TestEnum
{
None,
Gruen,
Blau
}

[Fact]
public void ThrowArgumentNullException_If_Enum_Is_Default()
{
TestEnum argument = default(TestEnum);

// ReSharper disable once ExpressionIsAlwaysNull
var result = argument.ThrowIfNull(nameof(argument));

result.Should().Be(argument);
}

[Fact]
public void ThrowArgumentNullException_If_Nullable_Enum_Is_Default()
{
TestEnum? argument = default(TestEnum);

// ReSharper disable once ExpressionIsAlwaysNull
var result = argument.ThrowIfNull(nameof(argument));

result.Should().Be(argument);
}

[Fact]
public void ThrowArgumentNullException_If_Nullable_Enum_Is_Null()
{
TestEnum? argument = null;

var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfNull(nameof(argument));
});
exception.Message.Should().Be("Value cannot be null. (Parameter 'argument')");
}

[Fact]
public void ThrowArgumentNullException_If_ObjectArgumentIsNull()
{
Expand Down
8 changes: 4 additions & 4 deletions src/oehen.arguard.Tests/oehen.arguard.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<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.2" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 2 additions & 1 deletion src/oehen.arguard/ArgumentNullGuard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace oehen.arguard
{
Expand All @@ -22,7 +23,7 @@ public static class ArgumentNullGuard
/// </example>
public static T ThrowIfNull<T>([ArgumentValidatedNotNull] this T argument, string nameOfArgument)
{
if (object.Equals(argument, default(T)))
if (!typeof(T).IsEnum && EqualityComparer<T>.Default.Equals(argument, default))
{
throw new ArgumentNullException(nameOfArgument);
}
Expand Down
2 changes: 1 addition & 1 deletion src/oehen.arguard/oehen.arguard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 961c22c

Please sign in to comment.