ThomasW.Domain.SharedKernel.Results.FluentAssertions 0.2.2-alpha.0.1

This is a prerelease version of ThomasW.Domain.SharedKernel.Results.FluentAssertions.
dotnet add package ThomasW.Domain.SharedKernel.Results.FluentAssertions --version 0.2.2-alpha.0.1
NuGet\Install-Package ThomasW.Domain.SharedKernel.Results.FluentAssertions -Version 0.2.2-alpha.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ThomasW.Domain.SharedKernel.Results.FluentAssertions" Version="0.2.2-alpha.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ThomasW.Domain.SharedKernel.Results.FluentAssertions --version 0.2.2-alpha.0.1
#r "nuget: ThomasW.Domain.SharedKernel.Results.FluentAssertions, 0.2.2-alpha.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ThomasW.Domain.SharedKernel.Results.FluentAssertions as a Cake Addin
#addin nuget:?package=ThomasW.Domain.SharedKernel.Results.FluentAssertions&version=0.2.2-alpha.0.1&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.1&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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 703 12/3/2021
0.2.2-alpha.0 687 12/3/2021
0.2.1 757 12/3/2021
0.2.0 259 12/2/2021
0.2.0-beta.0.1 131 12/2/2021
0.2.0-alpha.0.2 132 12/2/2021