public void SearchTest_Invalid() { // Mock the WebPageUtility var mockedWebPageUtility = new MockedWebPageUtility("..\\..\\SampleData\\InvalidFile.txt"); // Create the searcher and pass the mocked utility var searcher = new GoogleSearcher(mockedWebPageUtility); var results = searcher.Search("Google Australia", new SearchQuery("latest space exploration", "www.space.com"), 100); // Check number of results and rank Assert.AreEqual(0, results.Count); }
public void SearchTest_1Result() { // Mock the WebPageUtility var mockedWebPageUtility = new MockedWebPageUtility("..\\..\\SampleData\\LSE_100Results.txt"); // Create the searcher and pass the mocked utility var searcher = new GoogleSearcher(mockedWebPageUtility); var results = searcher.Search("Google Australia", new SearchQuery("latest space exploration", "www.nasa.gov"), 100); // Check number of results and rank Assert.AreEqual(1, results.Count); Assert.AreEqual(6, results[0].RankPosition); }
public async Task SearchTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cancellationToken = cancellationTokenSource.Token; using var searcher = new GoogleSearcher(); var results = await searcher.SearchAsync("Hello, world!", cancellationToken); Console.WriteLine("Results:"); foreach (var result in results) { Console.WriteLine($" - {result.Url} {result.Description}"); } Assert.AreNotEqual(0, results.Count, nameof(results.Count)); }
public async Task GetContent_ShouldReturnNullDueToNotSuccessfulResponse() { var httpClientMock = new Mock <IHttpClientWrapper>(); var expectedData = "testData"; httpClientMock.Setup(x => x.GetAsync(It.IsAny <string>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(expectedData) }); var searcher = new GoogleSearcher(httpClientMock.Object); var result = await searcher.GetContent("test"); httpClientMock.Verify(x => x.GetAsync(It.IsAny <string>()), Times.Once); Assert.Null(result); }
public async Task TorrentTest() { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5)); var cancellationToken = cancellationTokenSource.Token; using var runner = CreateTorrentRunner(); if (!File.Exists(runner.QBitTorrentPath)) { Assert.Inconclusive("QBitTorrent is not installed."); } runner.CommandReceived += (_, command) => Console.WriteLine($"{command}"); runner.AsyncCommandReceived += async(_, command, token) => { Console.WriteLine($"{command}"); using var searcher = new GoogleSearcher(); var results = await searcher.SearchAsync(command.Input.Argument, token); return(new IValue[] { new Value(results.Select(result => result.Url).ToArray()) }); }; await runner.TorrentAsync("красотка", cancellationToken); }
public void Initialize() { googleSearcher = A.Fake <GoogleSearcher>(); }