Shouldly.LanguageExt
0.2.0-beta.1
dotnet add package Shouldly.LanguageExt --version 0.2.0-beta.1
NuGet\Install-Package Shouldly.LanguageExt -Version 0.2.0-beta.1
<PackageReference Include="Shouldly.LanguageExt" Version="0.2.0-beta.1" />
<PackageVersion Include="Shouldly.LanguageExt" Version="0.2.0-beta.1" />
<PackageReference Include="Shouldly.LanguageExt" />
paket add Shouldly.LanguageExt --version 0.2.0-beta.1
#r "nuget: Shouldly.LanguageExt, 0.2.0-beta.1"
#:package Shouldly.LanguageExt@0.2.0-beta.1
#addin nuget:?package=Shouldly.LanguageExt&version=0.2.0-beta.1&prerelease
#tool nuget:?package=Shouldly.LanguageExt&version=0.2.0-beta.1&prerelease
Shouldly.LanguageExt
Shouldly assertion extensions for LanguageExt v5 (beta), returning the asserted value so assertions can be chained.
- Targets
LanguageExt.Core 5.0.0-beta-78,Shouldly 4.3.0andnet10.0. - See LanguageExt C# Functional Programming Language Extensions for more information about the functional programming base library.
- See Shouldly for more information about the extensive set of extension methods for unit tests.
NuGet
dotnet add package Shouldly.LanguageExt --prerelease
The 0.2.x line is published as a prerelease (0.2.0-beta.1) because it depends on the LanguageExt v5
beta, so --prerelease is needed to get it.
Package link: Shouldly.LanguageExt on NuGet
Supported types
| Type | Assertions |
|---|---|
Option<T> |
ShouldBeSome(), ShouldBeSome(expected), ShouldBeSome(action), ShouldBeNone() |
Either<TL, TR> |
ShouldBeLeft(), ShouldBeLeft(expected), ShouldBeLeft(action), ShouldBeRight(), ShouldBeRight(expected), ShouldBeRight(action) |
Validation<TF, TA> |
ShouldBeSuccess(), ShouldBeSuccess(expected), ShouldBeSuccess(action), ShouldBeFail(), ShouldBeFail(expected), ShouldBeFail(action) |
Fin<T> |
ShouldBeSucc(), ShouldBeSucc(expected), ShouldBeSucc(action), ShouldBeFail(), ShouldBeFail(error), ShouldBeFail(errorMessage), ShouldBeFail(action) |
Try<T> |
ShouldBeSucc(), ShouldBeSucc(expected), ShouldBeSucc(action), ShouldBeFail(), ShouldBeFail(error), ShouldBeFail(errorMessage), ShouldBeFail(action) |
IO<A> |
ShouldBeSucc(), ShouldBeSucc(expected), ShouldBeSucc(action), ShouldBeFail(), ShouldBeFail(error), ShouldBeFail(errorMessage), and the async equivalents ShouldBeSuccAsync(...) / ShouldBeFailAsync(...) |
Error |
ShouldHaveCode(code), ShouldHaveMessage(message), ShouldHaveException<TException>() |
The expected, error, errorMessage and action overloads, and the Error helpers, accept an
optional customMessage. The parameterless overloads intentionally do not: an optional string there
would make calls such as Some("a").ShouldBeSome("b") ambiguous.
Fluent results
The Succ/Fail/Some/Left/Right/Success assertions return the value they asserted on, so
the result can be used or asserted on directly:
using Shouldly.LanguageExt;
using LanguageExt;
using LanguageExt.Common;
Option<int> option = Prelude.Some(8);
Fin<int> fin = Fin.Succ(8);
Try<int> trying = Try.Succ(42);
Validation<int, string> validation = "abc";
option.ShouldBeSome().ShouldBe(8); // returns int
fin.ShouldBeSucc().ShouldBe(8); // returns int
trying.ShouldBeSucc().ShouldBe(42); // returns int
validation.ShouldBeSuccess().ShouldBe("abc"); // returns string
Fin<int> failed = Fin.Fail<int>(Error.New(404, "nf"));
failed.ShouldBeFail().Code.ShouldBe(404); // returns Error
Failure messages name the expected state and show the actual value. For example,
Option<int>.None.ShouldBeSome() fails with:
Option<int>.None
should be some
"Some"
but was
None
The first line is the expression from your test, which Shouldly reads from the source file.
Error helpers
ShouldBeFail() returns the Error, which can be inspected directly or through the Error
assertions:
Fin<int> failed = Fin.Fail<int>(Error.New(404, "nf"));
failed.ShouldBeFail().ShouldHaveCode(404);
failed.ShouldBeFail().ShouldHaveMessage("nf");
Try<int> throwing = Try.Fail<int>(Error.New(new InvalidOperationException("boom")));
throwing.ShouldBeFail()
.ShouldHaveException<InvalidOperationException>()
.Message.ShouldContain("boom");
IO
An IO<A> is executed exactly once. A thrown exception is treated as a failure, and
Error.New(exception) recovers the original Error (code and message) when the IO failed with an
Error:
IO<int> pure = IO.pure(1);
IO<int> failed = IO.fail<int>(Error.New(404, "nf"));
IO<int> throwing = IO.lift<int>(() => throw new InvalidOperationException("boom"));
pure.ShouldBeSucc().ShouldBe(1);
failed.ShouldBeFail().ShouldHaveCode(404);
throwing.ShouldBeFail().ShouldHaveException<InvalidOperationException>();
// Async
(await pure.ShouldBeSuccAsync()).ShouldBe(1);
(await failed.ShouldBeFailAsync()).ShouldHaveCode(404);
(await throwing.ShouldBeFailAsync()).ShouldHaveException<InvalidOperationException>();
Failure messages from the async assertions start with the actual value rather than your test's
expression, because Shouldly cannot locate the calling source line after an await.
Upgrading from 0.1.0
The assertion methods now return the asserted value instead of void. Recompile against 0.2.0;
assemblies built against 0.1.0 are not binary-compatible.
Most code keeps compiling unchanged. The exception is a lambda stored with var and then passed to
ShouldThrow/ShouldNotThrow: var now infers Func<T> instead of Action. Declare it as
Action, or pass the lambda inline:
// 0.1.0 — no longer compiles
var action = () => option.ShouldBeSome();
action.ShouldThrow<ShouldAssertException>();
// 0.2.0
Action action = () => option.ShouldBeSome();
action.ShouldThrow<ShouldAssertException>();
// or
Should.Throw<ShouldAssertException>(() => option.ShouldBeSome());
Examples
Option
using Shouldly.LanguageExt;
using LanguageExt;
var some = Prelude.Some(8);
var none = Option<int>.None;
some.ShouldBeSome();
some.ShouldBeSome(8);
some.ShouldBeSome(v => v.ShouldBe(8));
none.ShouldBeNone();
Either
using Shouldly.LanguageExt;
using LanguageExt;
Either<int, string> left = Prelude.Left(8);
Either<int, string> right = Prelude.Right("a");
left.ShouldBeLeft();
left.ShouldBeLeft(8);
left.ShouldBeLeft(l => l.ShouldBe(8));
right.ShouldBeRight();
right.ShouldBeRight("a");
right.ShouldBeRight(r => r.ShouldBe("a"));
Validation
using Shouldly.LanguageExt;
using LanguageExt;
Validation<int, string> success = "abc";
Validation<int, string> fail = 123;
success.ShouldBeSuccess();
success.ShouldBeSuccess("abc");
success.ShouldBeSuccess(v => v.ShouldBe("abc"));
fail.ShouldBeFail();
fail.ShouldBeFail(123);
fail.ShouldBeFail(err => err.ShouldBe(123));
Fin
using Shouldly.LanguageExt;
using LanguageExt;
using LanguageExt.Common;
Fin<int> successFin = Fin.Succ(8);
Fin<int> failedFin = Fin.Fail<int>("Error message");
successFin.ShouldBeSucc();
successFin.ShouldBeSucc(8);
successFin.ShouldBeSucc(v => v.ShouldBe(8));
failedFin.ShouldBeFail();
failedFin.ShouldBeFail("Error message");
failedFin.ShouldBeFail(Error.New("Error message"));
failedFin.ShouldBeFail(err => err.Message.ShouldBe("Error message"));
Try
using Shouldly.LanguageExt;
using LanguageExt;
using LanguageExt.Common;
Try<int> successTry = Try.Succ(42);
Try<int> failedTry = Try.Fail<int>(Error.New("Failed computation"));
successTry.ShouldBeSucc();
successTry.ShouldBeSucc(42);
successTry.ShouldBeSucc(v => v.ShouldBe(42));
failedTry.ShouldBeFail();
failedTry.ShouldBeFail("Failed computation");
failedTry.ShouldBeFail(Error.New("Failed computation"));
failedTry.ShouldBeFail(err => err.Message.ShouldBe("Failed computation"));
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- LanguageExt.Core (>= 5.0.0-beta-78)
- Shouldly (>= 4.3.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.0-beta.1 | 75 | 11/5/2026 |
| 0.1.0 | 162 | 8/4/2026 |
Fluent assertions that return the asserted value (Option, Either, Validation, Fin, Try), Error helpers (ShouldHaveCode, ShouldHaveMessage, ShouldHaveException) that chain from ShouldBeFail(), and new IO support with sync and async assertions. Targets LanguageExt.Core 5.0.0-beta-78. Breaking: assertions now return the asserted value instead of void, so recompile against this version; a lambda declared with 'var' and passed to ShouldThrow/ShouldNotThrow must now be declared as 'Action' (see README, "Upgrading from 0.1.0").