using EventSubscriber.Application;
namespace Acceptance.Support;
/// In-memory stand-ins for the Event Subscriber's projection store and notification
/// log, so the S-06 acceptance scenario runs without Postgres (real delivery is a live-stack
/// check). Mirrors the InMemoryZaakGateway approach used for the ACL scenario.
public sealed class InMemoryNotificationLog : INotificationLog
{
private readonly Dictionary _byKey = [];
public Task TryRecordAsync(RecordedNotification notification, CancellationToken ct = default)
=> Task.FromResult(_byKey.TryAdd(notification.Key, notification));
public Task> AllAsync(CancellationToken ct = default)
=> Task.FromResult>([.. _byKey.Values]);
}
public sealed class InMemoryProjectionStore : IProjectionStore
{
private readonly Dictionary _byId = [];
public Task UpsertAsync(RegisterEntry entry, CancellationToken ct = default)
{
_byId[entry.Id] = entry;
return Task.CompletedTask;
}
public Task ClearAsync(CancellationToken ct = default)
{
_byId.Clear();
return Task.CompletedTask;
}
public Task> AllAsync(CancellationToken ct = default)
=> Task.FromResult>([.. _byId.Values]);
public IReadOnlyList RowsFor(string id)
=> [.. _byId.Values.Where(e => e.Id == id)];
}
/// A fake ACL client for the projection acceptance scenario: returns a reference derived
/// from the zaak, so the projector can enrich rows without a running ACL (#78).
public sealed class InMemoryAclReferenceClient : IAclClient
{
public Task GetZaakReferenceAsync(Uri zaakUrl, CancellationToken ct = default)
=> Task.FromResult("REG-" + zaakUrl.Segments[^1].Trim('/'));
}