public void Create_Returns400BadRequest() { //Arrange var userLoanInput = new UserLoan { Id = 10, UserLoanNum = "67853423187", InterestAmount = 375, EarlyPaymentFee = 76, Balance = 1990, AppliedForTopup = true, LoanMasterId = 1, CreatedOn = new DateTime(2019, 1, 1), UpdatedOn = new DateTime(2019, 1, 1) }; var mockUserLoanRepository = new Mock <IUserLoanRepository>(); var mockAppLogger = new Mock <IAppLogger>(); //mockUserLoanRepository.Setup(x => x.Add(userLoanInput)).Returns(userLoanInput); var controller = new UserLoanController(mockAppLogger.Object, mockUserLoanRepository.Object); //Act var actual = controller.Create(userLoanInput); //Assert Assert.Null(actual.Value); var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actual.Result); Assert.Equal(400, badRequestObjectResult.StatusCode); }
public void Get_Successful() { //Arrange var id = 1; var userId = 1; var userLoan = new UserLoan { Id = 1, UserLoanNum = "67853423187", InterestAmount = 375, EarlyPaymentFee = 76, Balance = 1990, AppliedForTopup = true, LoanMasterId = 1, CreatedOn = new DateTime(2019, 1, 1), UpdatedOn = new DateTime(2019, 1, 1), }; var mockUserLoanRepository = new Mock <IUserLoanRepository>(); var mockAppLogger = new Mock <IAppLogger>(); mockUserLoanRepository.Setup(x => x.GetByLoanIdUserId(id, userId)).Returns(userLoan); var controller = new UserLoanController(mockAppLogger.Object, mockUserLoanRepository.Object); //Act var actual = controller.GetObjectById(userId, id); //Assert Assert.Same(userLoan, actual.Value); }
public void Get_Returns500InternalServerError() { //Arrange var id = 1; var userId = 1; var mockUserLoanRepository = new Mock <IUserLoanRepository>(); var mockAppLogger = new Mock <IAppLogger>(); mockUserLoanRepository.Setup(x => x.GetByLoanIdUserId(id, userId)).Throws(new InvalidOperationException()); var controller = new UserLoanController(mockAppLogger.Object, mockUserLoanRepository.Object); //Act var actual = controller.GetObjectById(id, userId); //Assert Assert.Null(actual.Value); Assert.Equal(500, ((ObjectResult)actual.Result).StatusCode); }
public void TestGetLoanDetailsOrderNumber() { var mockRep = new Mock <IPersonalLoanDetailsRepository>(); List <Data.Models.PersonalLoanDetail> retVal = new List <Data.Models.PersonalLoanDetail> { new Data.Models.PersonalLoanDetail { AccountNumber = 111111, } }; mockRep.Setup(c => c.GetPersonalLoanDetails(It.IsAny <long>())).Returns(retVal); UserLoanController obj = new UserLoanController(mockRep.Object); var currentResult = obj.UserDetail(1); int actualNumber = currentResult.Select(c => c.OrderNumber).FirstOrDefault(); int expectedNumber = 1; Assert.Equal(actualNumber, expectedNumber); }
public void Get_Returns404NotFound() { //Arrange var id = 999; var userId = 999; var mockUserLoanRepository = new Mock <IUserLoanRepository>(); var mockAppLogger = new Mock <IAppLogger>(); mockUserLoanRepository.Setup(x => x.GetByLoanIdUserId(id, userId)).Returns <UserLoan>(null); var controller = new UserLoanController(mockAppLogger.Object, mockUserLoanRepository.Object); //Act var actual = controller.GetObjectById(id, userId); //Assert Assert.Null(actual.Value); var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(actual.Result); Assert.Equal(404, notFoundObjectResult.StatusCode); }