ThomasW.Domain.SharedKernel.Results.FluentAssertions
0.2.2-alpha.0
See the version list below for details.
dotnet add package ThomasW.Domain.SharedKernel.Results.FluentAssertions --version 0.2.2-alpha.0
NuGet\Install-Package ThomasW.Domain.SharedKernel.Results.FluentAssertions -Version 0.2.2-alpha.0
<PackageReference Include="ThomasW.Domain.SharedKernel.Results.FluentAssertions" Version="0.2.2-alpha.0" />
paket add ThomasW.Domain.SharedKernel.Results.FluentAssertions --version 0.2.2-alpha.0
#r "nuget: ThomasW.Domain.SharedKernel.Results.FluentAssertions, 0.2.2-alpha.0"
// Install ThomasW.Domain.SharedKernel.Results.FluentAssertions as a Cake Addin
#addin nuget:?package=ThomasW.Domain.SharedKernel.Results.FluentAssertions&version=0.2.2-alpha.0&prerelease
// Install ThomasW.Domain.SharedKernel.Results.FluentAssertions as a Cake Tool
#tool nuget:?package=ThomasW.Domain.SharedKernel.Results.FluentAssertions&version=0.2.2-alpha.0&prerelease
ThomasW.Domain.SharedKernel.Results.FluentAssertions
FluentAssertions extensions for ThomasW.Domain.SharedKernel.Results.
Installation
This package can be installed via NuGet.
Usage
The package currently provides two assertion methods, BeSuccessful
and
BeFailed
, for both typed and non-typed results.
Simple checks on the success of a result can be made by using the methods with no arguments:
public async Task GetUser_ValidId_ReturnsUser()
{
// Arrange Act
Result<User> result = await this._sut.GetUser(this._userId);
// Assert
result.Should().BeSuccessful();
}
public async Task GetUser_InvalidId_ReturnsUser()
{
// Arrange Act
Result<User> result = await this._sut.GetUser(Guid.NewGuid());
// Assert
result.Should().BeFailed();
}
If you want to assert on the value of a successful result, you can pass a
predicate into the method. The assertion will only pass if the result is
successful and the predicate evaluates to true
:
public async Task GetUser_ValidId_ReturnsUser()
{
// Arrange Act
Result<User> result = await this._sut.GetUser(this._userId);
// Assert
result.Should().BeSuccessful(user => user.Id == this._userId);
}
You can also assert on the failure reason by passing a type argument into the
IsFailed
method:
public async Task GetUser_InvalidId_ReturnsUser()
{
// Arrange Act
Result<User> result = await this._sut.GetUser(Guid.NewGuid());
// Assert
result.Should().BeFailed<EntityNotFoundFailure>();
}
This assertion will only pass if the result is failed and the failure reason matches the passed-in type.
Furthermore, you can pass a predicate into the IsFailed
method, as well as
the type parameter, to assert against the FailureReason
object itself:
public async Task GetUser_InvalidId_ReturnsUser()
{
// Arrange Act
Result<User> result = await this._sut.GetUser(Guid.NewGuid());
// Assert
result.Should().BeFailed<EntityNotFoundFailure>(
reason => reason.Message == "User not found");
}
The above assertion will only pass if the result is failed, the failure reason
matches the passed-in type and the predicate evaluates to true
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- FluentAssertions (>= 6.2.0)
- ThomasW.Domain.SharedKernel.Results (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.2.2-alpha.0.1 | 705 | 12/3/2021 |
0.2.2-alpha.0 | 688 | 12/3/2021 |
0.2.1 | 760 | 12/3/2021 |
0.2.0 | 260 | 12/2/2021 |
0.2.0-beta.0.1 | 132 | 12/2/2021 |
0.2.0-alpha.0.2 | 133 | 12/2/2021 |