Announcing the CSharpFunctionalExtensions.FluentAssertions library

Version 1.0.0 of CSharpFunctionalExtensions.FluentAssertions is now available on NuGet! This package enables developers to increase the readability of their tests by providing a more fluent way to write assertions based on common types such as Maybe<T> and Result from the CSharpFunctionalExtensions library.

An Example from CSharpFunctionalExtensions.FluentAssertions

Let's take a look at what a xUnit test method with an assertion on a Maybe<T> object might look like first without and then with this new library.

[Fact]
public void MaybeShouldHaveValue()
{
  int value = 4680;
  var maybe = Maybe.From(value);

  maybe.Value.Should().NotBeNull();
  maybe.Value.Should().Be(value); 
}

With the reference to the CSharpFunctionalExtensions.FluentAssertions library, the assertion of the test method can be changed to the following.

maybe.Should().HaveSomeValue();
maybe.Should().HaveValue(value);

You can check out other sample usages of the CSharpFunctionalExtensions.FluentAssertions library in the Usage section of the project's readme. The library contains FluentAssertion extensions for Maybe<T>, Result, Result<T>, Result<T, E>, and UnitResult<E> types.

Closing Remarks

This package was motivated by some of the tests I have been writing for payroll processor as I refactor that codebase from LanguageExt to CSharpFunctionalExtensions. This project's success should also be strongly attributed to the contributions by Sean Wright](https://twitter.com/seangwright) for helping me through the process of publishing a NuGet package for the first time and establishing an automated deployment pipeline with the ability to generate a preview package easily. Give him a follow on Twitter! I'd also like to thank Giovanni Costagliola for being the first community contributor to this project.

Resources