Exemplo n.º 1
0
        public void GenerateJSONMortgageFileFromValidData()
        {
            var amount      = 100000m;
            var interest    = 0.055f;
            var downPayment = 20000m;
            var term        = 30;
            var expected    = "{\"monthly payment\":454.23,\"total interest\":83522.80,\"total payment\":163522.80}";

            var output = _mortgageService.CalculateMortgageFromData(amount, interest, downPayment, term);

            Assert.Equal(expected, output.toJSONString());
        }
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            decimal amount      = data?.amount ?? 0;
            float   interest    = data?.interest ?? 0;
            decimal downpayment = data?.downpayment ?? 0;;
            int     term        = data?.downpayment ?? 0;

            var mortgageData = _mortgageService.CalculateMortgageFromData(amount, interest, downpayment, term);

            return(mortgageData != null
                ? (ActionResult) new OkObjectResult(mortgageData.toJSONString())
                : new BadRequestObjectResult(""));
        }