Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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);
        }