Ports, schema and failing tests for the subscriber half of S-19b-2, ahead of the implementation. The subscriber now listens on the `objecten` kanaal instead of `zaken`. An Objecten notification carries no record data — only the object URL — so the record is read back through the ACL (§8.1), and the zaak-shaped surface goes away: IsZaakCreated / IsZaakStatusSet / ZaakUrl / ZaakId and ToEntry's `Resource == "status"` mapping are replaced by IsRegisterRecordWritten + ObjectUrl. The notification log now holds the projected row itself (register id, status, reference), so a rebuild is a replay with no mapping rules and no upstream reads. The migration drops the old columns rather than renaming them — EF scaffolded renames that would have carried ZGW values into columns meaning something else — and empties both tables, since a pre-slice row is neither reprojectable nor re-derivable from the new source. Red: HandleAsync recognises a register write but does not yet read or project it, so the seven projection assertions fail on an empty store.
58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
using EventSubscriber.Application;
|
|
|
|
namespace EventSubscriber.Tests;
|
|
|
|
/// <summary>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).</summary>
|
|
/// <summary>A fake ACL client standing in for the register records Objecten holds: a test seeds a
|
|
/// record per object URL, and the call count proves a rebuild does not re-read through the ACL.</summary>
|
|
internal sealed class FakeAclClient : IAclClient
|
|
{
|
|
public Dictionary<string, RegisterRecord> Records { get; } = [];
|
|
|
|
public int CallCount { get; private set; }
|
|
|
|
public Task<RegisterRecord?> GetRegisterRecordAsync(Uri objectUrl, CancellationToken ct = default)
|
|
{
|
|
CallCount++;
|
|
return Task.FromResult(Records.TryGetValue(objectUrl.ToString(), out var record) ? record : null);
|
|
}
|
|
}
|
|
|
|
internal sealed class InMemoryNotificationLog : INotificationLog
|
|
{
|
|
private readonly Dictionary<string, RecordedNotification> _byKey = [];
|
|
|
|
public Task<bool> TryRecordAsync(RecordedNotification notification, CancellationToken ct = default)
|
|
=> Task.FromResult(_byKey.TryAdd(notification.Key, notification));
|
|
|
|
public Task<IReadOnlyList<RecordedNotification>> AllAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<RecordedNotification>>([.. _byKey.Values]);
|
|
}
|
|
|
|
internal sealed class InMemoryProjectionStore : IProjectionStore
|
|
{
|
|
private readonly Dictionary<string, RegisterEntry> _byId = [];
|
|
|
|
/// <summary>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).</summary>
|
|
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<IReadOnlyList<RegisterEntry>> AllAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<RegisterEntry>>([.. _byId.Values]);
|
|
}
|