public void expect_exception_when_argument_equals_null()
        {
            ICalculation <MarketRateInputModel, MarketRateOutputModel> rateCalculation =
                new RateCalculation();

            rateCalculation.Calculate(null);
        }
        public void expect_true_for_correct_requested_amount()
        {
            ICalculation <MarketRateInputModel, MarketRateOutputModel> rateCalculation =
                new RateCalculation();

            var loanAmount = 1000;
            var rate       = 0.07;
            var term       = 36;
            var result     = rateCalculation.Calculate(new MarketRateInputModel(loanAmount, term, rate));

            Assert.AreEqual(loanAmount, result.RequstedAmount);
        }
        public void expect_true_for_correct_total_repayment()
        {
            ICalculation <MarketRateInputModel, MarketRateOutputModel> rateCalculation =
                new RateCalculation();

            var loanAmount = 1000;
            var rate       = 0.07;
            var term       = 36;
            var result     = rateCalculation.Calculate(new MarketRateInputModel(loanAmount, term, rate));

            // excepted result is true
            var expectedTotalPayment = (decimal)1111.57;
            var currentTotalPayment  = Math.Truncate(result.TotalPayment * 100) / 100;

            Assert.AreEqual(expectedTotalPayment, currentTotalPayment);
        }
        /// <summary>
        ///    Get offer for good match with requested amount
        /// </summary>
        /// <param name="requestedAmount"></param>
        /// <param name="lenderMarkerDatas"></param>
        private List <MarketRateOutputModel> FindPossibleQuotes(decimal requestedAmount, List <MarketData> lenderMarkerDatas)
        {
            var rateCalculation = new RateCalculation();
            var possibleQuotes  = new List <MarketRateOutputModel>();

            // requestedAmount assign to neededAmount
            var neededAmount = requestedAmount;

            foreach (var lenderData in lenderMarkerDatas)
            {
                // if lender has amount which I needed, get all money. Otherwise, get money which is available
                var available = neededAmount >= lenderData.Available
                    ? lenderData.Available
                    : neededAmount;

                var rateInput = new MarketRateInputModel
                {
                    Amount = available,
                    Rate   = lenderData.Rate,
                    Term   = Term
                };

                // calculate rate and repayment
                var rateOutput = rateCalculation.Calculate(rateInput);
                possibleQuotes.Add(rateOutput);

                // subtraction avaible money from needed amount
                neededAmount -= available;

                // exit loop when we get money which I needed
                if (neededAmount <= 0)
                {
                    break;
                }
            }

            return(possibleQuotes);
        }
        public void expect_exception_when_interest_rate_equal_zero()
        {
            ICalculation <MarketRateInputModel, MarketRateOutputModel> rateCalculation =
                new RateCalculation();

            var loanAmount = 1000;
            var rate       = 0;
            var term       = 36;

            Exception exception = null;

            try
            {
                rateCalculation.Calculate(new MarketRateInputModel(loanAmount, term, rate));
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            var isTrue = CheckException(exception, ErrorMessage.ArgumentRateGreaterThanZero);

            Assert.IsTrue(isTrue);
        }