Table of Contents

Class UnwrapExtensions

Namespace
Trellis.Testing
Assembly
Trellis.Testing.dll

Provides Unwrap() extension methods for extracting values from Result<TValue> and Maybe<T> in test code. These methods throw a descriptive exception on failure/none rather than letting the test crash with an opaque error, keeping the test intent explicit.

public static class UnwrapExtensions
Inheritance
UnwrapExtensions
Inherited Members

Remarks

Intended for test code only. Do not use in production code — use pattern matching, Match, GetValueOrDefault, or other ROP operations instead.

Typical usage after a FluentAssertions guard:

result.Should().BeSuccess();
var value = result.Unwrap(); // Safe — we know it's a success

Methods

UnwrapAsync<T>(Task<Result<T>>)

Awaits the task and extracts the value from a successful result, or throws UnwrapFailedException with the error details if the result is a failure.

public static Task<T> UnwrapAsync<T>(this Task<Result<T>> resultTask)

Parameters

resultTask Task<Result<T>>

The task producing the result to unwrap.

Returns

Task<T>

The success value.

Type Parameters

T

Type of the result value.

Exceptions

UnwrapFailedException

Thrown when the result is a failure.

UnwrapAsync<T>(ValueTask<Result<T>>)

Awaits the value task and extracts the value from a successful result, or throws UnwrapFailedException with the error details if the result is a failure.

public static ValueTask<T> UnwrapAsync<T>(this ValueTask<Result<T>> resultTask)

Parameters

resultTask ValueTask<Result<T>>

The value task producing the result to unwrap.

Returns

ValueTask<T>

The success value.

Type Parameters

T

Type of the result value.

Exceptions

UnwrapFailedException

Thrown when the result is a failure.

UnwrapError(Result<Unit>)

Extracts the error from a failed no-payload Result<Unit>, or throws if success.

public static Error UnwrapError(this Result<Unit> result)

Parameters

result Result<Unit>

Returns

Error

UnwrapError<T>(Result<T>)

Extracts the error from a failed result, or throws UnwrapFailedException if the result is a success.

public static Error UnwrapError<T>(this Result<T> result)

Parameters

result Result<T>

The result to unwrap the error from.

Returns

Error

The error.

Type Parameters

T

Type of the result value.

Exceptions

UnwrapFailedException

Thrown when the result is a success.

Unwrap<T>(Maybe<T>)

Extracts the value from a Maybe that has a value, or throws UnwrapFailedException if the Maybe is None.

public static T Unwrap<T>(this Maybe<T> maybe) where T : notnull

Parameters

maybe Maybe<T>

The Maybe to unwrap.

Returns

T

The contained value.

Type Parameters

T

Type of the Maybe value.

Exceptions

UnwrapFailedException

Thrown when the Maybe is None.

Unwrap<T>(Result<T>)

Extracts the value from a successful result, or throws UnwrapFailedException with the error details if the result is a failure.

public static T Unwrap<T>(this Result<T> result)

Parameters

result Result<T>

The result to unwrap.

Returns

T

The success value.

Type Parameters

T

Type of the result value.

Exceptions

UnwrapFailedException

Thrown when the result is a failure.