Table of Contents

Class AggregateTestMutator

Namespace
Trellis.Testing
Assembly
Trellis.Testing.dll

Reflection-based helpers for setting source-generated Maybe<T> backing fields in test scenarios. Works on the CLR object directly — no DbContext needed for the mutation itself.

public static class AggregateTestMutator
Inheritance
AggregateTestMutator
Inherited Members

Remarks

Use in integration tests to backdate time-dependent properties (e.g., SubmittedAt) without raw SQL. Also usable in unit tests with FakeRepository<TAggregate, TId>.

These helpers are test-only. Do NOT use in production code.

Methods

ClearMaybeField<TEntity, TValue>(TEntity, Expression<Func<TEntity, Maybe<TValue>>>)

Clears a Maybe<T> property's backing field to null (equivalent to None).

[RequiresUnreferencedCode("Uses reflection to set source-generated backing fields. Not AOT-compatible — test-only.")]
public static TEntity ClearMaybeField<TEntity, TValue>(this TEntity entity, Expression<Func<TEntity, Maybe<TValue>>> propertySelector) where TEntity : class where TValue : notnull

Parameters

entity TEntity

The entity to mutate.

propertySelector Expression<Func<TEntity, Maybe<TValue>>>

A lambda selecting the Maybe<T> property.

Returns

TEntity

The same entity for fluent chaining.

Type Parameters

TEntity

The entity type.

TValue

The inner value type of the Maybe.

SetMaybeField<TEntity, TValue>(TEntity, Expression<Func<TEntity, Maybe<TValue>>>, TValue?)

Sets the source-generated backing field of a Maybe<T> property via reflection. Returns the entity for fluent chaining.

[RequiresUnreferencedCode("Uses reflection to set source-generated backing fields. Not AOT-compatible — test-only.")]
public static TEntity SetMaybeField<TEntity, TValue>(this TEntity entity, Expression<Func<TEntity, Maybe<TValue>>> propertySelector, TValue? value) where TEntity : class where TValue : notnull

Parameters

entity TEntity

The entity to mutate.

propertySelector Expression<Func<TEntity, Maybe<TValue>>>

A lambda selecting the Maybe<T> property (e.g., o => o.SubmittedAt).

value TValue

The value to set, or null to set to None.

Returns

TEntity

The same entity for fluent chaining.

Type Parameters

TEntity

The entity type.

TValue

The inner value type of the Maybe.

Examples

order.SetMaybeField(o => o.SubmittedAt, DateTime.UtcNow.AddDays(-8))
     .SetMaybeField(o => o.ShippedAt, DateTime.UtcNow.AddDays(-5));