public void GetSearchRequestUriWithQueryString_ValidInputs_ReturnsCorrectly() { // Arrange string expected = "search?limit=30&term=dog"; string inputEndpoint = "search"; string inputTerm = "dog"; int inputLimit = 30; // Act string actual = DadJokeServiceHelpers.GetSearchRequestUriWithQueryString(inputEndpoint, inputTerm, inputLimit); // Assert Assert.AreEqual(expected, actual); }
/// <summary> /// Gets a collection of jokes by the search term provided. Supports multiple search terms, split by whitespaces. /// An OR operation is used by the API if more than one term is given. /// </summary> /// <param name="searchTerm">The term to search for jokes with.</param> /// <param name="limit">The maximum number of search results to return. Default is 30.</param> /// <returns>Collection of jokes that contain the search term provided.</returns> public async Task <JokeSearchResponse> GetBySearchTerm(string searchTerm, int limit = 30) { var responseMessage = await _httpClient.GetAsync( DadJokeServiceHelpers.GetSearchRequestUriWithQueryString(_endpointGetBySearchTerm, searchTerm, limit)); responseMessage.EnsureSuccessStatusCode(); string content = await responseMessage.Content.ReadAsStringAsync(); var jokeSearchReponse = JsonConvert.DeserializeObject <JokeSearchResponse>(content); if (searchTerm != null) { // Account for cases where there are two or more terms in the search term string[] searchTermSplit = searchTerm.Split(' ', StringSplitOptions.RemoveEmptyEntries); jokeSearchReponse.Results = DadJokeServiceHelpers.EmphasizeWithUppercase(jokeSearchReponse.Results, searchTermSplit); } jokeSearchReponse.ResultsBySize = DadJokeServiceHelpers.GroupByJokeSize(jokeSearchReponse.Results); return(jokeSearchReponse); }