using Acceptance.Support; using EventSubscriber.Application; using Reqnroll; using Xunit; namespace Acceptance.Steps; /// Bindings for RegisterProjectieBijwerken.feature (S-06, re-sourced by S-19b-2). /// Reqnroll creates one instance per scenario, so instance fields hold scenario-scoped state. [Binding] public sealed class RegisterProjectieBijwerkenSteps { private const string ObjectBase = "http://objecten.local:8000/api/v2/objects/"; private readonly InMemoryNotificationLog _log = new(); private readonly InMemoryProjectionStore _store = new(); private readonly InMemoryRegisterRecordClient _register = new(); private readonly NotificationProjector _projector; private Notification? _notification; public RegisterProjectieBijwerkenSteps() => _projector = new NotificationProjector(_log, _store, _register); [Given("registration \"(.*)\" is recorded in the register with status \"(.*)\"")] [When("registration \"(.*)\" is recorded in the register with status \"(.*)\"")] public void RegistrationIsRecorded(string id, string status) { // The ACL upserts one object per registration, so submit and approval share an object URL. var objectUrl = ObjectBase + id; _register.Records[objectUrl] = new RegisterRecord(id, status, "REG-" + id); _notification = new Notification("objecten", "object", "create", new Uri(objectUrl)); } [Given("the register notification is delivered to the event subscriber")] [When("the register notification is delivered to the event subscriber")] public Task TheNotificationIsDelivered() => _projector.HandleAsync(_notification!); [When("the same register notification is delivered again")] public Task TheSameNotificationIsDeliveredAgain() => _projector.HandleAsync(_notification!); [Then("the register projection contains a row for \"(.*)\" with status \"(.*)\"")] public async Task ThenTheProjectionContainsARowWithStatus(string id, string status) { var entry = Assert.Single(await _store.AllAsync()); Assert.Equal(id, entry.Id); Assert.Equal(status, entry.Status); } [Then("the register projection contains exactly one row for \"(.*)\"")] public async Task ThenTheProjectionContainsExactlyOneRowFor(string id) { await _store.AllAsync(); Assert.Single(_store.RowsFor(id)); } }