public async Task NewsResponse_EverythingRequest_NotNull() { var request = new AllNewsRequest("Arrow", SortType.PublishedDate); var result = await _newsClient.FetchNewsAsync(request); Assert.Equal(ResponseStatus.Ok, result.ResponseStatus); Assert.NotNull(result.Articles); }
/// <summary> /// Fetch News from the API. /// </summary> /// <param name="request">Returns news from all sources for an entered request.</param> /// <returns><see cref="NewsResult"/> The result of the search with an IEnumerable collection of articles.</returns> public async Task <NewsResult> FetchNewsAsync(AllNewsRequest request) { var baseUrl = Constants.BaseUrl; var query = RequestFormat.CreateUrl(request, baseUrl); var response = await SendRequestAsync(query); return(GetResult(response)); }
internal static string CreateUrl(AllNewsRequest request, string baseUrl) { baseUrl += "everything?"; baseUrl += $"q={request.Query}"; baseUrl += FormattedDates(request); baseUrl += FormattedSorting(request.SortType); return(baseUrl); }
private static string FormattedDates(AllNewsRequest request) { string formattedDate = ""; if (request.FromDate != null) { formattedDate += string.Format("&from={0:s}", request.FromDate); } if (request.ToDate != null) { formattedDate += string.Format("&to={0:s}", request.ToDate); } return(formattedDate); }