Exemplo n.º 1
0
            public void Given_FunctionalTag_Should_Return_EmptyString(string tagName)
            {
                //Arrange
                string html    = $"<{tagName}>it doesn't matter what you put here</{tagName}>";
                var    service = new HtmlParserService();

                //Act
                var result = service.GetVisibleText(html);

                //Assert
                Assert.Equal(string.Empty, result);
            }
Exemplo n.º 2
0
        public async Task Parser_should_get_html_nodes()
        {
            // Arrange
            HtmlParserService sut = new HtmlParserService(_avanzaUrl);
            await sut.Initialise();

            // Act
            var result = sut.GetAllTickers();

            // Assert
            result.Should().NotBeEmpty();
        }
Exemplo n.º 3
0
            public void Given_MultipleWhitespacesBetweenWords_Should_Return_SingleWhitespaceBetweenWords()
            {
                //Arrange
                string multipleWhitepaces = "french   croissant";
                string singleWhitespace   = "french croissant";
                var    service            = new HtmlParserService();

                //Act
                var result = service.GetVisibleText(multipleWhitepaces);

                //Assert
                Assert.Equal(singleWhitespace, result);
            }
Exemplo n.º 4
0
            public void Given_SimpleTag_Should_Return_VisibleText()
            {
                //Arrange
                string visibleText = "The Story";
                string html        = $"<h1>{visibleText}<h1>";
                var    service     = new HtmlParserService();

                //Act
                var result = service.GetVisibleText(html);

                //Assert
                Assert.Equal(visibleText, result);
            }
Exemplo n.º 5
0
            public void Given_MultilineHtml_Should_Return_OnelineVisibleText()
            {
                //Arrange
                string visibleText        = "The Story\nbegins long ago\nin a faraway kingdom";
                string onelineVisibleText = "The Story begins long ago in a faraway kingdom";
                string html    = $"<h1>{visibleText}<h1>";
                var    service = new HtmlParserService();

                //Act
                var result = service.GetVisibleText(html);

                //Assert
                Assert.Equal(onelineVisibleText, result);
            }
Exemplo n.º 6
0
            public void Given_SimpleTag_With_HtmlEntities_Should_Return_EncodedVisibleText()
            {
                //Arrange
                string encodedVisibleText = "&#165;1234";
                string decodedVisibleText = "¥1234";
                string html    = $"<h1>{encodedVisibleText}<h1>";
                var    service = new HtmlParserService();

                //Act
                var result = service.GetVisibleText(html);

                //Assert
                Assert.Equal(decodedVisibleText, result);
            }
Exemplo n.º 7
0
        public async void ReplacePeopleNames_WhenHttpClientRequestDoesNotSucceed_ReturnsEmptyString()
        {
            //Arrange
            var httpMessageHandlerMock = TestingHelper.MockHttpMessageHandlerReturnsErrorStatusCode();
            var httpClient             = new HttpClient(httpMessageHandlerMock)
            {
                BaseAddress = new Uri("http://nowebsite.com/")
            };

            var htmlParserService = new HtmlParserService(httpClient);

            //Act
            var actualHtml = await htmlParserService.ReplacePeopleNames("//div//h1");

            //Assert
            Assert.True(string.IsNullOrEmpty(actualHtml));
        }
Exemplo n.º 8
0
        public async void ReplacePeopleNames_WhenSelectorIsNotValid_ReturnsOriginalHtml()
        {
            //Arrange
            var expectedHtml = @"<html>
            <body>
                <div><h1>List of People Names</h1></div>
                <div class=""people-names"">
                <ul>
                    <li>Aaron</li>
                    <li>Adam</li>
                    <li>Bryan</li>
                    <li>Bob</li>
                    <li>Cameron</li>
                    <li>Cathie</li>
                    <li>John</li>
                    <li>Kelly</li>
                    <li>Tony</li>
                </ul>
                </div>
            </body>
            </html>";

            var httpMessageHandlerMock = TestingHelper.MockHttpMessageHandlerReturnsSuccessStatusCode(expectedHtml);
            var httpClient             = new HttpClient(httpMessageHandlerMock)
            {
                BaseAddress = new Uri("http://nowebsite.com/")
            };

            var htmlParserService = new HtmlParserService(httpClient);

            //Act
            var actualHtml = await htmlParserService.ReplacePeopleNames("//div[@class='i-dont-exist']//ul//li");

            //Assert
            Assert.NotNull(actualHtml);
            Assert.Equal(expectedHtml.Trim(), actualHtml.Trim());
        }
 public YandexTaxiDataAnalyzerCore(ImapService imapService, HtmlParserService htmlParserService)
 {
     _imapService       = imapService;
     _htmlParserService = htmlParserService;
 }
Exemplo n.º 10
0
 public ValuesController(HtmlParserService htmlParserService)
 {
     _htmlParserService = htmlParserService;
 }
 public HtmlParserServiceTests()
 {
     _htmlParserService = new HtmlParserService();
 }