private IEnumerable <Task <WebResponse> > SubmitWebRequests(string keywords)
        {
            if (string.IsNullOrWhiteSpace(keywords))
            {
                throw new ReadableException($"Keywords must not be null or whitespace.");
            }

            if (totalResults < pageSize || (totalResults % pageSize != 0))
            {
                throw new ReadableException("Total results must be >= page size and equally divisible!");
            }

            var webRequestTasks   = new List <Task <WebResponse> >();
            var delimitedKeywords = GoogleStringUtilities.ConvertKeywordsToSearchTerms(keywords);
            var pagesToSearch     = totalResults / pageSize;

            for (var pageIndex = 0; pageIndex < pagesToSearch; pageIndex++)
            {
                string uri          = $"{baseSearchableUrl}{delimitedKeywords}&start={pageIndex * pageSize}";
                var    request      = (HttpWebRequest)WebRequest.Create(uri);
                var    responseTask = request.GetResponseAsync();
                webRequestTasks.Add(responseTask);
            }

            return(webRequestTasks);
        }
        public void ConvertKeywordsToSearchTerms_ReturnsOriginalKeyword_GivenSingleKeyword()
        {
            var keywords = "online";

            var result = GoogleStringUtilities.ConvertKeywordsToSearchTerms(keywords);

            Assert.IsTrue(string.Equals(result, "online", StringComparison.InvariantCultureIgnoreCase));
        }
        public void ConvertKeywordsToSearchTerms_ReturnsDelimitedKeywords_GivenMultipleSpaceSeparatedKeywords()
        {
            var keywords = "online title search";

            var result = GoogleStringUtilities.ConvertKeywordsToSearchTerms(keywords);

            Assert.IsTrue(string.Equals(result, "online+title+search", StringComparison.InvariantCultureIgnoreCase));
        }
 public void ConvertKeywordsToSearchTerms_ThrowsReadableException_GivenNoKeywords(string keywords)
 {
     var result = GoogleStringUtilities.ConvertKeywordsToSearchTerms(keywords);
 }