public void When_drinks_added() { var tab = TabAggregate.BuildFromHistory(new List <IDomainEvent> { new TabOpened { AggregateId = _tabId, WaiterName = "Gary", TableNumber = 45, Balance = 0.0m } }); tab.AddDrinks(new OrderDrinks { Id = Guid.NewGuid(), AggregateId = _tabId, OrderItems = new List <OrderItem> { new OrderItem { Name = "Coke (pint)", Price = 2.0m } } }); var tabEvent = tab.GetDomainEvents().Last() as DrinksOrdered; tabEvent.OrderItems.Count.Should().Be(1); }
public void When_new_tab_aggregate_tab_opened_event_raised() { var tab = new TabAggregate(_tabId, 45, "Gary"); var tabEvent = tab.GetDomainEvents().Last() as TabOpened; tabEvent.AggregateId.Should().Be(_tabId); tabEvent.TableNumber.Should().Be(45); tabEvent.WaiterName.Should().Be("Gary"); tabEvent.Balance.Should().Be(0.0m); }
public void Handle(OrderDrinks command) { var events = _repository.GetEventsFor(command.AggregateId); var tab = TabAggregate.BuildFromHistory(events.ToList()); if (tab is null) { throw new NullAggregateException(); } tab.AddDrinks(command); tab.RaiseLastEvent(@event => _messageBus.RaiseEvent(@event)); }
public void Handle(OpenTab command) { var tab = new TabAggregate(command.AggregateId, command.TableNumber, command.WaiterName); tab.RaiseLastEvent(@event => _messageBus.RaiseEvent(@event)); }