private async Task<IEnumerable<Location>> GetLocationAsync(string locationText) { Log.Info("GLA", "Getting a location...."); var requestEntity = new ResolveRequest { LookupText = locationText, LocationType = 0, MaxResults = 10, }; // we don't have a PostAsJsonAsync in Android, this is the next best thing... probably a good idea to farm this // out to an extension method, since we'd be using it a LOT. Log.Info("GLA", "Serialising request...."); HttpContent content = new StringContent(JsonConvert.SerializeObject(requestEntity), Encoding.UTF8, "application/json"); Log.Info("GLA", "Hitting OPIA API Proxy with request"); var response = await _client.PostAsync("location/resolve", content); response.EnsureSuccessStatusCode(); Log.Info("GLA", "Request successful: {0}", response.StatusCode); // Ditto on the ReadAsAsync<T> method, we don't have one of those either. Log.Info("GLA", "Reading response...."); string dataString = response.Content.ReadAsStringAsync().Result; Log.Info("GLA", "Deserialising response...."); var result = JsonConvert.DeserializeObject<ResolveResponse>(dataString); Log.Info("GLA", "{0} Resolve: Locations Found: {1}", DateTime.Now.ToString("s"), result.Locations.Count()); return result.Locations; }
public void ResolveRequest_ToString_WithZeroMaxResults_MustThrowArgumentException() { var requestEntity = new ResolveRequest() { MaxResults = 0, }; string expected = requestEntity.ToString(); }
public void ResolveRequest_ToString_WithEmptyLookupText_MustThrowArgumentException() { var requestEntity = new ResolveRequest() { MaxResults = 10, }; string expected = requestEntity.ToString(); }
public async Task<HttpResponseMessage> Resolve(ResolveRequest request) { var result = CheckCacheForEntry<IRequest, ResolveResponse>(request); if (result == null) { Logger.DebugFormat("Getting {0} from web: ", request.ToString()); result = await new OpiaLocationClient().ResolveAsync(request); await StoreResultInCache<IRequest, ResolveResponse>(request, result); } var response = Request.CreateResponse(HttpStatusCode.OK, result); return response; }
public void ResolveRequest_ToString_WithMandatoryValuesSet_MustReturnCorrectQueryString() { var requestEntity = new ResolveRequest { LookupText = "King George Sq., Brisbane", LocationType = LocationType.None, // get us everything: stops, landmarks, etc. MaxResults = 10, }; string expected = string.Format("resolve?input=King%20George%20Sq.%2C%20Brisbane&filter=0&maxResults=10"); string actual = requestEntity.ToString(); Assert.AreEqual(expected, actual); }
public async Task ResolveAsync_MustResolveFreeFormLocationTextAsync() { var requestEntity = new ResolveRequest { LookupText = "Anzac Sq., Brisbane", LocationType = 0, MaxResults = 10 }; var locationClient = new OpiaLocationClient(); var result = await locationClient.ResolveAsync(requestEntity); Assert.IsTrue(result.Locations.Any()); }
public void Resolve_MustResolveFreeFormLocationText() { var requestEntity = new ResolveRequest { LookupText = "Anzac Sq., Brisbane", LocationType = 0, MaxResults = 10 }; var response = _client.PostAsJsonAsync("location/resolve", requestEntity).Result; response.EnsureSuccessStatusCode(); var result = response.Content.ReadAsAsync<ResolveResponse>().Result; Assert.IsTrue(result.Locations.Any()); }