예제 #1
0
        public void throw_an_exception_if_there_are_no_offers()
        {
            var marketLenders = new LenderMarket(interestCalculation.Object);

            Action action = () => marketLenders.GetMinInterestRate(Fakes.EmptyOffers, new Money(1000m), NumberOfMonthlyPayments);

            action.ShouldThrow <InsufficientOffersAmountException>();
        }
예제 #2
0
        public void cut_the_last_included_lenders_offer_if_it_would_overflow_loan_amount()
        {
            var marketLenders = new LenderMarket(interestCalculation.Object);
            var loanOffers    = new LoanOffers(new List <LoanOffer> {
                new LoanOffer("Jane", janeInterestRate.Annual, 1100)
            });

            marketLenders.GetMinInterestRate(loanOffers, aPrincipal, NumberOfMonthlyPayments);

            interestCalculation.Verify(a => a.GetMonthlyPayment(aPrincipal, janeInterestRate, NumberOfMonthlyPayments), Times.Once);
        }
예제 #3
0
        public void throw_an_exception_if_offers_amount_not_sufficient()
        {
            var marketLenders = new LenderMarket(interestCalculation.Object);

            interestCalculation
            .Setup(a => a.GetMonthlyPayment(It.IsAny <Money>(), It.IsAny <InterestRate>(), It.IsAny <int>()))
            .Returns(aMoney);
            interestCalculation.Setup(a => a.FindCompoundInterestRate(It.IsAny <Money>(), It.IsAny <Money>(),
                                                                      It.IsAny <int>(), It.IsAny <InterestRate>(), It.IsAny <InterestRate>()))
            .Returns(anInterestRate);

            Action action = () => marketLenders.GetMinInterestRate(Fakes.OneOfferOnly, new Money(1000m), NumberOfMonthlyPayments);

            action.ShouldThrow <InsufficientOffersAmountException>();
        }
예제 #4
0
        public void use_the_most_competitive_lenders_offers_for_calculating_min_interest_rate()
        {
            var marketLenders = new LenderMarket(interestCalculation.Object);
            var offers        = new LoanOffers(new List <LoanOffer>
            {
                new LoanOffer("Bob", bobInterestRate.Annual, (int)bobOffer.Amount),
                new LoanOffer("Jane", janeInterestRate.Annual, (int)janeOffer.Amount),
                new LoanOffer("Fred", fredInterestRate.Annual, (int)fredOffer.Amount)
            });

            interestCalculation.Setup(a => a.GetMonthlyPayment(janeOffer, janeInterestRate, NumberOfMonthlyPayments)).Returns(janeMonthlyRepayment);
            interestCalculation.Setup(a => a.GetMonthlyPayment(fredOffer, fredInterestRate, NumberOfMonthlyPayments)).Returns(fredMonthlyRepayment);
            interestCalculation.Setup(a => a.FindCompoundInterestRate(It.IsAny <Money>(), It.IsAny <Money>(),
                                                                      It.IsAny <int>(), It.IsAny <InterestRate>(), It.IsAny <InterestRate>()))
            .Returns(anInterestRate);

            var interestRate = marketLenders.GetMinInterestRate(offers, aPrincipal, NumberOfMonthlyPayments);

            interestRate.ShouldBeEquivalentTo(anInterestRate);
            interestCalculation.Verify(a => a.FindCompoundInterestRate(aPrincipal, janePlusFredRepayment,
                                                                       NumberOfMonthlyPayments, janeInterestRate, fredInterestRate), Times.Once);
        }