示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
        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);
        }
示例#5
0
        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>();
 }