public void BankAccountService_Tests() { IEnumerable <BankAccount> accs = CustomMapper <BankAccountDTO, BankAccount> .Map(_bankAccounts); IRepository <BankAccount> repository = new BankAccountMemoryRepository(); foreach (var item in accs) { repository.Create(item); } IUnitOfWork unitOfWork = new UnitOfWork(repository); IBankAccountService service = new BankAccountService(unitOfWork); BankAccountDTO bankAccount = service.Get(8); service.Deposit(bankAccount.Id, 200m); Assert.AreEqual(8, bankAccount.Id); bankAccount = service.Get(8); Assert.AreEqual(700.50m, bankAccount.Balance); Assert.AreEqual(20, bankAccount.BonusPoints); service.Withdraw(8, 500.50m); bankAccount = service.Get(8); Assert.AreEqual(200m, bankAccount.Balance); }
public ActionResult CheckBalance([FromRoute] string account) { try { var accounts = new List <BankAccount>(); if (string.IsNullOrWhiteSpace(account)) { accounts.AddRange(BankAccountService.GetByUser(CurrentLoginInfo.User.Id)); } else { var accountEntity = BankAccountService.Get(account); if (CurrentLoginInfo.User.Role.HasFlag(UserRole.Customer) && !BankAccountService.IsOwnedByUser(account, CurrentLoginInfo.User)) { return(Forbid()); } accounts.Add(accountEntity); } return(Ok(accounts.Select(x => new { account = x.AccountName, currency = x.Currency.Name, balance = x.Balance }))); } catch (Exception ex) when(ex is ArgumentException || ex is BusinessException) { return(BadRequest(ex.Message)); } catch (Exception ex) { Logger.LogError("Error while checking balance: " + ex.Message, ex); return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public async Task <TrxBalance?> GetBalance(DocumentId documentId, CancellationToken token) { _logger.LogTrace($"Getting directoryId={documentId}"); BankAccount?bankAccount = await _bankAccountService.Get(documentId, token); if (bankAccount == null) { _logger.LogWarning($"Account not found for directoryId={documentId}"); return(null); } return(new TrxBalance { AccountId = bankAccount.AccountId, Balance = bankAccount.Balance() }); }
public static BankAccount GetBankAccount(Tenant tenant) { var customer = GetCustomer(tenant.StripeID); var service = new BankAccountService(); BankAccount bankAccount = service.Get(tenant.StripeID, customer.DefaultSourceId); bankAccount.Id = ""; bankAccount.CustomerId = ""; return(bankAccount); }
public Result <BankAccountDetail> Get(int id, int clientId) { var result = new Result <BankAccountDetail>(); BankAccountService BankAccountDetailService = new BankAccountService(); var lstClient = BankAccountDetailService.Get(id, clientId); result.Value = (BankAccountDetail)lstClient; result.IsSuccess = true; return(result); }
public Result <IList <BankAccountDetail> > GetAll(int clientId) { var result = new Result <IList <BankAccountDetail> >(); BankAccountService BankAccountDetailService = new BankAccountService(); var lstClient = BankAccountDetailService.Get(clientId); result.Value = (IList <BankAccountDetail>)lstClient; result.IsSuccess = true; return(result); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IBankAccountRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <BankAccount>(null)); var service = new BankAccountService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BankAccountModelValidatorMock.Object, mock.DALMapperMockFactory.DALBankAccountMapperMock); ApiBankAccountServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async Task <IActionResult> Get(string path, CancellationToken token) { DocumentId documentId = DocumentIdTools.FromUrlEncoding(path); if (!documentId.Container.IsEmpty()) { return(BadRequest(_noContainer)); } BankAccount?response = await _service.Get(documentId, token); if (response == null) { return(NotFound()); } return(Ok(response)); }
public void CreditTest_OK() { // MOCK var dataBankAccount = new List <BankAccount> { new BankAccount { Id = 1, AccountNumber = 1, Agency = 1, Balance = 500, PersonId = 1, Type = Domain.Enum.BankAccountType.Corrente }, new BankAccount { Id = 2, AccountNumber = 2, Agency = 1, Balance = 1000, PersonId = 2, Type = Domain.Enum.BankAccountType.Corrente }, new BankAccount { Id = 3, AccountNumber = 3, Agency = 1, Balance = 200, PersonId = 3, Type = Domain.Enum.BankAccountType.Corrente } }.AsQueryable(); var dataBankAccountLaunches = new List <BankAccountLaunches> { }.AsQueryable(); var mockSetBankAccount = new Mock <DbSet <BankAccount> >(); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.Provider).Returns(dataBankAccount.Provider); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.Expression).Returns(dataBankAccount.Expression); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.ElementType).Returns(dataBankAccount.ElementType); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.GetEnumerator()).Returns(dataBankAccount.GetEnumerator()); var mockSetBankAccountLaunches = new Mock <DbSet <BankAccountLaunches> >(); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.Provider).Returns(dataBankAccountLaunches.Provider); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.Expression).Returns(dataBankAccountLaunches.Expression); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.ElementType).Returns(dataBankAccountLaunches.ElementType); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.GetEnumerator()).Returns(dataBankAccountLaunches.GetEnumerator()); var mockContext = new Mock <AppDbContext>(); mockContext.Setup(c => c.BankAccount).Returns(mockSetBankAccount.Object); mockContext.Setup(c => c.Set <BankAccount>()).Returns(mockSetBankAccount.Object); mockContext.Setup(c => c.BankAccountLaunches).Returns(mockSetBankAccountLaunches.Object); mockContext.Setup(c => c.Set <BankAccountLaunches>()).Returns(mockSetBankAccountLaunches.Object); BankAccountRepository bankAccountRepository = new BankAccountRepository(mockContext.Object); BankAccountLaunchesRepository bankAccountLaunchesRepository = new BankAccountLaunchesRepository(mockContext.Object); BankAccountService bankAccountService = new BankAccountService(bankAccountRepository, new Service.Validators.BankAccountValidator()); BankAccountLaunchesService bankAccountLaunchesService = new BankAccountLaunchesService(bankAccountLaunchesRepository, new Service.Validators.BankAccountLaunchesValidator()); TransactionsService transactionsService = new TransactionsService(bankAccountLaunchesService, bankAccountService); var credit = new Domain.ApiEntryModels.Credit(1, 1, 100); var bankAccountCurrentBalance = bankAccountService.Get(credit.Agency, credit.AccountNumber).Balance; var bankDebit = transactionsService.Credit(credit); decimal currentBalanceWithDebit = bankAccountCurrentBalance + credit.Value; decimal currentBalance = bankDebit.Result.Balance; Assert.Equal(currentBalanceWithDebit, currentBalance); }
public void TransferTest_OK() { // MOCK var dataBankAccount = new List <BankAccount> { new BankAccount { Id = 1, AccountNumber = 1, Agency = 1, Balance = 500, PersonId = 1, Type = Domain.Enum.BankAccountType.Corrente }, new BankAccount { Id = 2, AccountNumber = 2, Agency = 1, Balance = 1000, PersonId = 2, Type = Domain.Enum.BankAccountType.Corrente }, new BankAccount { Id = 3, AccountNumber = 3, Agency = 1, Balance = 200, PersonId = 3, Type = Domain.Enum.BankAccountType.Corrente } }.AsQueryable(); var dataBankAccountLaunches = new List <BankAccountLaunches> { }.AsQueryable(); var mockSetBankAccount = new Mock <DbSet <BankAccount> >(); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.Provider).Returns(dataBankAccount.Provider); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.Expression).Returns(dataBankAccount.Expression); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.ElementType).Returns(dataBankAccount.ElementType); mockSetBankAccount.As <IQueryable <BankAccount> >().Setup(m => m.GetEnumerator()).Returns(dataBankAccount.GetEnumerator()); var mockSetBankAccountLaunches = new Mock <DbSet <BankAccountLaunches> >(); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.Provider).Returns(dataBankAccountLaunches.Provider); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.Expression).Returns(dataBankAccountLaunches.Expression); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.ElementType).Returns(dataBankAccountLaunches.ElementType); mockSetBankAccountLaunches.As <IQueryable <BankAccountLaunches> >().Setup(m => m.GetEnumerator()).Returns(dataBankAccountLaunches.GetEnumerator()); var mockContext = new Mock <AppDbContext>(); mockContext.Setup(c => c.BankAccount).Returns(mockSetBankAccount.Object); mockContext.Setup(c => c.Set <BankAccount>()).Returns(mockSetBankAccount.Object); mockContext.Setup(c => c.BankAccountLaunches).Returns(mockSetBankAccountLaunches.Object); mockContext.Setup(c => c.Set <BankAccountLaunches>()).Returns(mockSetBankAccountLaunches.Object); BankAccountRepository bankAccountRepository = new BankAccountRepository(mockContext.Object); BankAccountLaunchesRepository bankAccountLaunchesRepository = new BankAccountLaunchesRepository(mockContext.Object); BankAccountService bankAccountService = new BankAccountService(bankAccountRepository, new Service.Validators.BankAccountValidator()); BankAccountLaunchesService bankAccountLaunchesService = new BankAccountLaunchesService(bankAccountLaunchesRepository, new Service.Validators.BankAccountLaunchesValidator()); TransactionsService transactionsService = new TransactionsService(bankAccountLaunchesService, bankAccountService); var transfer = new Domain.ApiEntryModels.Transfer(1, 1, 1, 2, 200); var sourceBankAccountCurrentBalance = bankAccountService.Get(transfer.SourceAgency, transfer.SourceBankAccount).Balance; var destinyBankAccountCurrentBalance = bankAccountService.Get(transfer.DestinyAgency, transfer.DestinyBankAccount).Balance; var bankTransfer = transactionsService.Transfer(transfer).Result; decimal sourceBankAccountCurrentBalanceTransfer = sourceBankAccountCurrentBalance - transfer.Value; decimal destinyAccountCurrentBalanceTransfer = destinyBankAccountCurrentBalance + transfer.Value; Assert.Equal(sourceBankAccountCurrentBalanceTransfer, bankTransfer.SourceBankAccount.Balance); Assert.Equal(destinyAccountCurrentBalanceTransfer, bankTransfer.DestinyBankAccount.Balance); }