示例#1
0
        public void AddOrderLoanShouldAddOrderLoan()
        {
            var options = new DbContextOptionsBuilder <BankCloudDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_OrderLoan_Database")
                          .Options;

            var dbContext = new BankCloudDbContext(options);

            var ordersService = new OrdersService(dbContext, null);

            var product = new Loan
            {
                Name         = "ABCD",
                Amount       = 1000m,
                Commission   = 0.1m,
                InterestRate = 10m,
                Period       = 12
            };
            var order = new OrderLoan
            {
                Name       = product.Name,
                Commission = BankCloudCalculator.CalculateCommission(product),
                MonthlyFee = BankCloudCalculator.CalculateMounthlyFee(product)
            };

            ordersService.AddOrderLoan(order, product);
            dbContext.SaveChanges();

            var orders = dbContext.OrdersLoans.ToList();

            Assert.Single(orders);
            Assert.Equal(order.Name, orders.First().Name);
        }
示例#2
0
        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 AddOrderLoan(OrderLoan order, Product loan)
        {
            if (order == null || loan == null)
            {
                return;
            }

            order.Commission = BankCloudCalculator.CalculateCommission(loan);
            order.MonthlyFee = BankCloudCalculator.CalculateMounthlyFee(loan);
            order.Status     = OrderStatus.Pending;
            order.Name       = loan.Name;
            loan.Popularity++;

            context.OrdersLoans.Add(order);
            context.SaveChanges();
        }
        public IActionResult OrderLoan(string id)
        {
            Product loanFromDb = this.productsService.GetProductById(id);

            BankUser userFromDb = this.usersService.GetCurrentUser();

            if (!userFromDb.Accounts.Any())
            {
                return(this.Redirect("/Accounts/Activate"));
            }

            this.ViewData["Accounts"] = this.accountsService.GetUserAccounts();

            var view = this.mapper.Map <OrdersOrderLoanInputModel>(loanFromDb);

            view.UserCurrencyTypes = this.accountsService.GetUserAccounts()
                                     .Select(x => x.Currency.Name).ToList();

            view.MonthlyFee = BankCloudCalculator.CalculateMounthlyFee(loanFromDb);

            return(View(view));
        }