public async void Deposit_Valid_Amount(string accountId, double amount) { var account = Substitute.For <Account>(); var customer = Substitute.For <Customer>(); customer.FindAccount(Arg.Any <Guid>()) .Returns(account); customerReadOnlyRepository .GetByAccount(Guid.Parse(accountId)) .Returns(customer); var output = Substitute.For <CustomPresenter <Application.UseCases.Deposit.DepositResponse> >(); var depositUseCase = new Application.UseCases.Deposit.DepositInteractor( customerReadOnlyRepository, customerWriteOnlyRepository, output, converter ); var request = new Application.UseCases.Deposit.DepositCommand( Guid.Parse(accountId), amount ); await depositUseCase.Handle(request); Assert.Equal(request.Amount, output.Response.Transaction.Amount); }
public async void Deposit_Valid_Amount(string pin, string name, string accountId, double amount) { var account = Substitute.For <Account>(); var customer = Substitute.For <Customer>(); customer.FindAccount(Arg.Any <Guid>()) .Returns(account); customerReadOnlyRepository .GetByAccount(Guid.Parse(accountId)) .Returns(customer); var depositUseCase = new DepositService( customerReadOnlyRepository, customerWriteOnlyRepository, converter ); var request = new DepositCommand( Guid.Parse(accountId), amount ); DepositResult result = await depositUseCase.Handle(request); Assert.Equal(request.Amount, result.Transaction.Amount); }
public async Task <CloseResult> Handle(CloseCommand command) { Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId); Account account = customer.FindAccount(command.AccountId); customer.RemoveAccount(command.AccountId); await customerWriteOnlyRepository.Update(customer); CloseResult response = resultConverter.Map <CloseResult>(account); return(response); }
public async Task Handle(CloseCommand request) { Customer customer = await customerReadOnlyRepository.GetByAccount(request.AccountId); Account account = customer.FindAccount(request.AccountId); customer.RemoveAccount(request.AccountId); await customerWriteOnlyRepository.Update(customer); CloseResponse response = responseConverter.Map <CloseResponse>(account); this.outputBoundary.Populate(response); }
public async Task Handle(GetAccountDetailsCommand message) { var customer = await customerReadOnlyRepository.GetByAccount(message.AccountId); if (customer == null) { outputBoundary.Populate(null); return; } var account = customer.FindAccount(message.AccountId); AccountResponse response = responseConverter.Map <AccountResponse>(account); outputBoundary.Populate(response); }
public async Task Handle(DepositCommand command) { Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId); if (customer == null) { throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed."); } Credit credit = new Credit(new Amount(command.Amount)); Account account = customer.FindAccount(command.AccountId); account.Deposit(credit); await customerWriteOnlyRepository.Update(customer); TransactionResponse transactionResponse = responseConverter.Map <TransactionResponse>(credit); DepositResponse response = new DepositResponse(transactionResponse, account.CurrentBalance.Value); outputBoundary.Populate(response); }
public async Task <DepositResult> Process(DepositCommand command) { Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId); if (customer == null) { throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed."); } Credit credit = new Credit(new Amount(command.Amount)); Account account = customer.FindAccount(command.AccountId); account.Deposit(credit); await customerWriteOnlyRepository.Update(customer); TransactionResult transactionResult = resultConverter.Map <TransactionResult>(credit); DepositResult response = new DepositResult(transactionResult, account.CurrentBalance.Value); return(response); }
public async Task Handle(WithdrawCommand request) { Customer customer = await customerReadOnlyRepository.GetByAccount(request.AccountId); if (customer == null) { throw new AccountNotFoundException($"The account {request.AccountId} does not exists or is already closed."); } Debit debit = new Debit(new Amount(request.Amount)); Account account = customer.FindAccount(request.AccountId); account.Withdraw(debit); await customerWriteOnlyRepository.Update(customer); TransactionResponse transactionResponse = responseConverter.Map <TransactionResponse>(debit); WithdrawResponse response = new WithdrawResponse( transactionResponse, account.CurrentBalance.Value ); outputBoundary.Populate(response); }