Skip to content

Repository files navigation

CSharpFunctionalExtensions.FluentAssertions

  • NuGet PackageCSharpFunctionalExtensions.FluentAssertions

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

Star History

Star History Chart

Learn More

Dependencies

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

CSharpFunctionalExtensons >= 3.0.0

FluentAssertions >= 7.2.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

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

Result Assertions

varresult=Result.Success();result.Should().Succeed();// passesresult.Should().Fail()// throws
varresult=Result.Failure("error");result.Should().Fail()// passes
result.Should().FailWith("error");// passesresult.Should().FailWith("some other error");// throwsresult.Should().Succeed();// throws

Generic Result of T Assertions

varresult=Result.Success(420);result.Should().Succeed();// passesresult.Should().SucceedWith(420);// passesresult.Should().SucceedWith(69);// throwsresult.Should().Fail();// throws
varresult=Result.Failure<string>("error");result.Should().Fail()// passes
result.Should().FailWith("error");// passesresult.Should().FailWith("some other error");// throwsresult.Should().Succeed();// throws

Generic Result of T:Value and E:Error Assertions

varresult=Result.Success<int,Exception>(420);result.Should().Succeed();// passesresult.Should().SucceedWith(420);// passesresult.Should().SucceedWith(69);// throwsresult.Should().Fail();// throwsresult.Should().FailWith(newException("error"));// throws
varresult=Result.Failure<int,Exception>(newException("error"));result.Should().Fail();// passesresult.Should().FailWith(newException("error"));// passesresult.Should().FailWith(newException("some other error"));// throwsresult.Should().Succeed();// throwsresult.Should().SucceedWith(4680);// throws

UnitResult Assertions

varresult=UnitResult.Success<string>();result.Should().Succeed();// passesresult.Should().Fail();// throwsresult.Should().FailWith("error");// throws
varresult=UnitResult.Failure("error");result.Should().Fail();// passesresult.Should().FailWith("error");// passesresult.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! 😄

About

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

Topics

Resources

Code of conduct

Stars

25 stars

Watchers

5 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages