/// <summary> /// Creates a new SearchEngineOrchestrator instance. /// </summary> /// <param name="searchEngineDefinition">The ISearchEngineDefinition with which this orchestrator is associated.</param> /// <param name="httpClientHelperProvider">An IHttpClientHelperProvider to be used by this instance.</param> public SearchEngineOrchestrator(ISearchEngineDefinition <T> searchEngineDefinition, IHttpClientHelperProvider httpClientHelperProvider) { this.searchEngineDefinition = searchEngineDefinition ?? throw new ArgumentNullException(nameof(searchEngineDefinition)); if (httpClientHelperProvider == null) { throw new ArgumentNullException(nameof(httpClientHelperProvider)); } // Create a properly-configured HttpClientHelper instance. var defaultHeaders = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(searchEngineDefinition.UserAgentString)) { defaultHeaders.Add("User-Agent", searchEngineDefinition.UserAgentString); } httpClientHelper = httpClientHelperProvider.GetHttpClientHelper(); httpClientHelper.SetDefaultRequestHeaders(defaultHeaders); }
public void Initialize() { mockHtmlDocument.LoadHtml("<html><body><p>Text</p></body></html>"); var mockResults = new List <SimpleSearchResult> { new SimpleSearchResult("Test Page 1", new Uri("http://www.google.com"), 1) }; var mockResultScraper = Substitute.For <ISearchResultScraper <ISimpleSearchResult> >(); mockResultScraper.ScrapeResults(Arg.Any <HtmlDocument>(), Arg.Any <int>()).Returns(mockResults); mockSearchEngineDefinition = Substitute.For <ISearchEngineDefinition <ISimpleSearchResult> >(); mockSearchEngineDefinition.UriFormat.Returns("http://www.google.com/{0}"); mockSearchEngineDefinition.ResultScraper.Returns(mockResultScraper); mockHttpClientHelper = Substitute.For <IHttpClientHelper>(); mockHttpClientHelperProvider = Substitute.For <IHttpClientHelperProvider>(); mockHttpClientHelperProvider.GetHttpClientHelper().Returns(mockHttpClientHelper); testInstance = new SearchEngineOrchestrator <ISimpleSearchResult>(mockSearchEngineDefinition, mockHttpClientHelperProvider); }