public async Task Handle(DeleteInventoryItem command) { InventoryItemEvents iie = new InventoryItemEvents(_inventoryEventRepository, command.AggregateId); // ToDo: Cache aggregate and attempt to update rather than regenerate InventoryItemAggregate iia = (InventoryItemAggregate)await iie.ModelAsync(); await Task.WhenAll( iie.AppendEventAsync((IModelEvent <Guid>)command) , _inventoryWriteRepository.DeleteAsync(command.AggregateId) ); }
private async Task _HandleUpdate(AInventoryItemEvent command) { InventoryItemEvents iie = new InventoryItemEvents(_inventoryEventRepository, command.AggregateId); // ToDo: Cache aggregate and attempt to update rather than regenerate InventoryItemAggregate iia = (InventoryItemAggregate)await iie.ModelAsync(); command.ApplyEventData(iia); await Task.WhenAll( iie.AppendEventAsync((IModelEvent <Guid>)command), _inventoryWriteRepository.UpdateAsync( command.AggregateId, new InventoryItemDto(iia) )); }
public async Task Confirm_Final_Aggregate_Model() { Guid id = Guid.NewGuid(); InventoryItemDto item = new InventoryItemDto() { Id = id, LastEventTimestamp = DateTime.UtcNow, Name = "", IsActive = false, Count = 0, Note = "" }; // Create Inventory Item await InvokeInventoryEventRepository().AppendEventAsync(new CreateInventoryItem(item)); // Activate await InvokeInventoryEventRepository().AppendEventAsync(new ActivateInventoryItem(id, new SetInventoryItemActivation())); // Deactivate await InvokeInventoryEventRepository().AppendEventAsync(new DeactivateInventoryItem(id, new SetInventoryItemActivation())); // Update Full Item await InvokeInventoryEventRepository().AppendEventAsync(new UpdateInventoryItem(new InventoryItemDto() { Id = id, LastEventTimestamp = DateTime.UtcNow, Name = "UpdatedItem", IsActive = true, Count = 2, Note = "N/A" })); // Set Count await InvokeInventoryEventRepository().AppendEventAsync(new SetInventoryItemCount( id, new SetInventoryItemCountData() { Count = 10 })); // Increase Count by 1 await InvokeInventoryEventRepository().AppendEventAsync(new IncreaseInventoryItemCount( id, new AdjustInventoryItemCount() { Delta = 1 })); // Decrease Count by 3 await InvokeInventoryEventRepository().AppendEventAsync(new DecreaseInventoryItemCount( id, new AdjustInventoryItemCount() { Delta = 3 })); // Set Name await InvokeInventoryEventRepository().AppendEventAsync(new SetInventoryItemName( id, new SetInventoryItemNameData() { Name = "Name" })); // Set Note await InvokeInventoryEventRepository().AppendEventAsync(new SetInventoryItemNote( id, new SetInventoryItemNoteData() { Note = "Note" })); // Confirm Final Model InventoryItemEvents iie = new InventoryItemEvents(InvokeInventoryEventRepository(), id); InventoryItemAggregate iia = (InventoryItemAggregate)await iie.ModelAsync(); Assert.IsTrue(iia.Name.Equals("Name", StringComparison.Ordinal)); Assert.IsTrue(iia.IsActive); Assert.IsTrue(iia.Count == 8); Assert.IsTrue(iia.Note.Equals("Note", StringComparison.Ordinal)); // Delete Item await InvokeInventoryEventRepository().AppendEventAsync(new DeleteInventoryItem(id)); // Confirm Nb of Events int eventCount = await InvokeInventoryEventRepository().ModelEventsCountAsync(id); Assert.IsTrue(eventCount == 10); }