Beispiel #1
0
        public void ParseNoAuthorHtml()
        {
            var context = TestUtilites.ExecuteExtractor(HtmlWithNoAuthor, new AuthorsExtractor());

            context.Authors
            .Should()
            .HaveCount(0);
        }
Beispiel #2
0
        public void ParseTwoAuthorHtml()
        {
            var context = TestUtilites.ExecuteExtractor(HtmlWithTwoAuthor, new AuthorsExtractor());

            context.Authors
            .Should()
            .HaveCount(2)
            .And
            .Contain("John Smith", "Bill Gates");
        }
Beispiel #3
0
        public void ParseOneAuthorHtml()
        {
            var context = TestUtilites.ExecuteExtractor(HtmlWithAuthor, new AuthorsExtractor());

            context.Authors
            .Should()
            .HaveCount(1)
            .And
            .Contain("John Smith");
        }
Beispiel #4
0
        public void ShouldExtractFromTitleTag()
        {
            var htmlContent  = string.Format(TitleTagTemplate, "my title");
            var htmlDocument = TestUtilites.CreateHtmlDocument(htmlContent);
            var context      = new ExtractorContext(htmlDocument);

            var extractor = new TitleExtractor();

            extractor.Execute(context);

            context.Title.Should().Be("my title");
        }
Beispiel #5
0
        public void ParseSimpleHtml()
        {
            var htmlDocument = TestUtilites.CreateHtmlDocument(HtmlWithOpenGraph);
            var context      = new ExtractorContext(htmlDocument);

            var extractor = new OpengraphExtractor();

            extractor.Execute(context);

            context.OpenGraph.Should().ContainKeys("title", "type", "url", "image");

            context.OpenGraph["title"].Should().Be("The Rock");
            context.OpenGraph["type"].Should().Be("video.movie");
            context.OpenGraph["url"].Should().Be("http://www.imdb.com/title/tt0117500/");
            context.OpenGraph["image"].Should().Be("http://ia.media-imdb.com/images/rock.jpg");
        }
Beispiel #6
0
        public void ShouldExtractFromOpenGraph(string title, string expectedTitle)
        {
            var htmlDocument = TestUtilites.CreateHtmlDocument("<html></hmtl>");
            var context      = new ExtractorContext(htmlDocument)
            {
                OpenGraph = new Dictionary <string, string>()
                {
                    { "title", title },
                    { "site_name", "hi" }
                },
                Domain = "www.example.com"
            };

            var extractor = new TitleExtractor();

            extractor.Execute(context);

            context.Title.Should().Be(expectedTitle);
        }