Beispiel #1
0
        public async Task <IActionResult> Create(int?loanId)
        {
            if (User.Identity.IsAuthenticated)
            {
                var getCurrentUserId = _userManager.GetUserId(HttpContext.User);
                var currentUser      = await _userService.GetById(int.Parse(getCurrentUserId));

                TempData["LoanId"] = loanId;
                var loan = await _loanService.GetById(loanId.GetValueOrDefault());

                ViewBag.Term                = typeof(Term).GetValues();
                ViewBag.Currencies          = typeof(Currency).GetAllEnumNames();
                ViewBag.Status              = Status.Pending.ToString();
                ViewData["AccrueAccountId"] = new SelectList(currentUser.Accounts, "Id", "AccountNumber");
                ViewData["AccountId"]       = new SelectList(currentUser.Accounts, "Id", "AccountNumber");

                var model = new AccountLoanViewModel
                {
                    Loan = loan
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
        //[Fact]
        public async Task Create_ReturnsARedirectToIndexAction_ForValidModel()
        {
            // Arrange
            var controller = new AccountLoansController(_accLoanMock.Object, _accMock.Object, _loanMock.Object,
                                                        _mapperMock.Object, UserManagerMockHelper().Object, _userMock.Object);

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            tempData["LoanId"]  = null;
            controller.TempData = tempData;

            // Act
            var AccloanModel = new AccountLoanViewModel
            {
                Employment        = "test",
                Sum               = 1000,
                Currency          = "GEL",
                Term              = "test",
                OfficePhoneNumber = "+995 598 545 555"
            };

            var mapperResult = _mapperMock.Setup(m => m.Map <AccountLoanViewModel>(It.IsAny <AccountLoanViewModel>())).Returns(AccloanModel);



            var result = await controller.Create(accountLoanViewModel : AccloanModel);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("AccountLoans", redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
Beispiel #3
0
        public async Task <IActionResult> Create(AccountLoanViewModel accountLoanViewModel)
        {
            var loanId = TempData["loanId"] as int?;

            if (ModelState.IsValid)
            {
                var accountLoan = _mapper.Map <AccountLoan>(accountLoanViewModel);
                accountLoan.LoanId = loanId.GetValueOrDefault();

                await _accountLoanService.Create(accountLoan);

                Alert("The Loan Has Successfully Added To Your Account", NotificationType.success);
                return(RedirectToAction(nameof(Index)));
            }
            Alert("Something went wrong", NotificationType.error);
            return(View(accountLoanViewModel));
        }