public void CreateHomeLoan_WhenValidLoanRequestCriteriaSupplied_ReturnsServiceStatusSuccessWithPaymentPlan()
        {
            //Arrange
            var mockLoanServiceResponse = new HomeLoanResponse()
            {
                Status        = ServiceStatus.Success,
                InterestTotal = 100,
                Principle     = 2000,
                Loan          = _fixture.Build <HomeLoan>().Create(),
                PaymentPlan   = new List <IPayment>()
                {
                    _fixture.Build <MonthlyRepayment>().Create()
                }
            };

            var homeLoanCreateRequest = _fixture.Build <HomeLoanCreateRequest>().Create();

            var mockLoanService = new Mock <ILoanService>();

            mockLoanService.Setup(s => s.NewHomeLoan(It.IsAny <HomeLoanServiceRequest>())).Returns(mockLoanServiceResponse);

            var homeLoanService = new HomeLoanService(mockLoanService.Object);

            //Act
            var response = homeLoanService.CreateHomeLoan(homeLoanCreateRequest);

            //Assert
            var expectedStatus = ServiceStatus.Success;

            Assert.AreEqual(expectedStatus, response.ServiceStatus);
            Assert.AreEqual(0, response.ValidationMessages.Count);
            Assert.IsNotNull(response.LoanSummary, "Expected to receive details of payment plan for the loan");
            Assert.AreEqual(1, response.LoanSummary.ScheduledPayments.Count, "Expected number of scheduled repayments to be 1");
        }
        public void CreateHomeLoan_WhenInterestRateIsLessThanZero_ReturnsServiceStatusFailure()
        {
            //Arrange
            var mockLoanServiceResponse = new HomeLoanResponse()
            {
                BrokenBusinessRules = new List <BusinessRule>()
                {
                    new BusinessRule()
                    {
                        Description = ValidationMessages.InvalidHomeLoanInterestRate
                    }
                },
                Status = ServiceStatus.Failure
            };

            var homeLoanCreateRequest = _fixture.Build <HomeLoanCreateRequest>().Create();

            var mockLoanService = new Mock <ILoanService>();

            mockLoanService.Setup(s => s.NewHomeLoan(It.IsAny <HomeLoanServiceRequest>())).Returns(mockLoanServiceResponse);

            var homeLoanService = new HomeLoanService(mockLoanService.Object);

            //Act
            var response = homeLoanService.CreateHomeLoan(homeLoanCreateRequest);

            //Assert
            var expectedStatus = ServiceStatus.Failure;

            Assert.AreEqual(expectedStatus, response.ServiceStatus);
            Assert.AreEqual(1, response.ValidationMessages.Count);
            Assert.AreEqual(ValidationMessages.InvalidHomeLoanInterestRate, response.ValidationMessages[0].Message);
        }