private async void OnSearchPressed(object sender, EventArgs e) { SearchBar searchBar = (SearchBar)sender; EbaySearch search = new EbaySearch(searchBar.Text); string json = JsonConvert.SerializeObject(search); HttpResponseMessage response = await GetProduct.GetProducts(json); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); Products = JsonConvert.DeserializeObject <List <Product> >(response_content); MyCollectionView.ItemsSource = Products; } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Try Again!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } }
public void TestGetJson() { search = new EbaySearch(ht, apiKey); JObject data = search.GetJson(); Assert.IsTrue(search.IsApiKeySet()); Assert.AreEqual(data["search_metadata"]["status"], "Success"); JArray coffeeShops = (JArray)data["organic_results"]; Assert.IsNotNull(coffeeShops); foreach (JObject coffeeShop in coffeeShops) { Console.WriteLine("Found: " + coffeeShop["title"]); Assert.IsNotNull(coffeeShop["title"]); } }