Esempio n. 1
0
        public async Task start_date_is_ahead_of_end_date_throw_exception()
        {
            var startDate = new DateTime(2019, 8, 10, 9, 0, 0); //hour ahead of end date
            var endDate   = new DateTime(2019, 8, 10, 8, 0, 0);

            await Assert.ThrowsAsync <ArgumentException>(async() =>
                                                         await _service.GetByDate(startDate, endDate));
        }
        public async Task <IActionResult> Post(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "queries")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            if (req == null)
            {
                return(new NotFoundObjectResult("Null HttpRequest"));
            }

            string requestBody = await _readerService.ReadToEndAsync(req.Body);

            if (string.IsNullOrEmpty(requestBody))
            {
                return(new BadRequestObjectResult("Could not find Start Date or End date"));
            }

            var data = _jsonConverter.DeserializeObject <VehicleQueryRequest>(requestBody);

            if (data == null)
            {
                return(new BadRequestObjectResult("VehicleQueryrequest is null after deserialization"));
            }

            try
            {
                var result = await _vehicleQueryService.GetByDate(data.StartDate, data.EndDate);

                //Send Email
                var msg = _emailService.Create(result);
                if (msg == null)
                {
                    log.LogWarning("Error creating Email");
                }
                var response = await _emailService.Send(msg);

                log.LogInformation($"Output Response: {response.Success} - {response.Message}. Number of Queries: {result.NumberOfQueries}");

                return(new OkObjectResult(result));
            }
            catch (Exception e)
            {
                log.LogInformation($"Exception occured. {e.Message}");
                throw e;
            }
        }