static void Main(string[] args) { string googleKey = "yWje5FlQFHIDjiuRQzVyhVmvn9dSjsPp"; if( args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help"))) { Console.WriteLine("Usage: google.exe <query>\n"); return; } string query = args[0]; // Create a Google SOAP client proxy, generated by: // c:\> wsdl.exe http://api.google.com/GoogleSearch.wsdl GoogleSearchService googleSearch = new GoogleSearchService(); GoogleSearchResult results = googleSearch.doGoogleSearch(googleKey, query, 0, 10, false, "", false, "", "latin1", "latin1"); if (results.resultElements != null) { foreach (ResultElement result in results.resultElements) { Console.WriteLine(); Console.WriteLine(result.title.Replace("<b>", "").Replace("</b>", "")); Console.WriteLine(result.URL); //Console.WriteLine(result.snippet); Console.WriteLine(); } } }
static void Main(string[] args) { string googleKey = "yWje5FlQFHIDjiuRQzVyhVmvn9dSjsPp"; if (args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help"))) { Console.WriteLine("Usage: google.exe <query>\n"); return; } string query = args[0]; // Create a Google SOAP client proxy, generated by: // c:\> wsdl.exe http://api.google.com/GoogleSearch.wsdl GoogleSearchService googleSearch = new GoogleSearchService(); GoogleSearchResult results = googleSearch.doGoogleSearch(googleKey, query, 0, 10, false, "", false, "", "latin1", "latin1"); if (results.resultElements != null) { foreach (ResultElement result in results.resultElements) { Console.WriteLine(); Console.WriteLine(result.title.Replace("<b>", "").Replace("</b>", "")); Console.WriteLine(result.URL); //Console.WriteLine(result.snippet); Console.WriteLine(); } } }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Recipe11_1 [Google Key] [Site to Scan]"); } else { key = args[0]; search = new GoogleSearchService(); List <ResultElement> c = GetResults("\"" + args[1] + "\""); foreach (ResultElement element in c) { StringBuilder str = new StringBuilder(); str.Append(getLinkCount(element.URL)); str.Append(":"); str.Append(element.title); str.Append("("); str.Append(element.URL); str.Append(")"); Console.WriteLine(str.ToString()); } } }
public async Task GoogleSearchTest() { var client = new HttpClient(); var googleService = new GoogleSearchService(client); var result = await googleService.Search("5", "5"); Assert.IsTrue(result.Results.Contains("1, 2")); }
public JsonResult GetIndexes(string url, string keywords) { var testCollection = new List <string>(); var results = new GoogleSearchService(url, keywords).GetSearchIndexes(testCollection); return(Json(new { results = string.Join(", ", results), all = string.Join(Environment.NewLine, testCollection) })); }
public void TestingEmptySearchTerm() { GoogleSearchService gss = new GoogleSearchService(new Search() { SearchQuery = string.Empty }); gss.ProcessingService(); }
static void Main(string[] args) { GoogleSearchService GoogleSearchService = new GoogleSearchService(); BingSearchService BingSearchService = new BingSearchService(); List <SearchResult> SearchResultList = new List <SearchResult>(); Console.Write("What would you like to search for? Write it here: " + Environment.NewLine + Environment.NewLine); string SearchQuery = Console.ReadLine(); var words = Regex.Matches(SearchQuery, @"[\""].+?[\""]|[^ ]+") .Cast <Match>() .Select(m => m.Value) .ToList(); foreach (string word in words) { List <SearchResult> TempSearchResultList = new List <SearchResult>(); TempSearchResultList.Add(GoogleSearchService.GetSearchResult(word)); TempSearchResultList.Add(BingSearchService.GetSearchResult(word)); SearchResultList.AddRange(TempSearchResultList); PrintResult(TempSearchResultList); } string GoogleWinner = GetWinner(SearchResultList, Base.Constants.GOOGLE); string BingWinner = GetWinner(SearchResultList, Base.Constants.BING); long MaxValue = 0; string TotalWinner = ""; foreach (var word in words) { long TempMaxValue = SearchResultList.Where(x => x.SearchQuery.Equals(word)) .Select(y => y.TotalResultsCount).Sum(); if (TempMaxValue > MaxValue) { MaxValue = TempMaxValue; TotalWinner = word; } } Console.WriteLine($"Google Winner: {GoogleWinner}"); Console.WriteLine($"Bing Winner: {BingWinner}"); Console.WriteLine($"Total Winner: {TotalWinner}"); Console.ReadKey(); }
/// <summary> /// Cache button: look up a URL in the Google cache, display size of page /// </summary> private void cacheButton_Click(object sender, System.EventArgs e) { // Create a Google Search object GoogleSearchService s = new GoogleSearchService(); // Invoke the doGetCachedPage method and get the cached bytes System.Byte[] bytes = s.doGetCachedPage(keyBox.Text, cacheBox.Text); // Display the length of the cached page cacheResultLabel.Text = Convert.ToString(bytes.Length); }
public void ProcessingSearchReturnsResults() { GoogleSearchService gss = new GoogleSearchService(new Search() { SearchQuery = searchQuery }); gss.ProcessingService(); Assert.IsTrue(gss.TotalResults > 0); }
/// <summary> /// Search button: do a search, display number of results /// </summary> private void searchButton_Click(object sender, System.EventArgs e) { // Create a Google Search object GoogleSearchService s = new GoogleSearchService(); // Invoke the search method GoogleSearchResult r = s.doGoogleSearch(keyBox.Text, searchBox.Text, 0, 1, false, "", false, "", "", ""); // Extract the estimated number of results for the search and display it int estResults = r.estimatedTotalResultsCount; searchResultLabel.Text = Convert.ToString(estResults); }
public void GoogleSearchService_ReturnsError_BlankURL() { // Arrange var keywords = "conveyancing software"; var url = ""; var service = new GoogleSearchService(); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("URL cannot be blank", result); }
public void GoogleSearchService_ReturnsError_BlankKeywordsAndURL() { // Arrange var keywords = ""; var url = ""; var service = new GoogleSearchService(); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("Keywords cannot be blank" + Environment.NewLine + "URL cannot be blank", result); }
public void GoogleSearchService_ReturnsError_BlankKeywords() { // Arrange var keywords = ""; var url = "www.smokeball.com.au"; var service = new GoogleSearchService(); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("Keywords cannot be blank", result); }
public InfoModule(CommandService service, GoogleSearchService searchService, IConfigService config) { commandService = service; var censoredWords = config.GetValue <IEnumerable <string> >("CensoredWords"); censor = new Censor(censoredWords); halfDaySchedule = config.GetValue <SchoolSchedule>("HalfDaySchedule").ToString(); fullDaySchedule = config.GetValue <SchoolSchedule>("FullDaySchedule").ToString(); this.searchService = searchService; }
public async void GetSearchContent_ReturnsNull_WhenNotFound() { var mockHttp = new MockHttpMessageHandler(); var search = "anything here"; mockHttp.When($"{Host}/search?q={search}&num=100").Respond(HttpStatusCode.NotFound); var httpClient = new HttpClient(mockHttp); var service = new GoogleSearchService(_mockConfig.Object, httpClient); var result = await service.GetSearchContent(search); Assert.Null(result); }
public GoogleSearchServiceTests() { //Arrange var codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase); var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath); var dirPath = Path.GetDirectoryName(codeBasePath); var path = Path.Combine(dirPath, @"Search\ExampleData\GoogleSearchExampleResponse.html"); GoogleSearchResponse = System.IO.File.ReadAllText(path); Mock <IHttpClientFactory> mockFactory = GenerateMockedHTTPMessageHandler(GoogleSearchResponse); subject = new GoogleSearchService(mockFactory.Object); //_bingSearchService = bingSearchService; }
public async void GetSearchContent_ReturnsContent(string content) { var mockHttp = new MockHttpMessageHandler(); var search = "anything here"; mockHttp.When($"{Host}/search?q={search}&num=100").Respond("application/json", content); var httpClient = new HttpClient(mockHttp); var service = new GoogleSearchService(_mockConfig.Object, httpClient); var result = await service.GetSearchContent(search); Assert.NotNull(result); Assert.Equal(result, content); }
/// <summary> /// Handles the Click event of the Search control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> private void Search_Click(object sender, EventArgs e) { string searchText = txtSearchString.Text; GoogleSearchService s = new GoogleSearchService(); /* * s.doGoogleSearch(string license,string query, int start, int maxResults, * bool filter,string restrict,bool safeSearch, string lr, string ie, string oe) */ try { //Overrides following if (restrictToThisDomain.Length != 0 && searchText.IndexOf("site:") == -1) { searchText = searchText += " site:" + restrictToThisDomain.Trim(); } if (searchThisSiteOnly && searchText.IndexOf("site:") == -1) { searchText = searchText += " site:" + (Request.Url.Host); } //debug only //txtSearchString.Text = searchText; int start = (Convert.ToInt32(TextBox2.Text) - 1) * 10; GoogleSearchResult r = s.doGoogleSearch(licKey, searchText, start, maxResults, false, string.Empty, false, string.Empty, string.Empty, string.Empty); // Extract the estimated number of results for the search and display it int estResults = r.estimatedTotalResultsCount; lblHits.Text = Convert.ToString(estResults) + " Results found"; DataSet ds1 = new DataSet(); DataSet ds = FillGoogleDS(ds1, r); DataGrid1.DataSource = ds; DataGrid1.DataBind(); } catch (Exception ex) { lblHits.Text = ex.Message; return; } return; }
public void GetUrlsFromGoogleSearchTest() { // Arrange Mock <IBrowserService> browserServiceMock = new Mock <IBrowserService>(); browserServiceMock.Setup(bs => bs.ScrapeTextInCiteTags()) .Returns(citeTextExample); GoogleSearchService googleSearchService = new GoogleSearchService(browserServiceMock.Object); var keywords = "test"; // Act var urlResults = googleSearchService.GetUrlsFromGoogleSearch(keywords); // Assert CollectionAssert.AreEqual(expectedUrlsExample, urlResults); }
/// <summary> /// Spell button: ask Google for a suggested alternate spelling, display it /// </summary> private void spellButton_Click(object sender, System.EventArgs e) { // Create a Google Search object GoogleSearchService s = new GoogleSearchService(); // Ask for spelling suggestion String suggestion = s.doSpellingSuggestion(keyBox.Text, spellBox.Text); // Display the suggestion, if any if (suggestion == null) { this.spellResultLabel.Text = "<no suggestion>"; } else { this.spellResultLabel.Text = suggestion; } }
public void SetUp() { _mocker = new AutoMoqer(); _searchResult = new SearchResult { Rank = Rank, Url = Url }; _mocker.GetMock <ISearchClient>() .Setup(u => u.SearchAsync(It.IsAny <string>(), It.IsAny <int>())) .ReturnsAsync(new List <SearchResult> { _searchResult }); _googleSearchService = _mocker.Create <GoogleSearchService>(); }
public void GoogleSearchService_ReturnsOK_ValidData() { // Arrange var keywords = "conveyancing software"; var url = "www.smokeball.com.au"; var searcher = new Mock <ISearchEngineSearcher>(); searcher.Setup(s => s.GetSearchResult(It.IsAny <string>())).Returns(TestHelper.GetTextFromFile("GoogleSearchResultForConveyancingSoftware.txt")); var parser = new GoogleParser(); var service = new GoogleSearchService(searcher.Object, parser); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("3", result); }
public void GoogleSearchService_ReturnsError_WithSearchException() { // Arrange var keywords = "conveyancing software"; var url = "www.smokeball.com.au"; var searcher = new Mock <ISearchEngineSearcher>(); searcher.Setup(s => s.GetSearchResult(It.IsAny <string>())).Throws(new Exception("Exception in Searcher")); var parser = new GoogleParser(); var service = new GoogleSearchService(searcher.Object, parser); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("Error with Google Search results: Exception in Searcher", result); }
public void GetUrlsFromGoogleSearch_WhenBrowserServiceThrowsAnException_ShouldReturnEmptyList() { // Arrange Mock <IBrowserService> browserServiceMock = new Mock <IBrowserService>(); string url = "www.whatever.com"; browserServiceMock.Setup(bs => bs.NavigateToUrl(url)) .Throws(new System.Exception()); GoogleSearchService googleSearchService = new GoogleSearchService(browserServiceMock.Object); // Act var keywords = "test"; var urlResults = googleSearchService.GetUrlsFromGoogleSearch(keywords); // Assert var expectedUrls = new List <string>(); CollectionAssert.AreEqual(expectedUrls, urlResults); Assert.AreEqual(0, urlResults.Count); }
public void GoogleSearchService_ReturnsError_WithParserException() { // Arrange var keywords = "conveyancing software"; var url = "www.smokeball.com.au"; var searcher = new Mock <ISearchEngineSearcher>(); searcher.Setup(s => s.GetSearchResult(It.IsAny <string>())).Returns(TestHelper.GetTextFromFile("GoogleSearchResultForConveyancingSoftware.txt")); var parser = new Mock <ISearchResultParser>(); parser.Setup(p => p.ParseSearchResultForRanks(It.IsAny <string>(), It.IsAny <string>())).Throws(new Exception("Exception in Parser")); var service = new GoogleSearchService(searcher.Object, parser.Object); // Act var result = service.GetSearchRanks(keywords, url); // Assert Assert.AreEqual("Error with Google Search results: Exception in Parser", result); }
public void Setup() { _googleSearchService = new GoogleSearchService(); }