LanguageExt.UnitTesting 3.4.0

dotnet add package LanguageExt.UnitTesting --version 3.4.0
NuGet\Install-Package LanguageExt.UnitTesting -Version 3.4.0
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="LanguageExt.UnitTesting" Version="3.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LanguageExt.UnitTesting --version 3.4.0
#r "nuget: LanguageExt.UnitTesting, 3.4.0"
#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 LanguageExt.UnitTesting as a Cake Addin
#addin nuget:?package=LanguageExt.UnitTesting&version=3.4.0

// Install LanguageExt.UnitTesting as a Cake Tool
#tool nuget:?package=LanguageExt.UnitTesting&version=3.4.0

LanguageExt.UnitTesting

Extension methods to simplify writing unit tests for code written using LanguageExt library. These extension methods throw an exception if expectation fails.

Avalable as LanguageExt.UnitTesting nuget package.

Option

  • ShouldBeSome<T>(Action<T> someValidation)
  • ShouldBeNone<T>()
Option<int> subject = UnitUnderTest();

// the following line throws an exception if subject is Option<int>.None 
// or the integer value wrapped by Some does not equal 5
subject.ShouldBeSome(some => Assert.Equal(5, some));

// the following line throws an exception if subject is Option<int>.None 
subject.ShouldBeSome();

// the following line throws an exception if subject is not Option<int>.None
subject.ShouldBeNone();

OptionAsync

  • ShouldBeSome<T>(Action<T> someValidation)
  • ShouldBeNone<T>()
OptionAsync<int> subject = UnitUnderTest();

// the following line throws an exception if subject is OptionAsync<int>.None 
// or the integer value wrapped by Some does not equal 5
await subject.ShouldBeSome(some => Assert.Equal(5, some));

// the following line throws an exception if subject is OptionAsync<int>.None 
await subject.ShouldBeSome();

// the following line throws an exception if subject is not OptionAsync<int>.None
await subject.ShouldBeNone();

Validation

  • ShouldBeSuccess<TFail, TSuccess>(Action<TSuccess> successValidation)
  • ShouldBeFail<TFail, TSuccess>(Action<IEnumerable<TFail>> failValidation)
Validation<string, int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure
// or in case of successful validation the integer value does not equal 5
subject.ShouldBeSuccess(success => Assert.Equal(5, success));

// the following line throws an exception if subject represents failure
subject.ShouldBeSuccess();

// the following line throws an exception if subject does not represent failed validation
// or in case of failed validation the failure value does not meet expectation
subject.ShouldBeFail(errors => Assert("value is not valid", errors.First()));

// the following line throws an exception if subject does not represent failed validation
subject.ShouldBeFail();

Fin

  • ShouldBeSuccess<TSuccess>(Action<TSuccess> successFin)
  • ShouldBeFail<TSuccess>(Action<Error> errFin)
Fin<int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure
// or in case of successful fin the integer value does not equal 5
subject.ShouldBeSuccess(success => Assert.Equal(5, success));

// the following line throws an exception if subject represents failure
subject.ShouldBeSuccess();

// the following line throws an exception if subject does not represent failure
// or in case of failed fin the failure value does not meet expectation
subject.ShouldBeFail(error => Assert("value is not valid", error.Message));

// the following line throws an exception if subject does not represent failed fin
subject.ShouldBeFail();

Either

  • ShouldBeRight<TLeft, TRight>(Action<TRight> rightValidation)
  • ShouldBeLeft<TLeft, TRight>(Action<TLeft> leftValidation)
Either<string, int> subject = UnitUnderTest();

// the following line throws an exception if subject represents left side of Either
// or in case of right side of Either when the integer value does not equal 5
subject.ShouldBeRight(right => Assert.Equal(5, right));

// the following line throws an exception if subject represents left side of Either
subject.ShouldBeRight();

// the following line throws an exception if subject represents right side of Either
// or in case of left side of Either when the string value does not equal "abcd"
subject.ShouldBeLeft(left => Assert.Equal("abcd", left));

// the following line throws an exception if subject represents right side of Either
subject.ShouldBeLeft();

EitherAsync

  • ShouldBeRight<TLeft, TRight>(Action<TRight> rightValidation)
  • ShouldBeLeft<TLeft, TRight>(Action<TLeft> leftValidation)
EitherAsync<string, int> subject = UnitUnderTest();

// the following line throws an exception if subject represents left side of Either
// or in case of right side of Either when the integer value does not equal 5
await subject.ShouldBeRight(right => Assert.Equal(5, right));

// the following line throws an exception if subject represents left side of Either
await subject.ShouldBeRight();

// the following line throws an exception if subject represents right side of Either
// or in case of left side of Either when the string value does not equal "abcd"
await subject.ShouldBeLeft(left => Assert.Equal("abcd", left));

// the following line throws an exception if subject represents right side of Either
await subject.ShouldBeLeft();

Try

  • ShouldBeSuccess<T>(Action<T> successValidation)
  • ShouldBeFail<T>(Action<Exception> failValidation)
Try<int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure
// or in case of successful try the integer value does not equal 5
subject.ShouldBeSuccess(success => Assert.Equal(5, success));

// the following line throws an exception if subject represents failure
subject.ShouldBeSuccess();

// the following line throws an exception if subject does not represent failure
// or in case of failure the exception has wrong message
subject.ShouldBeFail(ex => Assert.Equal("something went wrong", ex.Message));

// the following line throws an exception if subject does not represent failure
subject.ShouldBeFail();

TryAsync

  • ShouldBeSuccess<T>(Action<T> successValidation)
  • ShouldBeFail<T>(Action<Exception> failValidation)
TryAsync<int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure
// or in case of successful try the integer value does not equal 5
await subject.ShouldBeSuccess(success => Assert.Equal(5, success));

// the following line throws an exception if subject represents failure
await subject.ShouldBeSuccess();

// the following line throws an exception if subject does not represent failure
// or in case of failure the  exception has wrong message
await subject.ShouldBeFail(ex => Assert.Equal("something went wrong", ex.Message));

// the following line throws an exception if subject does not represent failure
await subject.ShouldBeFail();

TryOption

  • ShouldBeSome<T>(Action<T> someValidation)
  • ShouldBeNone<T>()
  • ShouldBeFail<T>(Action<Exception> failValidation)
TryOption<int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure or Option<T>.None
// or the integer value wrapped by Some does not equal 5
subject.ShouldBeSome(some => Assert.Equal(5, some));

// the following line throws an exception if subject represents failure or Option<T>.None
subject.ShouldBeSome(some => Assert.Equal(5, some));

// the following line throws an exception if subject is not Option<int>.None
subject.ShouldBeNone();

// the following line throws an exception if subject does not represent failure
// or in case of failure the exception has wrong message
subject.ShouldBeFail(ex => Assert.Equal("something went wrong", ex.Message));

// the following line throws an exception if subject does not represent failure
subject.ShouldBeFail();

TryOptionAsync

  • ShouldBeSome<T>(Action<T> someValidation)
  • ShouldBeNone<T>()
  • ShouldBeFail<T>(Action<Exception> failValidation)
TryOptionAsync<int> subject = UnitUnderTest();

// the following line throws an exception if subject represents failure or Option<T>.None
// or the integer value wrapped by Some does not equal 5
await subject.ShouldBeSome(some => Assert.Equal(5, some));

// the following line throws an exception if subject represents failure or Option<T>.None
await subject.ShouldBeSome();

// the following line throws an exception if subject is not Option<int>.None
await subject.ShouldBeNone();

// the following line throws an exception if subject does not represent failure
// or in case of failure the exception has wrong message
await subject.ShouldBeFail(ex => Assert.Equal("something went wrong", ex.Message));

// the following line throws an exception if subject does not represent failure
await subject.ShouldBeFail();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.4.0 53,997 4/20/2023
3.3.5 95,888 8/9/2019
3.1.14 33,372 12/15/2018
3.1.0 1,091 8/31/2018
3.0.22 1,975 8/20/2018
3.0.19 5,122 7/23/2018
2.1.0 771 7/22/2018
2.0.0 1,175 3/25/2018
1.0.0 1,187 3/24/2018

Adding Fin extenstion methods