Table of Contents

Class FakeSharedResourceLoader<TResource, TId>

Namespace
Trellis.Testing.Fakes
Assembly
Trellis.Testing.dll

In-memory fake implementation of SharedResourceLoaderById<TResource, TId> that delegates to a FakeRepository<TAggregate, TId>. Use in application-layer tests to wire resource-based authorization without hand-writing a loader per command.

public class FakeSharedResourceLoader<TResource, TId> : SharedResourceLoaderById<TResource, TId> where TResource : Aggregate<TId> where TId : notnull

Type Parameters

TResource

The aggregate type.

TId

The aggregate ID type.

Inheritance
SharedResourceLoaderById<TResource, TId>
FakeSharedResourceLoader<TResource, TId>
Inherited Members
Extension Methods

Examples

var repo = new FakeRepository<Order, OrderId>();
var loader = new FakeSharedResourceLoader<Order, OrderId>(repo);

// Register in test DI:
services.AddScoped<FakeRepository<Order, OrderId>>();
services.AddScoped<SharedResourceLoaderById<Order, OrderId>, FakeSharedResourceLoader<Order, OrderId>>();

Constructors

FakeSharedResourceLoader(FakeRepository<TResource, TId>)

Creates a new fake shared resource loader backed by the specified repository.

public FakeSharedResourceLoader(FakeRepository<TResource, TId> repository)

Parameters

repository FakeRepository<TResource, TId>

The fake repository to delegate lookups to.

Methods

GetByIdAsync(TId, CancellationToken)

Loads the resource by ID. Return Result.Failure with a NotFoundError if the resource does not exist.

public override Task<Result<TResource>> GetByIdAsync(TId id, CancellationToken cancellationToken)

Parameters

id TId

The resource identifier.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<TResource>>

A success result containing the loaded resource, or a failure result if not found.