All checks were successful
CI / lint (pull_request) Successful in 1m15s
CI / build (pull_request) Successful in 1m1s
CI / unit (pull_request) Successful in 1m20s
CI / frontend (pull_request) Successful in 2m50s
CI / mutation (pull_request) Successful in 5m22s
CI / verify-stack (pull_request) Successful in 7m18s
verify-stack surfaced a Flowable 500: delivering messageEventReceived to the Beoordelen task's execution is wrong — a message boundary event's subscription lives on its own execution. Correlate instead by the registration's process instance id (recorded at submit): query the execution subscribed to RegistratieIngetrokken and deliver the message there. Withdrawal moves from IUserTaskClient to IWorkflowClient.WithdrawProcessAsync; the handler no longer needs a task lookup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
101 lines
3.8 KiB
C#
101 lines
3.8 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
public class WithdrawRegistrationTests
|
|
{
|
|
private static Registration Submitted(string processInstanceId = "proc-1")
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.RecordProcessStarted(processInstanceId);
|
|
return registration;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Withdrawing_marks_the_registration_ingetrokken_and_persists_it()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Submitted();
|
|
store.Seed(registration);
|
|
var handler = new WithdrawRegistration(store, new FakeWorkflowClient());
|
|
|
|
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
|
|
|
|
var saved = await store.GetAsync(registration.Id);
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, saved!.Status);
|
|
Assert.Equal(1, store.SaveCount);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Withdrawing_cancels_the_running_process()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Submitted("proc-42");
|
|
store.Seed(registration);
|
|
var workflow = new FakeWorkflowClient();
|
|
var handler = new WithdrawRegistration(store, workflow);
|
|
|
|
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
|
|
|
|
// The process the registration recorded at submit is cancelled (ADR-0014).
|
|
Assert.Equal("proc-42", workflow.WithdrawnProcessInstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Withdrawing_before_a_process_was_started_still_marks_ingetrokken()
|
|
{
|
|
// A registration with no recorded process (e.g. start never happened) can still be withdrawn;
|
|
// there is simply no process to cancel.
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Registration.Submit("123456782"); // no RecordProcessStarted
|
|
store.Seed(registration);
|
|
var workflow = new FakeWorkflowClient();
|
|
var handler = new WithdrawRegistration(store, workflow);
|
|
|
|
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
|
|
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, (await store.GetAsync(registration.Id))!.Status);
|
|
Assert.Null(workflow.WithdrawnProcessInstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Rejects_a_null_command_without_touching_the_store()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var handler = new WithdrawRegistration(store, new FakeWorkflowClient());
|
|
|
|
await Assert.ThrowsAsync<ArgumentNullException>(() => handler.HandleAsync(null!));
|
|
Assert.Equal(0, store.SaveCount);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Withdrawing_an_unknown_registration_throws()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var handler = new WithdrawRegistration(store, new FakeWorkflowClient());
|
|
|
|
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
|
|
() => handler.HandleAsync(new WithdrawRegistrationCommand(RegistrationId.New())));
|
|
Assert.Contains("No registration", ex.Message);
|
|
Assert.Equal(0, store.SaveCount);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Re_withdrawing_an_already_ingetrokken_registration_is_idempotent()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Submitted();
|
|
store.Seed(registration);
|
|
var workflow = new FakeWorkflowClient();
|
|
var handler = new WithdrawRegistration(store, workflow);
|
|
|
|
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
|
|
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
|
|
|
|
// The second withdrawal is a no-op: the aggregate is not persisted again.
|
|
Assert.Equal(1, store.SaveCount);
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, (await store.GetAsync(registration.Id))!.Status);
|
|
}
|
|
}
|