public async Task <List <Category> > GetCategoryListAsync() { string uri = Secrets.BASE_API_ENDPOINT + "Categories"; List <Category> categoryList = await _httpConnection.GetAsync <List <Category> >(uri); return(categoryList.OrderBy(c => c.Name).ToList()); }
public async Task ServiceCorrectlyCreatesUrlForGivenLocation() { _httpConnectionMock.GetAsync(Arg.Any <string>()).Returns(x => Task.FromResult((string)x[0])); var result = await _sut.GetWeatherForNamedLocationAsync("Warsaw"); result.Should().Be("https://api.openweathermap.org/data/2.5/weather?q=Warsaw"); }
public async Task <string> GetWeatherForNamedLocationAsync(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Argument name was null or empty."); } var url = AppendUrl(name); var result = await _connection.GetAsync(url); return(result); }
internal virtual async Task <IHttpConnectionResponse> GetAsync(HttpConnectionRequest request, CancellationToken cancellationToken) { IHttpConnection connection = this._httpConnectionFactory.CreateHttpConnection(); Uri requestUrl = request.Url; Uri url = requestUrl; int retry = 0; IHttpConnectionResponse response; string location; do { await connection.ConnectAsync(request.Proxy ?? url, cancellationToken).ConfigureAwait(false); request.Url = url; response = await connection.GetAsync(request, true, cancellationToken).ConfigureAwait(false); request.Url = requestUrl; IHttpStatus status = response.Status; if (HttpStatusCode.Moved == status.StatusCode || HttpStatusCode.Found == status.StatusCode) { if (++retry < 8) { connection.Close(); location = Enumerable.FirstOrDefault <string>(response.Headers["Location"]); } else { goto label_5; } } else { goto label_3; } }while (Uri.TryCreate(request.Url, location, out url)); goto label_7; label_3: IHttpConnectionResponse connectionResponse = response; goto label_9; label_5: connectionResponse = response; goto label_9; label_7: connectionResponse = response; label_9: return(connectionResponse); }