Skip to content

Commit

Permalink
feat(tests) Improve multitargetframework
Browse files Browse the repository at this point in the history
  • Loading branch information
eoehen committed Mar 8, 2024
1 parent 30165e3 commit 7e31369
Show file tree
Hide file tree
Showing 20 changed files with 1,025 additions and 879 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ jobs:
with:
dotnet-version: 6.x

- name: Setup .NET 8.x
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
with:
dotnet-version: 8.x

# Caching Tools
- name: Cache Tools
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ jobs:
with:
dotnet-version: 6.x

# Caching Tools
- name: Setup .NET 8.x
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4
with:
dotnet-version: 8.x

# Caching Tools
- name: Cache Tools
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
with:
Expand Down
141 changes: 80 additions & 61 deletions src/oehen.arguard.Tests/ArgumentEmtpyGuardTest.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,81 @@
using System;
using FluentAssertions;
using Xunit;

namespace oehen.arguard
{
[UseCulture("en-US")]
public class ArgumentEmtpyGuardTest
{
[Fact]
public void ThrowIfIsNullOrEmpty_ShouldThrowArgumentNullException_If_StringArgumentIsNullOrEmpty()
{
const string argument = "";
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrEmpty(nameof(argument));
});
exception.Message.Should().Be("Argument is null or empty. (Parameter 'argument')");
}

[Fact]
public void ThrowIfIsNullOrEmpty_ShouldNotThrowArgumentOutOfRangeException_IfArgumentIsStringValue()
{
const string argument = "not empty value";
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldThrowArgumentNullException_If_StringArgumentIsNull()
{
string argument = null;
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrWhiteSpace(nameof(argument));
});
exception.Message.Should().Be("Argument is null or whitespace. (Parameter 'argument')");
}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldThrowArgumentNullException_If_StringArgumentIsWhiteSpace()
{
const string argument = " ";
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrWhiteSpace(nameof(argument));
});
exception.Message.Should().Be("Argument is null or whitespace. (Parameter 'argument')");
}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldNotThrowArgumentOutOfRangeException_IfArgumentIsStringValue()
{
const string argument = "Hello";
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrWhiteSpace(nameof(argument)); });
Assert.Null(exception);
}
}
using System;
using FluentAssertions;
using Xunit;

namespace oehen.arguard
{
[UseCulture("en-US")]
public class ArgumentEmtpyGuardTest
{
[Fact]
public void ThrowIfIsNullOrEmpty_ShouldThrowArgumentNullException_If_StringArgumentIsNullOrEmpty()
{
const string argument = "";
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrEmpty(nameof(argument));
});

#if NET472
#elif NET48
exception.Message.Should().Be("Argument is null or empty.\r\nParameter name: argument");
#else
exception.Message.Should().Be("Argument is null or empty. (Parameter 'argument')");
#endif
}

[Fact]
public void ThrowIfIsNullOrEmpty_ShouldNotThrowArgumentOutOfRangeException_IfArgumentIsStringValue()
{
const string argument = "not empty value";
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldThrowArgumentNullException_If_StringArgumentIsNull()
{
string argument = null;
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrWhiteSpace(nameof(argument));
});

#if NET472
#elif NET48
exception.Message.Should().Be("Argument is null or whitespace.\r\nParameter name: argument");
#else
exception.Message.Should().Be("Argument is null or whitespace. (Parameter 'argument')");
#endif

}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldThrowArgumentNullException_If_StringArgumentIsWhiteSpace()
{
const string argument = " ";
var exception = Assert.Throws<ArgumentNullException>(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
argument.ThrowIfIsNullOrWhiteSpace(nameof(argument));
});

#if NET472
#elif NET48
exception.Message.Should().Be("Argument is null or whitespace.\r\nParameter name: argument");
#else
exception.Message.Should().Be("Argument is null or whitespace. (Parameter 'argument')");
#endif
}

[Fact]
public void ThrowIfIsNullOrWhiteSpace_ShouldNotThrowArgumentOutOfRangeException_IfArgumentIsStringValue()
{
const string argument = "Hello";
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrWhiteSpace(nameof(argument)); });
Assert.Null(exception);
}
}
}
143 changes: 74 additions & 69 deletions src/oehen.arguard.Tests/ArgumentEnumerableGuardTest.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,75 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Xunit;

namespace oehen.arguard
{
[UseCulture("en-US")]
public class ArgumentEnumerableGuardTest
{
[Fact]
public void ThrowArgumentNullException_If_IEnumerableIsEmpty()
{
IEnumerable<string> argument = new List<string>();
var exception = Assert.Throws<ArgumentNullException>(() =>
{
argument.ThrowIfIsNullOrEmpty(nameof(argument));
});
exception.Message.Should().Be("Argument is null or empty. (Parameter 'argument')");
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_One_Entry_Should_Not_Throw_ArgumentException()
{
IEnumerable<string> argument = new List<string>
{
"entry one"
};
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_One_Entry_Should_Return_ArgumentValue()
{
IEnumerable<string> argument = new List<string>
{
"entry one"
};
var result = argument.ThrowIfIsNullOrEmpty(nameof(argument));
result.Should().BeEquivalentTo(argument);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_Many_Entries_Should_Not_Throw_ArgumentException()
{
IEnumerable<string> argument = new List<string>
{
"entry one",
"entry two",
"entry three"
};
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_Many_Entries_Should_Return_ArgumentValue()
{
IEnumerable<string> argument = new List<string>
{
"entry one",
"entry two",
"entry three"
};
var result = argument.ThrowIfIsNullOrEmpty(nameof(argument));
result.Should().BeEquivalentTo(argument);
}
}
using System;
using System.Collections.Generic;
using FluentAssertions;
using Xunit;

namespace oehen.arguard
{
[UseCulture("en-US")]
public class ArgumentEnumerableGuardTest
{
[Fact]
public void ThrowArgumentNullException_If_IEnumerableIsEmpty()
{
IEnumerable<string> argument = new List<string>();
var exception = Assert.Throws<ArgumentNullException>(() =>
{
argument.ThrowIfIsNullOrEmpty(nameof(argument));
});
#if NET472
#elif NET48
exception.Message.Should().Be("Argument is null or empty.\r\nParameter name: argument");
#else
exception.Message.Should().Be("Argument is null or empty. (Parameter 'argument')");
#endif
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_One_Entry_Should_Not_Throw_ArgumentException()
{
IEnumerable<string> argument = new List<string>
{
"entry one"
};
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_One_Entry_Should_Return_ArgumentValue()
{
IEnumerable<string> argument = new List<string>
{
"entry one"
};
var result = argument.ThrowIfIsNullOrEmpty(nameof(argument));
result.Should().BeEquivalentTo(argument);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_Many_Entries_Should_Not_Throw_ArgumentException()
{
IEnumerable<string> argument = new List<string>
{
"entry one",
"entry two",
"entry three"
};
var exception = Record.Exception(() => { argument.ThrowIfIsNullOrEmpty(nameof(argument)); });
Assert.Null(exception);
}

[Fact]
public void ThrowIfIsNullOrEmpty_When_IEnumerable_Has_Many_Entries_Should_Return_ArgumentValue()
{
IEnumerable<string> argument = new List<string>
{
"entry one",
"entry two",
"entry three"
};
var result = argument.ThrowIfIsNullOrEmpty(nameof(argument));
result.Should().BeEquivalentTo(argument);
}
}
}
Loading

0 comments on commit 7e31369

Please sign in to comment.