using Big.Application; using Big.Domain; namespace Big.Tests; public class SubmitRegistrationTests { [Fact] public async Task Submitting_persists_an_ingediend_registration_and_starts_the_process() { var store = new InMemoryRegistrationStore(); var workflow = new FakeWorkflowClient(processInstanceId: "proc-42"); var handler = new SubmitRegistration(store, workflow); var id = await handler.HandleAsync(new SubmitRegistrationCommand("123456782")); var saved = await store.GetAsync(id); Assert.NotNull(saved); Assert.Equal("123456782", saved.Bsn); Assert.Equal(RegistrationStatus.Ingediend, saved.Status); Assert.Equal("proc-42", saved.ProcessInstanceId); Assert.Equal(id, workflow.StartedFor); Assert.Null(saved.ZaakUrl); } [Fact] public async Task Submitting_persists_the_registration_before_starting_the_process() { // The worker correlates the OpenZaakAanmaken job back to the aggregate by id, so the // aggregate must already be persisted when the process starts (ADR-0009). var store = new InMemoryRegistrationStore(); Registration? visibleAtStart = null; var workflow = new FakeWorkflowClient(onStart: id => visibleAtStart = store.GetAsync(id).Result); var handler = new SubmitRegistration(store, workflow); await handler.HandleAsync(new SubmitRegistrationCommand("123456782")); Assert.NotNull(visibleAtStart); } [Fact] public async Task Submitting_without_a_bsn_is_rejected_and_starts_no_process() { var store = new InMemoryRegistrationStore(); var workflow = new FakeWorkflowClient(); var handler = new SubmitRegistration(store, workflow); await Assert.ThrowsAnyAsync( () => handler.HandleAsync(new SubmitRegistrationCommand(""))); Assert.Null(workflow.StartedFor); } }