public async Task GetTransactionsByAccountNumberAndAgency_Given_NoneTransactionsForAccount_Then_ReturnNotFound() { // Arrange var mockService = new Mock <IAccountAppService>(); var sourceAccountViewModel = new SourceAccountViewModel() { AccountNumber = 12232, Agency = 1232 }; var account = new Account("7127hs71hs17hs7217s2", 1232, "18187277163263"); mockService.Setup(service => service.GetByAccountNumberAndAgencyAsync( account.AccountNumber, account.Agency )).ReturnsAsync(account); var controller = new AccountController(mockService.Object); // Act var result = await controller.GetTransactionsByAccountNumberAndAgency(sourceAccountViewModel); //Assert Assert.IsType <NotFoundObjectResult>(result.Result); }
public async Task GetTransactionsByAccountNumberAndAgency_Given_InvalidAccount_Then_ReturnNotFound() { // Arrange var mockService = new Mock <IAccountAppService>(); var invalidSourceAccountViewModel = new SourceAccountViewModel() { AccountNumber = 0, Agency = 0 }; mockService.Setup(service => service.GetByAccountNumberAndAgencyAsync( invalidSourceAccountViewModel.AccountNumber, invalidSourceAccountViewModel.Agency )).ReturnsAsync((Account)null); var controller = new AccountController(mockService.Object); // Act var result = await controller.GetTransactionsByAccountNumberAndAgency(invalidSourceAccountViewModel); //Assert Assert.IsType <NotFoundObjectResult>(result.Result); }
public async Task <ActionResult <IEnumerable <TransactionViewModel> > > GetTransactionsByAccountNumberAndAgency([FromBody] SourceAccountViewModel sourceAccountViewModel) { if (!ModelState.IsValid) { ModelState.AddModelError("TransactionViewModelInvalid", "Informe um modelo válido"); return(BadRequest(ModelState)); } var account = await _accountAppService.GetByAccountNumberAndAgencyAsync(sourceAccountViewModel.AccountNumber, sourceAccountViewModel.Agency); if (account == null) { return(NotFound("Conta não encontrada")); } var transactions = await _transactionAppService.GetByAccountIdAsync(account.AccountId); if (!transactions.Any()) { return(NotFound("Nenhuma transação encontrada para esta conta")); } var result = _mapper.Map <IEnumerable <TransactionViewModel> >(transactions.OrderByDescending(t => t.Date)); return(Ok(result)); }