示例#1
0
		private async Task<IList<Restaurant>> GetRestaurantFromAPI(string outcode)
		{
			JustEATResponse result = new JustEATResponse();
			_httpClient.BaseAddress = new Uri(ConfigurationManager.AppSettings["JustEATUrl"]);
			AddHttpClientRequestHeaders();
			HttpResponseMessage response = await _httpClient.GetAsync(string.Format("{0}?q={1}", 
				ConfigurationManager.AppSettings["RestaurantEndPoint"], outcode));
			if (response.IsSuccessStatusCode)
			{
				result = await response.Content.ReadAsAsync<JustEATResponse>();
			}
			return result.Restaurants;
		}
        private JustEATResponse CreateFakeResponse(string outcode)
        {
            JustEATResponse result = new JustEATResponse()
            {
                ShortResultText = outcode,
                Restaurants = new List<Restaurant>()
            };

            IList<CuisineType> types = new List<CuisineType>();
            types.Add(new CuisineType()
                {
                    Name = "Indian"
                });
            result.Restaurants.Add(new Restaurant()
                {
                    Name = "Restaurant1",
                    RatingStars = 5,
                    NumberOfRatings = 10,
                    CuisineTypes = types
                });
            return result;
        }