public async void WhenAMakeDepositEventIsReceived_ThenATheBankAccountBalanceIsUpdated() { var accountId = Guid.NewGuid(); var mockBankAccount = new Banking.QueryProcessor.Domain.BankAccount.BankAccount { Id = accountId.ToString() }; mockRepositoryFacade.MockBankAccountRepository .Setup(mock => mock.Get(mockBankAccount.Id)) .Returns(Task.Run(() => mockBankAccount)); var depositMadeEvent = new DepositMadeEvent(Guid.NewGuid(), "A Deposit", 123.45m, accountId, 1); var jsonData = JsonConvert.SerializeObject(depositMadeEvent); await readerStoreEventHandler.Run(jsonData, 1, DateTime.UtcNow, "1", mockLogger.Object); mockRepositoryFacade.MockRepositoryFacade.Verify( mock => mock.BankAccountRepository.Update(It.Is <Banking.QueryProcessor.Domain.BankAccount.BankAccount>( bankAccount => bankAccount.Balance == 123.45m ) ) ); }
public async void WhenAMakeDepositEventIsReceived_ThenADepositIsSaved() { var accountId = Guid.NewGuid(); var mockBankAccount = new Banking.QueryProcessor.Domain.BankAccount.BankAccount { Id = accountId.ToString() }; mockRepositoryFacade.MockBankAccountRepository .Setup(mock => mock.Get(mockBankAccount.Id)) .Returns(Task.Run(() => mockBankAccount)); var depositMadeEvent = new DepositMadeEvent(Guid.NewGuid(), "A Deposit", 123.45m, accountId, 1); var jsonData = JsonConvert.SerializeObject(depositMadeEvent); await readerStoreEventHandler.Run(jsonData, 1, DateTime.UtcNow, "1", mockLogger.Object); mockRepositoryFacade.MockRepositoryFacade.Verify( mock => mock.TransactionsRepository.Insert(It.Is <Transaction>( transaction => transaction.BankAccount.Id == mockBankAccount.Id && transaction.Description == depositMadeEvent.Description && transaction.Id == depositMadeEvent.EntityId.ToString() && transaction.Amount == depositMadeEvent.Amount && transaction.Type == TransactionType.Deposit ) ) ); }
public DepositId MakeDeposit(string description, decimal amount) { if (Id == default) { throw new EntityException("Bank account must be opened before making a deposit."); } var depositId = new DepositId(); var @event = new DepositMadeEvent( depositId.Value, description, amount, Id.Value ); Apply(@event); return(depositId); }