using EventSubscriber.Application; namespace EventSubscriber.Tests; /// In-memory stand-ins for the projection store and notification log, so the /// projector's behaviour is exercised without Postgres (hand-written stubs, the repo's /// convention — no mocking library). /// A fake ACL client that returns a fixed reference derived from the zaak, and records /// how many times it was called (to prove a rebuild does not re-read via the ACL). internal sealed class FakeAclClient : IAclClient { public int CallCount { get; private set; } public Task GetZaakReferenceAsync(Uri zaakUrl, CancellationToken ct = default) { CallCount++; return Task.FromResult("REG-" + zaakUrl.Segments[^1].Trim('/')); } } internal 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]); } internal sealed class InMemoryProjectionStore : IProjectionStore { private readonly Dictionary _byId = []; /// How many times a write was attempted — lets a test prove a deduped delivery /// never reaches the store (an idempotent upsert hides the difference in row count alone). public int UpsertCount { get; private set; } public Task UpsertAsync(RegisterEntry entry, CancellationToken ct = default) { UpsertCount++; _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]); }