Example #1
0
        public void it_should_return_correct_result()
        {
            // setup
            var givenHtmlString = "<html><body><div><a href=\'www.facebook.com\'/></div><div class=\'g\'><a href=\'www.facebook.com\'/></div><div class=\'g\'><a href=\'www.woolworths.com.au\'/></div><div><a href=\'www.facebook.com\'/></div><div class=\'g\'><a href=\'www.facebook.com\'/></div></body></html>";
            var givenTarget     = "www.facebook.com";

            // act
            var result = _htmlProcessor.GetSearchPositions(givenHtmlString, givenTarget).ToList();

            // assert
            Assert.Equal(2, result.Count);
            Assert.Equal(0, result[0]);
            Assert.Equal(2, result[1]);
        }
Example #2
0
        public async Task <IEnumerable <int> > Handle(GetSearchPositionsQuery request, CancellationToken cancellationToken)
        {
            var response = await _searchService.GetHtmlString($"/search?num={_searchSetting.Value.ResultNumber}&q={request.Keyword}");

            var result = _htmlProcessor.GetSearchPositions(response, request.TargetUrl).ToList();

            return(result);
        }