Class FakeSharedResourceLoader<TResource, TId>
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
TResourceThe aggregate type.
TIdThe 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
repositoryFakeRepository<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
idTIdThe resource identifier.
cancellationTokenCancellationTokenCancellation token.