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 returning the raw .Value, which avoids TRLS003 warnings in test projects.

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.

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.