Пример #1
0
        public void Setup()
        {
            this.model = new List <Dto.Mortgage>();

            DateTime StartDate = DateTime.Now;

            StartDate = StartDate.AddDays(-10);

            model.Add(new Dto.Mortgage
            {
                Name = "Fixed Home Loan (Interest Only)",
                EffectiveStartDate = DateTime.Parse(StartDate.ToString()),
                EffectiveEndDate   = DateTime.Parse(DateTime.Today.ToString()),
                CancellationFee    = Convert.ToDecimal(259.99),
                EstablishmentFee   = Convert.ToDecimal(259.99),
                InterestRepayment  = (Dto.InterestRepayment)Enum.Parse(typeof(Dto.InterestRepayment), "InterestOnly"),
                MortgageId         = 1,
                MortgageType       = (Dto.MortgageType)Enum.Parse(typeof(Dto.MortgageType), "Variable")
            });

            details               = new Dto.MortgageDetails();
            details.LoanAmount    = 100000;
            details.LoanDurationY = 15;
            details.InterestRateY = 6;

            expdetails                   = new Dto.MortgageDetails();
            expdetails.LoanAmount        = 100000;
            expdetails.LoanDurationY     = 15;
            expdetails.InterestRateY     = 6;
            expdetails.MonthlyPayment    = 843.90;
            expdetails.TotalRepayment    = 151902;
            expdetails.TotalInterestPaid = 51902;
        }
        public void MortgageCalculateInvalid()
        {
            //Arrange
            Mock <IMortgageService> mortgageService = new Mock <IMortgageService>();

            //mortgageService.Setup(ur => ur.MortgageCalculate(this.invaliddetails)).Returns(this.expdetails);

            //Action
            Api.Controllers.MortgageController controller = new Api.Controllers.MortgageController(mortgageService.Object);
            Dto.MortgageDetails updModel = controller.Post(this.invaliddetails);

            //Assert
            mortgageService.Verify(ur => ur.MortgageCalculate(this.invaliddetails), Times.Once);
            Assert.IsNull(updModel);
        }
        public async Task <ActionResult> MortgageCalculate(Dto.MortgageDetails model)
        {
            if (ModelState.IsValid)
            {
                _httpClient.BaseAddress = new Uri(Baseurl);
                HttpResponseMessage result = await _httpClient.PostAsJsonAsync <Dto.MortgageDetails>("api/Mortgage", model);

                if (result.IsSuccessStatusCode)
                {
                    var EmpResponse = result.Content.ReadAsStringAsync().Result;
                    model = JsonConvert.DeserializeObject <Dto.MortgageDetails>(EmpResponse);;
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }
            return(View());
        }