Пример #1
0
        public async Task <HttpResponseMessage> GetRatings(string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Search query is missing"));
            }

            try
            {
                (HttpStatusCode Status, string Data)result = await WebRequestService.GetRequest($"{api}/beers?beer_name={query}");

                if (result.Status != HttpStatusCode.OK || string.IsNullOrEmpty(result.Data))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadGateway, "Proxy server did not return a valid response"));
                }

                ICollection <BeerItem> beerList = PunkService.GetRating(result.Data);
                if (beerList == null || beerList.Count < 1)
                {
                    return(Request.CreateResponse(HttpStatusCode.NoContent, "Search query did not match any beers"));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, beerList));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #2
0
        public void TestSearchRating()
        {
            string searchResult = @"[{
                ""id"": 1,
                ""name"": ""Buzz"",
                ""tagline"": ""A Real Bitter Experience."",
                ""description"": ""A light, crisp and bitter IPA brewed with English and American hops. A small batch brewed only once.""
            }]";

            ICollection <BeerItem> result = PunkService.GetRating(searchResult);

            Assert.True(result.Count > 0);

            bool beerExists = result.Any(x => x.Id == 1);

            Assert.True(beerExists);
        }