public async Task Test_Apply_Loan() { //Arrange var fakeLoan = LoanFakes.GetFakeLoan(); //Act await _customerLoanController.Apply(fakeLoan); var loans = await _customerLoanController.Index(); var loansValue = (loans.Result as OkObjectResult).Value as IEnumerable <Loan>; //Assert loansValue.Should().NotBeNull(); loansValue.Count().Should().Be(1); loansValue.ToArray()[0].CustomerID.Should().Be(2); }
public void TestOnHttpPost_AfterPopulatingValidData_ReturnsValidData() { var mortgageinfo = new MortgageModelInfo(); mortgageinfo.Principal = 1000; mortgageinfo.DurationYears = 2.5; mortgageinfo.InterestRate = 65; var loanController = new LoanController(); ViewResult result = loanController.Index(mortgageinfo) as ViewResult; string message = result.ViewBag.Message; Assert.AreEqual("With a principal of $1000, duration of 2.5 years and an interest rate of 65%, the monthly loan payment amount is $68.17", message); }
public void Index_WhenTruePassedtToIndex_ShouldReturnDefaultIndexView() { //Arrange const int amount = 2000; const decimal rate = 3.5m; const int term = 2; var mockHomeLoanService = new Mock <IHomeLoanService>(); var mockLoanDefaultConfiguration = new Mock <ILoanDefaultConfiguration>(); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultLoanAmount).Returns(amount); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultInterestRate).Returns(rate); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultLoanTerm).Returns(term); bool?noDefault = true; //Act var controller = new LoanController(mockHomeLoanService.Object, mockLoanDefaultConfiguration.Object); var actual = controller.Index(noDefault) as ViewResult; //Assert Assert.IsNotNull(actual, "View result cannot be null"); Assert.IsNull((actual.Model as HomeLoanViewModel), "Expect view model to be null"); }
public void Index_WhenNullPassedtToIndex_ShouldReturnUseConfigurationDefaultIndexView() { //Arrange const int amount = 2000; const decimal rate = 3.5m; const int term = 2; var mockHomeLoanService = new Mock <IHomeLoanService>(); var mockLoanDefaultConfiguration = new Mock <ILoanDefaultConfiguration>(); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultLoanAmount).Returns(amount); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultInterestRate).Returns(rate); mockLoanDefaultConfiguration.SetupGet(x => x.DefaultLoanTerm).Returns(term); bool?noDefault = null; //Act var controller = new LoanController(mockHomeLoanService.Object, mockLoanDefaultConfiguration.Object); var actual = controller.Index(noDefault) as ViewResult; //Assert Assert.IsNotNull(actual, "View result cannot be null"); Assert.AreEqual(amount, ((HomeLoanViewModel)actual.Model).Amount, "Home Loan default amount not set correctly"); Assert.AreEqual(term, ((HomeLoanViewModel)actual.Model).Term, "Home Loan default term not set correctly"); Assert.AreEqual(rate, ((HomeLoanViewModel)actual.Model).InterestRate, "Home Loan default interest rate not set correctly"); }