Beispiel #1
0
        public void Api_Submit_ValidLocationRequest_ReturnsCorrectWoeid(string cityName,
                                                                        int expectedCount,
                                                                        int expectedWoeid,
                                                                        ApiProxy apiProxy,
                                                                        ILocationRequest locationRequest,
                                                                        ILocationResponse locationResponse)
        {
            $"Given a cityName value of {cityName}"
            .x(() => locationRequest = new LocationRequest {
                CityName = cityName
            });

            "And an ApiProxy"
            .x(() => apiProxy = new ApiProxy(_metaWeatherService));

            "When the location request is submitted"
            .x(async() => locationResponse =
                   await apiProxy.SubmitLocationRequest(locationRequest).ConfigureAwait(false));

            $"Then the location response should return HttpStatusCode.OK), CityName {cityName} and WoeId {expectedWoeid}"
            .x(() =>
            {
                using (new AssertionScope())
                {
                    locationResponse.StatusCode.Should().Be(HttpStatusCode.OK);
                    locationResponse.Locations.Should().HaveCount(expectedCount);
                    locationResponse.Locations[0].WoeId.Should().Be(expectedWoeid);
                }
            });
        }
Beispiel #2
0
        public async Task <LocationResponse> SubmitLocationRequest(ILocationRequest locationRequest)
        {
            try
            {
                using (var apiResponse = await _metaWeatherService.GetLocationByCityName(locationRequest.CityName)
                                         .ConfigureAwait(false))
                {
                    if (!apiResponse.IsSuccessStatusCode)
                    {
                        return(new LocationResponse {
                            StatusCode = apiResponse.StatusCode, Locations = null
                        });
                    }

                    if (apiResponse.Content.Count == 0)
                    {
                        return(new LocationResponse {
                            StatusCode = HttpStatusCode.NotFound, Locations = null
                        });
                    }

                    return(new LocationResponse {
                        StatusCode = HttpStatusCode.OK, Locations = apiResponse.Content
                    });
                }
            } catch (Exception ex) when((ex is ApiException) || (ex is WebException))
            {
                //Here we would Log exception
                return(new LocationResponse {
                    StatusCode = HttpStatusCode.InternalServerError, Locations = null
                });
            }
        }
Beispiel #3
0
        public void Api_Submit_InvalidLocationRequest_ReturnsNotFound(string cityName,
                                                                      ApiProxy apiProxy,
                                                                      ILocationRequest locationRequest,
                                                                      ILocationResponse locationResponse)
        {
            $"Given a cityName value of {cityName}"
            .x(() => locationRequest = new LocationRequest {
                CityName = cityName
            });

            "And an ApiProxy".x(() => apiProxy = new ApiProxy(_metaWeatherService));

            "When the location request is submitted"
            .x(async() => locationResponse =
                   await apiProxy.SubmitLocationRequest(locationRequest).ConfigureAwait(false));

            "Then the location response should return HttpStatusCode.NotFound, and Locations should be empty"
            .x(() =>
            {
                using (new AssertionScope())
                {
                    locationResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
                    locationResponse.Locations.Should().BeNullOrEmpty();
                }
            });
        }
Beispiel #4
0
        public async Task <IEnumerable <IAppUser> > GetNearbyStoresAsync(ILocationRequest Request)
        {
            IEnumerable <IAppUser> Stores = new List <IAppUser>();

            using HttpResponseMessage Res = await Const.GlobalHttpClient.PostAsJsonAsync("Database/nearbystores?NestedTags=Foods", Request);

            if (Res.IsSuccessStatusCode)
            {
                using HttpContent content = Res.Content;
                Stores = await content.ReadAsAsync <IEnumerable <StoreUser> >();
            }
            return(Stores);
        }