using Kitchen.DAL.Contracts; using Kitchen.DAL.Repositories; namespace Kitchen.DAL.UnitTests; public sealed class InMemoryKitchenWorkItemRepositoryTests { private readonly InMemoryKitchenWorkItemRepository repository = new(); [Fact] public async Task UpsertAsync_PersistsLinkedKitchenWorkItem() { var record = CreateRecord(workItemId: "WK-4001", state: "Queued"); await repository.UpsertAsync(record, CancellationToken.None); var persisted = await repository.GetAsync(record.ContextId, record.WorkItemId, CancellationToken.None); Assert.NotNull(persisted); Assert.Equal("ORD-4001", persisted!.OrderId); Assert.Equal("CHK-4001", persisted.CheckId); } [Fact] public async Task ListQueuedAsync_ReturnsOnlyQueuedItemsForContext() { await repository.UpsertAsync(CreateRecord(workItemId: "WK-4001", state: "Queued"), CancellationToken.None); await repository.UpsertAsync(CreateRecord(workItemId: "WK-4002", state: "Preparing"), CancellationToken.None); await repository.UpsertAsync(CreateRecord(workItemId: "WK-4003", state: "Queued", contextId: "other-context"), CancellationToken.None); var queued = await repository.ListQueuedAsync("demo-context", CancellationToken.None); Assert.Single(queued); Assert.Equal("WK-4001", queued.Single().WorkItemId); } [Fact] public async Task AppendEventAsync_StoresHistoryForLinkedWorkItem() { var first = new KitchenWorkItemEventRecord("demo-context", "WK-4001", "EVT-1", "Queued", "Ticket was queued.", DateTime.UtcNow.AddMinutes(-3)); var second = new KitchenWorkItemEventRecord("demo-context", "WK-4001", "EVT-2", "Preparing", "Chef started work.", DateTime.UtcNow.AddMinutes(-1)); await repository.AppendEventAsync(first, CancellationToken.None); await repository.AppendEventAsync(second, CancellationToken.None); var events = await repository.ListEventsAsync("demo-context", "WK-4001", CancellationToken.None); Assert.Equal(2, events.Count); Assert.Equal("EVT-2", events.First().EventId); } private static KitchenWorkItemRecord CreateRecord(string workItemId, string state, string contextId = "demo-context") { return new KitchenWorkItemRecord( ContextId: contextId, WorkItemId: workItemId, OrderId: "ORD-4001", CheckId: "CHK-4001", TableId: "T-09", WorkType: "PrepareOrder", Station: "grill", Priority: 3, RequestedAtUtc: DateTime.UtcNow.AddMinutes(-4), State: state, ClaimedBy: null); } }