//UpdatesAuditing_WhenSavingAnExistingBankAccount private bool IsValidForInsert(BankAccountEntity bankAccountToSave) { bankAccountToSave.BankAccountID.Should().Be(Constants.NewRecordID); bankAccountToSave.Audit.Should().NotBeNull(); bankAccountToSave.Audit.CreatedBy.Should().NotBeNullOrEmpty(); bankAccountToSave.Audit.CreatedOn.Should().NotBe(default);
public async Task UpdateBankAccountForCurrentUser_UserDoesNotOwnAccount_ThrowsException() { // Arrange var existingEntity = new BankAccountEntity { AccountType = BankAccountType.Checking, Disabled = false, CurrentBalance = 100, StartBalance = 100, Name = "BankAccountName", UserId = _defaultUserId + 1 }; InsertEntity(existingEntity); var bankAccountModel = new BankAccountModel { Id = existingEntity.Id, AccountType = BankAccountType.Checking, Name = "OtherName" }; var bankAccountService = _mocker.CreateInstance <BankAccountService>(); // Act var result = FluentActions.Awaiting(async() => await bankAccountService.UpdateBankAccountForCurrentUser(bankAccountModel)); // Arrange await result.Should().ThrowAsync <NotFoundException>(); }
public bool Delete(BankAccountEntity bankAccountEntity) { using (var transaction = context.Database.BeginTransaction()) { try { var contracts = context.Contracts.Where(x => x.BankAccountInFinance == bankAccountEntity.BankAccountInFinance); foreach (var contract in contracts) { contract.BankAccountInFinance = 0; } context.SaveChanges(); context.BankAccounts.Remove(new BankAccounts { BankAccountInFinance = bankAccountEntity.BankAccountInFinance, CustomerId = bankAccountEntity.CustomerId, SupplierId = bankAccountEntity.SupplierId }); context.SaveChanges(); transaction.Commit(); return(true); } catch (Exception e) { transaction.Rollback(); throw e; } } }
public async Task UpdateBankAccountForCurrentUser_StartBalanceChanged_UpdatesCurrentBalance() { // Arrange var bankAccountModel = new BankAccountModel { Id = 1, AccountType = BankAccountType.Checking, Disabled = true, Name = "BankAccountName", StartBalance = 100 }; var bankAccountEntity = new BankAccountEntity { Name = bankAccountModel.Name, UserId = _defaultUserId, StartBalance = 200 }; InsertEntity(bankAccountEntity); _mocker.GetMock <IBankAccountCalculationService>().Setup(x => x.CalculateCurrentBalanceForBankAccount( It.IsAny <IUnitOfWork>(), It.Is <BankAccountEntity>(x => x.Id == bankAccountEntity.Id))).ReturnsAsync(bankAccountModel.StartBalance).Verifiable(); var bankAccountService = _mocker.CreateInstance <BankAccountService>(); // Act await bankAccountService.UpdateBankAccountForCurrentUser(bankAccountModel); // Assert _mocker.GetMock <IBankAccountCalculationService>().VerifyAll(); _mocker.GetMock <IBankAccountCalculationService>().VerifyNoOtherCalls(); }
public async Task GetBankAccountByIdForCurrentUser_AccountExists_ReturnsBankAccount() { // Arrange var bankAccountId = 1; var bankAccountEntity = new BankAccountEntity { AccountType = BankAccountType.Checking, Id = bankAccountId, Disabled = true, CurrentBalance = 100, StartBalance = 100, Name = "BankAccount", UserId = _defaultUserId }; InsertEntity(bankAccountEntity); var bankAccountService = _mocker.CreateInstance <BankAccountService>(); // Act var result = await bankAccountService.GetBankAccountByIdForCurrentUser(bankAccountId); // Arrange result.Should().NotBeNull(); result.Should().Match <BankAccountModel>(x => x.AccountType == bankAccountEntity.AccountType && x.CurrentBalance == bankAccountEntity.StartBalance && x.Disabled == bankAccountEntity.Disabled && x.Id == bankAccountEntity.Id && x.Name == bankAccountEntity.Name && x.StartBalance == bankAccountEntity.StartBalance); }
public async Task <bool> UpdateByUserIdAsync(long id, string name, string bankAccount, string bankName) { using (MyDbContext dbc = new MyDbContext()) { BankAccountEntity entity = await dbc.GetAll <BankAccountEntity>().SingleOrDefaultAsync(b => b.UserId == id); if (entity == null) { entity = new BankAccountEntity(); entity.Name = name; entity.BankAccount = bankAccount; entity.BankName = bankName; entity.UserId = id; dbc.BankAccounts.Add(entity); } else { entity.Name = name; entity.BankAccount = bankAccount; entity.BankName = bankName; } await dbc.SaveChangesAsync(); return(true); } }
private void InsertMonthlySavingTransaction(IUnitOfWork unitOfWork, BankAccountEntity primaryChecking, BankAccountEntity savingsAccount, CategoryEntity internalCashflowCategory, int dayOfMonth, int amount) { var today = DateTime.Now.Date; DateTime startDate = new DateTime(today.Year, today.Month, dayOfMonth); // Make sure its a historical transaction if (today.Day < dayOfMonth) { startDate = startDate.AddMonths(-1); } var transactions = new List <TransactionEntity>(); // Insert 2 years of monthly transactions for (var i = 0; i < 24; i++) { transactions.Add(new TransactionEntity { AccountNumber = "NL02ABNA9450889198", Amount = -amount, BankAccount = primaryChecking, Description = "Savings deposit", Date = startDate.AddMonths(-i), TransactionCategories = new List <TransactionCategoryEntity> { new TransactionCategoryEntity { Amount = amount, Category = internalCashflowCategory } }, DestinationAccount = "NL83RABO2338418883", Name = "Savings", User = primaryChecking.User }); transactions.Add(new TransactionEntity { AccountNumber = "NL83RABO2338418883", Amount = amount, BankAccount = savingsAccount, Description = "Savings deposit", Date = startDate.AddMonths(-i), TransactionCategories = new List <TransactionCategoryEntity> { new TransactionCategoryEntity { Amount = amount, Category = internalCashflowCategory } }, DestinationAccount = "", Name = "Savings", User = savingsAccount.User }); } unitOfWork.TransactionRepository.InsertRange(transactions); }
protected override IEnumerable <FileParserInput> DownloadTransactions() { var valueParser = ComponentContext.ResolveKeyed <IValueParser>(Constants.UniqueContainerKeys.ValueParserGermanDecimal); var account = BankAccountRepository.GetByAccountNameAndBankName(Constants.DownloadHandler.AccountNamePaymentService, Constants.DownloadHandler.BankNamePayPal); if (account == null) { account = new BankAccountEntity { BankName = Constants.DownloadHandler.BankNamePayPal, AccountName = Constants.DownloadHandler.AccountNamePaymentService }; BankAccountRepository.Insert(account); } var balanceEntries = Browser.FindElements(By.ClassName("currenciesEntry")) .Select(element => (decimal)valueParser.Parse(element.Text.CleanNumberStringFromOther())); var balance = balanceEntries.FirstOrDefault(); Browser.WaitForJavaScript(5000); TakeScreenshot("screenshot"); Browser.Navigate().GoToUrl("https://www.paypal.com/cgi-bin/webscr?cmd=_history-download"); //set date Browser.FindElement(By.Name("from_a")).Clear(); Browser.FindElement(By.Name("from_b")).Clear(); Browser.FindElement(By.Name("from_c")).Clear(); var startDate = DateTime.Now.AddYears(-2).AddDays(1); Browser.FindElement(By.Name("from_a")).SendKeys(startDate.Month.ToString()); //Month Browser.FindElement(By.Name("from_b")).SendKeys(startDate.Day.ToString()); //Day Browser.FindElement(By.Name("from_c")).SendKeys(startDate.Year.ToString()); //Year var downloadType = new SelectElement(Browser.FindElement(By.Name("custom_file_type"))); downloadType.SelectByValue("comma_balaffecting"); var resultingFile = DownloadFromWebElement(Browser.FindElement(By.Name("submit.x")), "transactions"); yield return(new FileParserInput { OwningEntity = account, FileParser = ComponentContext.ResolveKeyed <IFileParser>(Constants.UniqueContainerKeys.FileParserPayPal), FilePath = resultingFile, TargetEntity = typeof(PayPalTransactionEntity), Balance = balance, BalanceSelectorFunc = () => BankTransactionRepository.TransactionSumForAccountId(account.Id) }); }
public async Task GetActiveBankAccountsForCurrentUser_AccountsExist_ReturnsAllActiveBankAccounts() { // Arrange var checkingAccount = new BankAccountEntity { Name = "Checking", CurrentBalance = 100, AccountType = BankAccountType.Checking, Disabled = false, UserId = _defaultUserId }; var disabledCheckingAccount = new BankAccountEntity { Name = "DisabledChecking", CurrentBalance = 100, AccountType = BankAccountType.Checking, Disabled = true, UserId = _defaultUserId }; var savingsAccount = new BankAccountEntity { Name = "Savings", CurrentBalance = 300, StartBalance = 200, AccountType = BankAccountType.Savings, Disabled = false, UserId = _defaultUserId }; InsertEntities(checkingAccount, savingsAccount, disabledCheckingAccount); var bankAccountService = _mocker.CreateInstance <BankAccountService>(); // Act var result = await bankAccountService.GetActiveBankAccountsForCurrentUser(); // Assert result.Should().NotBeNull(); result.Should().HaveCount(2); result.Should().Contain(x => x.AccountType == checkingAccount.AccountType && x.CurrentBalance == checkingAccount.CurrentBalance && x.Disabled == checkingAccount.Disabled && x.Id == checkingAccount.Id && x.Name == checkingAccount.Name && x.StartBalance == checkingAccount.StartBalance); result.Should().Contain(x => x.AccountType == savingsAccount.AccountType && x.CurrentBalance == savingsAccount.CurrentBalance && x.Disabled == savingsAccount.Disabled && x.Id == savingsAccount.Id && x.Name == savingsAccount.Name && x.StartBalance == savingsAccount.StartBalance); }
public static BankAccountEntity UpdateFromModel(this BankAccountEntity bankAccount, BankAccountModel model) { bankAccount.Name = model.Name; bankAccount.StartBalance = model.StartBalance; bankAccount.AccountType = model.AccountType; bankAccount.Disabled = model.Disabled; return(bankAccount); }
public void addBankAccount(BankAccountEntity bankAccountEntity) { base.executeNonQueryCommand(@"INSERT INTO [dbo].[BankAccount] ([BA_ID],[BU_ID],[BU_Amount]) VALUES (@BA_ID,@BU_ID,@BU_Amount)", //new SqlParameter[] { ↓↓↓↓↓↓ new[] { new SqlParameter("BA_ID", bankAccountEntity.BankAccountId), new SqlParameter("BU_ID", bankAccountEntity.BankUserId), new SqlParameter("BU_Amount", bankAccountEntity.Amount) }); }
public static BankAccountModel ToDto(this BankAccountEntity entity) { return(new BankAccountModel { Id = entity.Id, Name = entity.Name, CurrentBalance = entity.CurrentBalance.GetValueOrDefault(), Type = entity.AccountType, Disabled = entity.Disabled }); }
public static BankAccountModel ToDto(this BankAccountEntity bankAccountEntity) { return(new BankAccountModel { AccountType = bankAccountEntity.AccountType, CurrentBalance = bankAccountEntity.CurrentBalance, Disabled = bankAccountEntity.Disabled, StartBalance = bankAccountEntity.StartBalance, Name = bankAccountEntity.Name, Id = bankAccountEntity.Id }); }
public IActionResult DeleteBank([FromBody] BankAccountEntity bank) { try { return(Ok(bankAccountsService.Delete(bank))); } catch (Exception e) { log.LogError(e.Message + "\nin:" + e.StackTrace); return(Problem(null)); } }
public bool CreateAccount(BankAccount newAccount) { var bankAccountEntity = new BankAccountEntity() { Balance = newAccount.Balance, OwnerId = newAccount.Owner.EntityId, BankAccountTypeValue = (int)newAccount.AccountType }; return(_bankDAO.AddBankAccount(bankAccountEntity)); }
public OpenUserDepositForm(BankAccountEntity currentAccount) { InitializeComponent(); _currentAccount = currentAccount; currentAccountLabel.Text += " " + _currentAccount.Currency + " " + _currentAccount.MoneyCount; dbContext = new BankDbContext(); depositTypeComboBox.DataSource = dbContext.DepositTypes.ToList(); }
public BankAccountDTO ToDTO(BankAccountEntity entity) { BankAccountDTO dto = new BankAccountDTO(); dto.Name = entity.Name; dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.BankAccount = entity.BankAccount; dto.BankName = entity.BankName; dto.Description = entity.Description; dto.UserId = entity.UserId; return(dto); }
public async Task UpdateBankAccountForCurrentUser_AccountExists_UpdatesBankAccount( string name, BankAccountType bankAccountType, decimal startBalance, bool disabled) { // Arrange var bankAccountModel = new BankAccountModel { Id = 1, AccountType = bankAccountType, Disabled = disabled, Name = name, StartBalance = startBalance }; var existingEntity = new BankAccountEntity { AccountType = BankAccountType.Checking, Disabled = false, CurrentBalance = 100, StartBalance = 100, Name = "BankAccountName", UserId = _defaultUserId }; InsertEntity(existingEntity); if (bankAccountModel.StartBalance != existingEntity.StartBalance) { _mocker.GetMock <IBankAccountCalculationService>().Setup(x => x.CalculateCurrentBalanceForBankAccount( It.IsAny <IUnitOfWork>(), It.Is <BankAccountEntity>(y => y.Id == existingEntity.Id))).ReturnsAsync(bankAccountModel.StartBalance); } var bankAccountService = _mocker.CreateInstance <BankAccountService>(); // Act var result = await bankAccountService.UpdateBankAccountForCurrentUser(bankAccountModel); // Arrange result.Should().NotBeNull(); result.Should().Match <BankAccountModel>(x => x.AccountType == bankAccountModel.AccountType && x.CurrentBalance == bankAccountModel.StartBalance && x.Disabled == bankAccountModel.Disabled && x.Name == bankAccountModel.Name && x.StartBalance == bankAccountModel.StartBalance); _mocker.GetMock <IBankAccountCalculationService>().VerifyAll(); _mocker.GetMock <IBankAccountCalculationService>().VerifyNoOtherCalls(); }
private BankAccountEntity InsertBankAccount(IUnitOfWork unitOfWork, SinanceUserEntity user, string name, BankAccountType bankAccountType) { var bankAccount = new BankAccountEntity { AccountType = bankAccountType, StartBalance = 3000, Name = name, User = user }; unitOfWork.BankAccountRepository.Insert(bankAccount); return(bankAccount); }
private async Task ProcessTransfer(BankAccountEntity account, SbpEventDto sbpEvent) { account.BalanceInBrl += sbpEvent.Amount; await _bankAccountRepository.Update(account); // var bankClientAccountExchange = _mapper.Map<SbpEventDto, BankAccountExchangeEntity>(sbpEvent); // bankClientAccountExchange.BankAccountId = account.Id; // // await _bankAccountExchangeRepository.Insert(bankClientAccountExchange); // _bankAccountExchangeRepository.Save(); _bankAccountRepository.Save(); }
private void InsertRandomMonthlyTransactionsForCategory(IUnitOfWork unitOfWork, BankAccountEntity bankAccount, CategoryEntity category, string transactionName, string transactionDescription, int amountMinValue, int amountMaxValue) { var today = DateTime.Now.Date; var dayInMonth = _random.Next(1, 25); DateTime transactionDate = new DateTime(today.Year, today.Month, dayInMonth); // Make sure its a historical transaction if (today.Day < dayInMonth) { transactionDate = transactionDate.AddMonths(-1); } var transactions = new List <TransactionEntity>(); // Insert 2 years of monthly transactions for (var i = 0; i < 24; i++) { var amount = (decimal)_random.Next(amountMinValue * 100, amountMaxValue * 100) / 100; dayInMonth = _random.Next(-7, 7); transactionDate = transactionDate.AddDays(dayInMonth); transactions.Add(new TransactionEntity { AccountNumber = "NL02ABNA9450889198", Amount = amount, BankAccount = bankAccount, Description = transactionDescription, Date = transactionDate, TransactionCategories = new List <TransactionCategoryEntity> { new TransactionCategoryEntity { Amount = amount, Category = category } }, DestinationAccount = "NL83RABO2338418883", Name = transactionName, User = bankAccount.User }); transactionDate = transactionDate.AddMonths(-1); } unitOfWork.TransactionRepository.InsertRange(transactions); }
protected override IEnumerable <FileParserInput> DownloadTransactions() { var downloadResults = new List <FileParserInput>(); Browser.WaitForJavaScript(12000); Browser.FindElement(By.XPath("//*[@data-test='main-nav-kontozentrale']")).Click(); Browser.WaitForJavaScript(); //fist ist cumulative account for (var i = 1; i < GetAccountLinks().Count; i++) { GetAccountLinks()[i].Click(); Browser.WaitForJavaScript(2000); var valueParser = ComponentContext.ResolveKeyed <IValueParser>(Constants.UniqueContainerKeys.ValueParserGermanDecimal); var balance = GetAccountBalance().Text.CleanNumberStringFromOther(); var infoBox = Browser.FindElement(By.ClassName("info-box")); var iban = infoBox.FindElement(By.TagName("h2")).Text.CleanString(); var bankAccount = BankAccountRepository.GetByIban(iban); if (bankAccount == null) { bankAccount = new BankAccountEntity { AccountNumber = iban, Iban = iban, BankName = Constants.DownloadHandler.BankNameRaiffeisen, AccountName = i == 0 ? Constants.DownloadHandler.AccountNameGiro : Constants.DownloadHandler.AccountNameSaving }; BankAccountRepository.Insert(bankAccount); } TakeScreenshot(iban); var resultingFile = DownloadFromWebElement(Browser.FindElement(By.ClassName("icon-csv")), iban); downloadResults.Add(new FileParserInput { OwningEntity = bankAccount, FileParser = ComponentContext.ResolveKeyed <IFileParser>(Constants.UniqueContainerKeys.FileParserRaiffeisenGiro), FilePath = resultingFile, TargetEntity = typeof(RaiffeisenTransactionEntity), Balance = (decimal)valueParser.Parse(balance), BalanceSelectorFunc = () => BankTransactionRepository.TransactionSumForAccountId(bankAccount.Id) }); } downloadResults.AddRange(DownloadDepots()); return(downloadResults); }
public async Task <long> AddAsync(long userId, string name, string bankAccount, string bankName) { using (MyDbContext dbc = new MyDbContext()) { BankAccountEntity entity = new BankAccountEntity(); entity.UserId = userId; entity.Name = name; entity.BankAccount = bankAccount; entity.BankName = bankName; dbc.BankAccounts.Add(entity); await dbc.SaveChangesAsync(); return(entity.Id); } }
public override void TestInitialize() { base.TestInitialize(); TransactionRepository = Container.Resolve <IRepository <RaiffeisenTransactionEntity> >(); BankAccountRepository = Container.Resolve <IRepository <BankAccountEntity> >(); BankAccountEntity = new BankAccountEntity { AccountName = "Giro", BankName = "Raiffeisen", AccountNumber = "AT001234567891234", Iban = "AT001234567891234" }; BankAccountRepository.InsertOrGetWithEquality(BankAccountEntity); BankAccountRepository.Save(); }
public async Task <bool> DeleteAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { BankAccountEntity entity = await dbc.GetAll <BankAccountEntity>().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(false); } entity.IsDeleted = true; await dbc.SaveChangesAsync(); return(true); } }
public bool AddBankAccount(BankAccountEntity bankAccount) { #region Argument Guards if (bankAccount is null) { throw new ArgumentNullException(nameof(bankAccount)); } #endregion // Assign key bankAccount.EntityId = $"{AccountTable}_{DateTime.UtcNow.ToString(FormatDefaults.BankAccountFormat)}"; return(_ds.AddOrUpdate(AccountTable, bankAccount)); }
public bool Add(BankAccountEntity bankAccountEntity) { try { context.BankAccounts.Add(new BankAccounts { BankAccountInFinance = bankAccountEntity.BankAccountInFinance, CustomerId = bankAccountEntity.CustomerId, SupplierId = bankAccountEntity.SupplierId }); context.SaveChanges(); return(true); } catch (Exception e) { throw e; } }
public async Task <bool> UpdateAsync(long id, string name, string bankAccount, string bankName) { using (MyDbContext dbc = new MyDbContext()) { BankAccountEntity entity = await dbc.GetAll <BankAccountEntity>().SingleOrDefaultAsync(b => b.Id == id); if (entity == null) { return(false); } entity.Name = name; entity.BankAccount = bankAccount; entity.BankName = bankName; await dbc.SaveChangesAsync(); return(true); } }
protected override IEnumerable <FileParserInput> DownloadTransactions() { Browser.WaitForJavaScript(5000); var ibanRaw = Browser.FindElement(By.ClassName("accountText")).Text; //First is Tagesgeld var iban = ibanRaw.Split(':')[1].CleanString(); var balanceStr = Browser.FindElement(new ByChained(By.ClassName("currency"), By.ClassName("amountblock-wrapper"))).Text; var valueParser = ComponentContext.ResolveKeyed <IValueParser>(Constants.UniqueContainerKeys.ValueParserGermanDecimal); var balance = (decimal)valueParser.Parse(balanceStr); Browser.FindElement(By.ClassName("accountInfo-wrapper")).Click(); Browser.WaitForJavaScript(); var bankAccount = BankAccountRepository.GetByIban(iban); if (bankAccount == null) { bankAccount = new BankAccountEntity { AccountNumber = iban, Iban = iban, BankName = Constants.DownloadHandler.BankNameRci, AccountName = Constants.DownloadHandler.AccountNameSaving }; BankAccountRepository.Insert(bankAccount); } TakeScreenshot(iban); var exportButton = Browser.FindElement(By.ClassName("transactions-csv-export")); var file = DownloadFromWebElement(exportButton, iban); yield return(new FileParserInput { Balance = balance, BalanceSelectorFunc = () => BankTransactionRepository.TransactionSumForAccountId(bankAccount.Id), FileParser = ComponentContext.ResolveKeyed <IFileParser>(Constants.UniqueContainerKeys.FileParserRci), FilePath = file, OwningEntity = bankAccount, TargetEntity = typeof(RciTransactionEntity) }); }
private void InsertWeeklyTransactionsForCategory( IUnitOfWork unitOfWork, BankAccountEntity bankAccount, CategoryEntity category, DayOfWeek transactionDayOfWeek, string transactionName, string transactionDescription, int amountMinValue, int amountMaxValue) { var today = DateTime.Now.Date; // Make sure its a historical transaction var todayDayOfWeek = today.DayOfWeek; var dayDifference = todayDayOfWeek > transactionDayOfWeek ? transactionDayOfWeek - todayDayOfWeek : transactionDayOfWeek - todayDayOfWeek - 7; var startDate = today.AddDays(dayDifference); var transactions = new List <TransactionEntity>(); // Insert 2 years of weekly transactions for (var i = 0; i < 104; i++) { var amount = (decimal)_random.Next(amountMinValue * 100, amountMaxValue * 100) / 100; transactions.Add(new TransactionEntity { AccountNumber = "NL02ABNA9450889198", Amount = amount, BankAccount = bankAccount, Description = transactionDescription, Date = startDate.AddDays(-7 * i), TransactionCategories = new List <TransactionCategoryEntity> { new TransactionCategoryEntity { Amount = amount, Category = category } }, DestinationAccount = "NL83RABO2338418883", Name = transactionName, User = bankAccount.User }); } unitOfWork.TransactionRepository.InsertRange(transactions); }
public void AddItems() { var bank = new BankEntity { Name = "Bank Account", Town = "Some Town", }; var customer = new CustomerEntity { Name = "customer 1", }; var account1 = new BankAccountEntity { Name = "acc1", Balance = 123 }; var account2 = new BankAccountEntity { Name = "acc2", Balance = 555 }; bank.Customers.Add(customer); customer.Accounts.Add(account1); customer.Accounts.Add(account2); using (var repo = _context.BeginTransaction()) { repo.Create(bank); repo.Create(customer); repo.Create(account1); repo.Create(account2); repo.Commit(); } }