Table of Contents

Class EnsureInspectExtensions

Namespace
Mokkit.Inspect
Assembly
Mokkit.dll

Ensure helpers for the Inspect phase. Because the source is already materialized during Inspect, these guard the value and capture it eagerly (synchronously) so later chained steps can consume the captured value directly. They apply to value scopes too, since Mokkit.Inspect.ITestInspectScope`1 derives from Mokkit.Inspect.ITestInspect.

public static class EnsureInspectExtensions

Inheritance

Inherited Members

Methods

Ensure<T>(ITestInspect, T, out T, string?)

Guards value as non-empty and captures it into captured for reuse in later chained inspect steps.

public static ITestInspect Ensure<T>(this ITestInspect inspect, T value, out T captured, string? because = null)

Parameters

inspect ITestInspect

The inspect chain.

value T

The already-materialized value (e.g. result.ClientId!.Value).

captured T

Receives the validated value.

because string?

Optional context appended to the failure message.

Returns

ITestInspect

The inspect chain for fluent chaining.

Type Parameters

T

The value type.

Exceptions

InvalidOperationException

Thrown when the value is empty.

Ensure<TSource, T>(ITestInspect, TSource, Func<TSource, T?>, out T, string?)

Projects a nullable value from source, guards that it has a non-empty value, and captures the unwrapped result — removing the !.Value noise for nullable-struct members (e.g. a Guid? id).

public static ITestInspect Ensure<TSource, T>(this ITestInspect inspect, TSource source, Func<TSource, T?> selector, out T captured, string? because = null) where T : struct

Parameters

inspect ITestInspect

The inspect chain.

source TSource

The source object to project from.

selector Func<TSource, T?>

Projects a nullable value from the source (e.g. r => r.ClientId).

captured T

Receives the unwrapped, validated value.

because string?

Optional context appended to the failure message.

Returns

ITestInspect

The inspect chain for fluent chaining.

Type Parameters

TSource

The source object type.

T

The unwrapped value type.

Exceptions

InvalidOperationException

Thrown when the projected value is null or empty.

Ensure<TSource, T>(ITestInspect, TSource, Func<TSource, T?>, out T, string?)

Reference-type counterpart of the nullable-struct overload: projects a possibly-null reference from source, guards it as non-empty, and captures it — so a name or an email threads on without a ! at the use site.

public static ITestInspect Ensure<TSource, T>(this ITestInspect inspect, TSource source, Func<TSource, T?> selector, out T captured, string? because = null) where T : class

Parameters

inspect ITestInspect

The inspect chain.

source TSource

The source object to project from.

selector Func<TSource, T?>

Projects a reference from the source (e.g. r => r.Name).

captured T

Receives the validated, non-null value.

because string?

Optional context appended to the failure message.

Returns

ITestInspect

The inspect chain for fluent chaining.

Type Parameters

TSource

The source object type.

T

The projected reference type.

Exceptions

InvalidOperationException

Thrown when the projected value is null or empty.

Ensure<TSource, T>(ITestInspect, ICapture<TSource>, Func<TSource, T>, out T, string?)

Projects a value off an already-filled Mokkit.ICapture`1, guards it as non-empty, and captures it. This is the capture-shaped sibling of the plain-source overloads — equivalent to .Ensure(client.Prop(c => c.Id), out var id), but it reports an uninitialized capture as its own failure rather than as an empty value. Works for both value and reference members.

public static ITestInspect Ensure<TSource, T>(this ITestInspect inspect, ICapture<TSource> source, Func<TSource, T> selector, out T captured, string? because = null)

Parameters

inspect ITestInspect

The inspect chain.

source ICapture<TSource>

The capture to read (must already be filled — Inspect runs after Arrange/Act).

selector Func<TSource, T>

Projects the value from the (non-null) captured value.

captured T

Receives the validated, non-empty value.

because string?

Optional context appended to the failure message.

Returns

ITestInspect

The inspect chain for fluent chaining.

Type Parameters

TSource

The captured type.

T

The projected value type.

Exceptions

InvalidOperationException

Thrown when the capture is not initialized, or when the projected value is empty.