feat(event-subscriber): NRC event subscriber + rebuildable read projection (closes #7) #59

Merged
not merged 7 commits from feat/7-event-subscriber-projection into main 2026-06-30 13:57:00 +00:00
4 changed files with 59 additions and 18 deletions
Showing only changes of commit a111e5cc20 - Show all commits

View File

@@ -20,8 +20,13 @@ internal sealed class InMemoryProjectionStore : IProjectionStore
{ {
private readonly Dictionary<string, RegisterEntry> _byId = []; 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) public Task UpsertAsync(RegisterEntry entry, CancellationToken ct = default)
{ {
UpsertCount++;
_byId[entry.Id] = entry; _byId[entry.Id] = entry;
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@@ -38,32 +38,52 @@ public sealed class NotificationProjectorTests
} }
[Fact] [Fact]
public async Task a_notification_on_another_kanaal_is_ignored() public async Task a_replayed_notification_never_reaches_the_projection_store()
{
await Projector().HandleAsync(new Notification("documenten", "enkelvoudiginformatieobject", "create", new Uri(ZaakUrl)));
Assert.Empty(await _store.AllAsync());
}
[Fact]
public async Task a_zaak_update_is_ignored_by_the_minimal_projection()
{
await Projector().HandleAsync(new Notification("zaken", "zaak", "update", new Uri(ZaakUrl)));
Assert.Empty(await _store.AllAsync());
}
[Fact]
public async Task rebuild_repopulates_the_projection_from_the_notification_log()
{ {
var projector = Projector(); var projector = Projector();
await projector.HandleAsync(ZaakCreated()); await projector.HandleAsync(ZaakCreated());
await _store.ClearAsync(); await projector.HandleAsync(ZaakCreated());
// The duplicate is dropped at the log, before the (idempotent) upsert — so the store
// is written exactly once. Row count alone can't see this; the upsert count can.
Assert.Equal(1, _store.UpsertCount);
}
[Fact]
public async Task two_different_zaken_each_get_their_own_row()
{
var projector = Projector();
await projector.HandleAsync(ZaakCreated());
await projector.HandleAsync(ZaakCreated(ZaakUrl[..^1] + "2")); // a distinct zaak url
Assert.Equal(2, (await _store.AllAsync()).Count);
}
[Theory]
[InlineData("documenten", "enkelvoudiginformatieobject", "create")] // wrong kanaal + resource
[InlineData("documenten", "zaak", "create")] // wrong kanaal only
[InlineData("zaken", "status", "create")] // wrong resource only
[InlineData("zaken", "zaak", "update")] // wrong actie
[InlineData("zaken", "zaak", "destroy")] // wrong actie
public async Task only_a_zaken_zaak_create_notification_is_projected(string kanaal, string resource, string actie)
{
await Projector().HandleAsync(new Notification(kanaal, resource, actie, new Uri(ZaakUrl)));
Assert.Empty(await _store.AllAsync()); Assert.Empty(await _store.AllAsync());
}
[Fact]
public async Task rebuild_clears_stale_rows_and_repopulates_from_the_notification_log()
{
var projector = Projector();
await projector.HandleAsync(ZaakCreated());
// A stale row that is not backed by any logged notification must not survive a rebuild.
await _store.UpsertAsync(new RegisterEntry("stale-9999", RegistrationStatus.Ingediend));
await projector.RebuildAsync(); await projector.RebuildAsync();
var entry = Assert.Single(await _store.AllAsync()); var entry = Assert.Single(await _store.AllAsync());
Assert.Equal("11111111-1111-1111-1111-111111111111", entry.Id);
Assert.Equal(RegistrationStatus.Ingediend, entry.Status); Assert.Equal(RegistrationStatus.Ingediend, entry.Status);
} }
} }

View File

@@ -0,0 +1,4 @@
<Solution>
<Project Path="EventSubscriber.Application/EventSubscriber.Application.csproj" />
<Project Path="EventSubscriber.Tests/EventSubscriber.Tests.csproj" />
</Solution>

View File

@@ -0,0 +1,12 @@
{
"stryker-config": {
"solution": "EventSubscriber.slnx",
"test-projects": ["EventSubscriber.Tests/EventSubscriber.Tests.csproj"],
"reporters": ["progress", "html"],
"thresholds": {
"high": 95,
"low": 90,
"break": 90
}
}
}