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)];
}
/// An in-memory stand-in for the register the ACL reads back for the projector, so the
/// scenario runs without a running ACL or Objecten (S-19b-2, ADR-0030).
public sealed class InMemoryRegisterRecordClient : IAclClient
{
public Dictionary Records { get; } = [];
public Task GetRegisterRecordAsync(Uri objectUrl, CancellationToken ct = default)
=> Task.FromResult(Records.TryGetValue(objectUrl.ToString(), out var record) ? record : null);
}