Home

Awesome

CSharpFunctionalExtensions.FluentAssertions

A small set of extensions to make test assertions more fluent when using CSharpFunctionalExtensions! Wow!

Star History

<a href="https://star-history.com/#NitroDevs/CSharpFunctionalExtensions.FluentAssertions&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=NitroDevs/CSharpFunctionalExtensions.FluentAssertions&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=NitroDevs/CSharpFunctionalExtensions.FluentAssertions&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=NitroDevs/CSharpFunctionalExtensions.FluentAssertions&type=Date" /> </picture> </a>

Learn More

Dependencies

This library is compatible with .NET 6+. It requires the following minimum package versions:

CSharpFunctionalExtensons >= 2.37.0

FluentAssertions >= 6.10.0

Installation

This library is available on Nuget and can be installed with the .NET CLI using the following command:

dotnet add package CSharpFunctionalExtensions.FluentAssertions

Usage

Maybe Assertions

var maybe = Maybe.From("foo");

maybe.Should().HaveSomeValue(); // passes
maybe.Should().HaveValue("foo"); // passes
maybe.Should().HaveValue("bar"); // throws
maybe.Should().HaveNoValue(); // throws
Maybe<string> maybe = null;

maybe.Should().HaveNoValue(); // passes
maybe.Should().HaveValue("foo"); // throws

Result Assertions

var result = Result.Success();

result.Should().Succeed(); // passes
result.Should().Fail() // throws
var result = Result.Failure("error");

result.Should().Fail() // passes
result.Should().FailWith("error"); // passes
result.Should().FailWith("some other error"); // throws
result.Should().Succeed(); // throws

Generic Result of T Assertions

var result = Result.Success(420);

result.Should().Succeed(); // passes
result.Should().SucceedWith(420); // passes
result.Should().SucceedWith(69); // throws
result.Should().Fail(); // throws
var result = Result.Failure<string>("error");

result.Should().Fail() // passes
result.Should().FailWith("error"); // passes
result.Should().FailWith("some other error"); // throws
result.Should().Succeed(); // throws

Generic Result of T:Value and E:Error Assertions

var result = Result.Success<int, Exception>(420);

result.Should().Succeed(); // passes
result.Should().SucceedWith(420); // passes
result.Should().SucceedWith(69); // throws
result.Should().Fail(); // throws
result.Should().FailWith(new Exception("error")); // throws
var result = Result.Failure<int, Exception>(new Exception("error"));

result.Should().Fail(); // passes
result.Should().FailWith(new Exception("error")); // passes
result.Should().FailWith(new Exception("some other error")); // throws
result.Should().Succeed(); // throws
result.Should().SucceedWith(4680); // throws

UnitResult Assertions

var result = UnitResult.Success<string>();

result.Should().Succeed(); // passes
result.Should().Fail(); // throws
result.Should().FailWith("error"); // throws
var result = UnitResult.Failure("error");

result.Should().Fail(); // passes
result.Should().FailWith("error"); // passes
result.Should().Succeed(); // throws

Related Projects

Acknowledgements

Special thanks to Sean Wright for all his guidance and contributions over the design, development, and release of this project. His insights are invaluable! :smile: