New IRegistrationStore.FindDueForHerregistratieReminderAsync — the sweep's candidate set. The production store is stubbed to an empty list so the new test fails; the green commit filters on the aggregate's own reminder-due rule. refs #18
123 lines
4.3 KiB
C#
123 lines
4.3 KiB
C#
using Big.Domain;
|
|
using Big.Infrastructure;
|
|
|
|
namespace Big.Tests;
|
|
|
|
public class InMemoryRegistrationStoreTests
|
|
{
|
|
[Fact]
|
|
public async Task Saves_and_reads_back_a_registration_by_id()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
await store.SaveAsync(registration);
|
|
|
|
var loaded = await store.GetAsync(registration.Id);
|
|
Assert.NotNull(loaded);
|
|
Assert.Equal(registration.Id, loaded.Id);
|
|
Assert.Null(await store.GetAsync(RegistrationId.New()));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Saving_the_same_id_upserts()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
var registration = Registration.Submit("123456782");
|
|
await store.SaveAsync(registration);
|
|
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
await store.SaveAsync(registration);
|
|
|
|
var loaded = await store.GetAsync(registration.Id);
|
|
Assert.NotNull(loaded);
|
|
Assert.Equal("http://openzaak/zaken/api/v1/zaken/abc", loaded.ZaakUrl!.ToString());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Saving_a_null_registration_is_rejected()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
|
|
await Assert.ThrowsAsync<ArgumentNullException>(() => store.SaveAsync(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Finds_the_open_registration_for_a_bsn()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
var open = Registration.Submit("123456782");
|
|
await store.SaveAsync(open);
|
|
|
|
var found = await store.FindOpenByBsnAsync("123456782");
|
|
|
|
Assert.NotNull(found);
|
|
Assert.Equal(open.Id, found.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task An_in_behandeling_registration_is_still_open()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
var registration = Registration.Submit("123456782");
|
|
registration.TakeIntoBehandeling();
|
|
await store.SaveAsync(registration);
|
|
|
|
Assert.NotNull(await store.FindOpenByBsnAsync("123456782"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(nameof(Registration.Withdraw))]
|
|
[InlineData(nameof(Registration.Approve))]
|
|
[InlineData(nameof(Registration.Reject))]
|
|
[InlineData(nameof(Registration.Expire))]
|
|
public async Task A_terminal_registration_is_not_returned_as_open(string transition)
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); // Approve requires an opened zaak
|
|
switch (transition)
|
|
{
|
|
case nameof(Registration.Withdraw): registration.Withdraw(); break;
|
|
case nameof(Registration.Approve): registration.Approve(DateTimeOffset.UtcNow); break;
|
|
case nameof(Registration.Reject): registration.Reject(); break;
|
|
case nameof(Registration.Expire): registration.Expire(); break;
|
|
}
|
|
await store.SaveAsync(registration);
|
|
|
|
Assert.Null(await store.FindOpenByBsnAsync("123456782"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Does_not_return_another_bsns_registration_or_an_unknown_bsn()
|
|
{
|
|
var store = new InMemoryRegistrationStore();
|
|
await store.SaveAsync(Registration.Submit("111111110"));
|
|
|
|
Assert.Null(await store.FindOpenByBsnAsync("123456782"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Finds_only_the_inscriptions_due_for_a_herregistratie_reminder()
|
|
{
|
|
var now = new DateTimeOffset(2026, 7, 23, 0, 0, 0, TimeSpan.Zero);
|
|
var store = new InMemoryRegistrationStore();
|
|
|
|
var due = Registration.Submit("123456782");
|
|
due.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
due.Approve(now - Registration.HerregistratieGeldigheid + Registration.Herinneringstermijn);
|
|
await store.SaveAsync(due);
|
|
|
|
var freshlyInscribed = Registration.Submit("111111110");
|
|
freshlyInscribed.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/def"));
|
|
freshlyInscribed.Approve(now);
|
|
await store.SaveAsync(freshlyInscribed);
|
|
|
|
await store.SaveAsync(Registration.Submit("222222222")); // still INGEDIEND — never inscribed
|
|
|
|
var result = await store.FindDueForHerregistratieReminderAsync(now);
|
|
|
|
Assert.Equal([due.Id], result.Select(r => r.Id).ToArray());
|
|
}
|
|
}
|