private void When(InvoiceItemAddedEvent @event) { Id = @event.AggregateRootId; var invoiceItem = new InvoiceItem { Price = @event.Price, Quantity = @event.Quantity }; Items.Add(invoiceItem); }
public void Handle(InvoiceItemAddedEvent @event) { var existing = this.items.FirstOrDefault(x => x.ProductId == @event.Item.ProductId); if (existing != null) { this.items.Remove(existing); this.items.Add(new InvoiceItem( existing.ProductId, existing.Price, existing.Amount + @event.Item.Amount)); } else { this.items.Add(@event.Item); } }
public void AllowToAddItemToOpenInvoice() { var item = new InvoiceItem("1", 1m, 1u); var addItemCommand = new AddInvoiceItemCommand(item); InvoiceItemAddedEvent invoiceEvent = null; using (this.invoiceRoot .Where(x => x is InvoiceItemAddedEvent) .Select(x => x as InvoiceItemAddedEvent) .Subscribe(x => invoiceEvent = x)) { this.invoice.SetupGet(x => x.IsOpen).Returns(true); this.invoiceRoot.Execute(this.invoice.Object, addItemCommand); Assert.Equal(item, invoiceEvent.Item); } }