public async Task <IActionResult> Index([FromQuery] string query, [FromQuery] int results = 20)
        {
            try
            {
                var queryResult = await _mediator.Send(new GetLocationsQuery
                {
                    Query       = query,
                    ResultCount = results
                });

                if (queryResult.SuggestedLocations == null)
                {
                    return(Ok(new GetLocationsListResponse {
                        Locations = new List <GetLocationsListItem>()
                    }));
                }

                var response = new GetLocationsListResponse
                {
                    Locations = queryResult.SuggestedLocations.Select(c => (GetLocationsListItem)c).ToList()
                };

                return(Ok(response));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Unable to get location data for {query} - number of results {results}");
                return(BadRequest());
            }
        }
Beispiel #2
0
        public async Task Then_Gets_Locations_From_Location_Api(
            GetLocationsQuery query,
            GetLocationsListResponse apiResponse,
            [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockApiClient,
            GetLocationsQueryHandler handler)
        {
            mockApiClient
            .Setup(client => client.Get <GetLocationsListResponse>(
                       It.Is <GetLocationsQueryRequest>(c => c.GetUrl.Contains(query.SearchTerm))))
            .ReturnsAsync(apiResponse);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Locations.Should().BeEquivalentTo(apiResponse.Locations);
        }