public async Task <ActionResult <decimal> > GetTrolleyTotal([FromBody] TrolleyRequest trolleyRequest) { var total = await _trolleyService.GetTrolleyTotalAsync(trolleyRequest); if (total <= 0) { return(BadRequest()); } return(Ok(total)); }
public async Task <ActionResult <decimal> > GetTrolleyTotal([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "answers/trolleyTotal")] HttpRequest req, ILogger log) { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var trolleyRequest = JsonConvert.DeserializeObject <TrolleyRequest>(requestBody); var trolleyTotal = await _trolleyService.GetTrolleyTotalAsync(trolleyRequest.Products, trolleyRequest.Specials, trolleyRequest.Quantities); return(trolleyTotal); }
public async Task GetTrolleyTotal() { // Arrange var trolleyRequest = new TrolleyRequest { Products = new List <ProductRequest> { new ProductRequest { Name = "Test A", Price = 14 } }, Specials = new List <SpecialRequest> { new SpecialRequest { Quantities = new List <QuantityRequest> { new QuantityRequest { Name = "Test B", Quantity = 1 } } } }, Quantities = new List <QuantityRequest> { new QuantityRequest { Name = "Test C" , Quantity = 1 } } }; _trolleyService.GetTrolleyTotalAsync(trolleyRequest).Returns(Task.FromResult(14m)); // Act var actionResult = await _controller.GetTrolleyTotal(trolleyRequest); var result = actionResult.Result as OkObjectResult; var total = (decimal)result.Value; // Assert Assert.IsAssignableFrom <decimal>(total); Assert.Equal(14, total); }
public async Task <decimal> CalculateTrolleyTotal([FromBody] TrolleyItem tItem) { try { _logger.LogInformation("Trolley total was Calculated."); var user = await _trolleyService.GetTrolleyTotalAsync(tItem); return(user); } catch (Exception ex) { _logger.LogError($"Something went wrong: {ex}"); throw; } }