public void When_depositing_money_on_a_closed_account_it_should_throw() { // Arrange var account = new Account(Guid.NewGuid(), "Thomas"); account.Close(); var repository = new InMemoryEventRepositoryBuilder().WithAggregates(account).Build(); var handler = new DepositMoneyCommandHandler(repository); // Act Action action = () => handler.Handle(new DepositMoneyCommand(account.Id, 200)); // Assert action.ShouldThrow<InvalidOperationException>(); }
public void When_depositing_money_it_should_add_it_to_the_account() { // Arrange var account = new Account(Guid.NewGuid(), "Thomas"); var eventStore = new InMemoryEventRepositoryBuilder().WithAggregates(account).Build(); var handler = new DepositMoneyCommandHandler(eventStore); // Act handler.Handle(new DepositMoneyCommand(account.Id, 200)); // Assert eventStore.Events.Should().HaveCount(1); eventStore.Events.OfType<MoneyDepositedEvent>().Should().HaveCount(1); account = eventStore.GetById<Account>(account.Id); account.Amount.Should().Be(200); }