public void GetAllActiveProductsShouldReturnActiveProducts() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Return_Active_Product_Database") .Options; var dbContext = new BankCloudDbContext(options); var productService = new ProductsService(dbContext, null); var loan = new Loan { Name = "abcd", IsDeleted = false }; var save = new Save { Name = "dcba", IsDeleted = false }; var save1 = new Save { Name = "1234", IsDeleted = true }; dbContext.Products.Add(loan); dbContext.Products.Add(save); dbContext.Products.Add(save1); dbContext.SaveChanges(); var products = dbContext.Products.Where(x => x.IsDeleted == false); var returnedActiveProducts = productService.GetAllActiveProducts(); Assert.Equal(2, returnedActiveProducts.Count()); Assert.Equal(products, returnedActiveProducts); }
public void AddOrderSaveShouldAddOrderSave() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Add_OrderSave_Database") .Options; var dbContext = new BankCloudDbContext(options); var ordersService = new OrdersService(dbContext, null); var product = new Save { Name = "ABCD", Amount = 1000m, Commission = 0, InterestRate = 10m, Period = 12 }; var order = new OrderSave { Name = product.Name, }; order.MonthlyFee = BankCloudCalculator.CalculateDepositMonthlyIncome(order, product); ordersService.AddOrderSave(order, product); dbContext.SaveChanges(); var orders = dbContext.OrdersSaves.ToList(); Assert.Single(orders); Assert.Equal(order.Name, orders.First().Name); }
public UsersService(BankCloudDbContext context, UserManager <BankUser> userManager, IHttpContextAccessor httpContextAccessor) { this.context = context; this.userManager = userManager; this.httpContextAccessor = httpContextAccessor; }
public void GetCurrenciesShouldReturnAllCurrencies() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Currencies_AccountServices_Database") .Options; var dbContext = new BankCloudDbContext(options); var currencies = new List <Currency> { new Currency { Id = "a" }, new Currency { Id = "b" }, new Currency { Id = "c" } }; dbContext.AddRange(currencies); dbContext.SaveChanges(); var accountService = new AccountsService(dbContext, null); var returnedCurrencies = accountService.GetCurrencies(); Assert.Equal(3, returnedCurrencies.Count()); Assert.Equal(currencies, returnedCurrencies); }
public void RestoreProductShouldWorkCorrectly() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Restore_Product_Database") .Options; var dbContext = new BankCloudDbContext(options); var productService = new ProductsService(dbContext, null); var loanId = "123"; var saveId = "321"; var productLoan = new Loan { Id = loanId, Name = "ABC", IsDeleted = true }; var productSave = new Save { Id = saveId, Name = "CBA", IsDeleted = true }; dbContext.Products.Add(productLoan); dbContext.Products.Add(productSave); dbContext.SaveChanges(); productService.RestoreProduct(loanId); productService.RestoreProduct(saveId); var loan = dbContext.Products.Find(loanId); var save = dbContext.Products.Find(saveId); Assert.False(loan.IsDeleted); Assert.False(save.IsDeleted); }
public TransferService(BankCloudDbContext context, IHttpContextAccessor httpContextAccessor, IAccountsService accountsService, IMapper mapper) { this.context = context; this.httpContextAccessor = httpContextAccessor; this.accountsService = accountsService; this.mapper = mapper; }
public void ApproveLoanRequestSholudSetOrderLoanToApprove() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Approve_OrderLoan_Database") .Options; var dbContext = new BankCloudDbContext(options); var ordersService = new OrdersService(dbContext, null); var orderId = "abcd123"; var product = new Loan { Name = "ABCD", Amount = 1000m, Commission = 0.1m, InterestRate = 10m, Period = 12, Account = new Account { Currency = new Currency { IsoCode = "USD" } } }; var order = new OrderLoan { Id = orderId, Name = product.Name, Account = new Account { Currency = new Currency { IsoCode = "USD" } }, Commission = BankCloudCalculator.CalculateCommission(product), MonthlyFee = BankCloudCalculator.CalculateMounthlyFee(product), Loan = product }; dbContext.OrdersLoans.Add(order); dbContext.SaveChanges(); var ordered = dbContext.OrdersLoans.Find(orderId); ordersService.ApproveLoanRequest(ordered); dbContext.SaveChanges(); var approved = dbContext.OrdersLoans.Find(orderId); Assert.Equal(OrderStatus.Approved, approved.Status); }
public void GetAccountByIdShouldReturnCoreectedAccount() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Create_AccountServices_Database") .Options; var dbContext = new BankCloudDbContext(options); var account = new Account { Id = "ABCD" }; dbContext.Accounts.Add(account); dbContext.SaveChanges(); var accountService = new AccountsService(dbContext, null); var returnedAccount = accountService.GetAccountById(account.Id); Assert.Equal(account.Id, returnedAccount.Id); }
public void GetAccountByIbanShouldReturnCorectAccount() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "AccountByIban_AccountServices_Database") .Options; var dbContext = new BankCloudDbContext(options); var account = new Account { IBAN = "CLD 1234 5478" }; dbContext.Accounts.Add(account); dbContext.SaveChanges(); var accountService = new AccountsService(dbContext, null); var returnedAccount = accountService.GetAccountByIban(account.IBAN); Assert.Equal(account, returnedAccount); }
public void AddProductShouldAddProduct() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Add_Product_Database") .Options; var dbContext = new BankCloudDbContext(options); var productService = new ProductsService(dbContext, null); var product = new Loan { Name = "ABCD" }; productService.AddProduct(product); var products = dbContext.Products.ToList(); Assert.Single(products); Assert.Equal(product.Name, products.First().Name); }
public void GetTransferByIdShouldReturnCorrectTransfer() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "GetTransferById_Database") .Options; var dbContext = new BankCloudDbContext(options); var transferService = new TransferService(dbContext, null, null, null); var transferId = "123abc"; var transfer = new Transfer { Id = transferId }; dbContext.Transfers.Add(transfer); dbContext.SaveChanges(); var returnedTransfer = transferService.GetTransferById(transferId); Assert.Equal(transfer, returnedTransfer); }
public void GetOrderSaveByIdShouldReturnCorrectOrderSave() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "GetOrderLoanById_Database") .Options; var dbContext = new BankCloudDbContext(options); var ordersService = new OrdersService(dbContext, null); var orderId = "123abc"; var order = new OrderSave { Id = orderId }; dbContext.OrdersSaves.Add(order); dbContext.SaveChanges(); var returnedOrder = ordersService.GetOrderSaveById(orderId); Assert.Equal(order, returnedOrder); }
public void GetProductByIdShouldReturCorrectProduct() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Return_Product_By_Id_Database") .Options; var dbContext = new BankCloudDbContext(options); var productService = new ProductsService(dbContext, null); var loan = new Loan { Name = "abcd", IsDeleted = false }; var loan2 = new Loan { Name = "1235", IsDeleted = true }; var save = new Save { Name = "dcba", IsDeleted = false }; var save2 = new Save { Name = "ddsdf", IsDeleted = false }; var save1 = new Save { Name = "1234", IsDeleted = true }; dbContext.Products.Add(loan); dbContext.Products.Add(loan2); dbContext.Products.Add(save); dbContext.Products.Add(save1); dbContext.Products.Add(save2); dbContext.SaveChanges(); var product = productService.GetProductById(save.Id); var product1 = productService.GetProductById(loan2.Id); Assert.Equal(product.Id, save.Id); Assert.Equal(product1.Id, loan2.Id); }
public void AddBankCloudTransferShouldAddBankCloudTran() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "AddBankCloudTransfer_Database") .Options; var dbContext = new BankCloudDbContext(options); var transferService = new TransferService(dbContext, null, null, null); var transferId = "123dsdabc"; var transfer = new Transfer { Id = transferId }; transferService.AddBankCloudTransfer(transfer); var transfers = dbContext.Transfers.ToList(); var returnedTransfer = dbContext.Transfers.Find(transferId); Assert.Single(transfers); Assert.Equal(transfer, returnedTransfer); }
public void GetAllActiveInsuranceShouldReturnActiveSaves() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "Return_ActiveInsurance_Product_Database") .Options; var dbContext = new BankCloudDbContext(options); var productService = new ProductsService(dbContext, null); var loan = new Loan { Name = "abcd", IsDeleted = false }; var loan2 = new Loan { Name = "1235", IsDeleted = true }; var insure = new Insurance { Name = "dcba", IsDeleted = false }; var insure1 = new Insurance { Name = "ddsdf", IsDeleted = false }; var insure2 = new Insurance { Name = "1234", IsDeleted = true }; dbContext.Products.Add(loan); dbContext.Products.Add(loan2); dbContext.Products.Add(insure); dbContext.Products.Add(insure2); dbContext.Products.Add(insure1); dbContext.SaveChanges(); var returnedSaves = productService.GetAllActiveInsurance(); Assert.Equal(2, returnedSaves.Count()); }
public void GetPaymentsByAccountIdShouldReturnPaymentsForAccount() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "GetPaymentsByAccount_Database") .Options; var dbContext = new BankCloudDbContext(options); var transferService = new TransferService(dbContext, null, null, null); var accountId = "123abc"; var account = new Account { Id = accountId }; dbContext.Accounts.Add(account); dbContext.SaveChanges(); dbContext.Payments.AddRange(new List <Payment> { new Payment { AccountId = accountId }, new Payment { AccountId = accountId }, new Payment { }, new Payment { } }); dbContext.SaveChanges(); var payments = transferService.GetPaymentsByAccountId(accountId); Assert.Equal(2, payments.Count()); }
public void RejectRequestShouldSetOrderRajected() { var options = new DbContextOptionsBuilder <BankCloudDbContext>() .UseInMemoryDatabase(databaseName: "RejectReques_Order_Database") .Options; var dbContext = new BankCloudDbContext(options); var ordersService = new OrdersService(dbContext, null); var orderId = "abcd123"; var product = new Save { Name = "ABCD", Amount = 1000m, Commission = 0, InterestRate = 10m, Period = 12 }; var order = new OrderSave { Id = orderId, Name = product.Name, }; ordersService.AddOrderSave(order, product); dbContext.SaveChanges(); var ordered = dbContext.OrdersSaves.Find(orderId); ordersService.RejectRequest(ordered); dbContext.SaveChanges(); var rejected = dbContext.OrdersSaves.Find(orderId); Assert.Equal(OrderStatus.Rejected, rejected.Status); }
public ProductsService(BankCloudDbContext context, IHttpContextAccessor httpContextAccessor) { this.context = context; this.httpContextAccessor = httpContextAccessor; }