예제 #1
0
            public void GetsDeeperLevels()
            {
                // Given
                string    input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Foo</h1>
                            <h2>Baz</h2>
                            <h1>Bar</h1>
                        </body>
                    </html>";
                IDocument document = new TestDocument
                {
                    Content = input
                };
                IExecutionContext context  = new TestExecutionContext();
                Headings          headings = new Headings(3);

                // When
                List <IDocument> results = headings.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                CollectionAssert.AreEqual(
                    new[] { "Foo", "Baz", "Bar" },
                    results[0].DocumentList(HtmlKeys.Headings).Select(x => x.Content).ToArray());
            }
예제 #2
0
            public void DoesNotSetHeadingMetadataIfNull()
            {
                // Given
                string    input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Foo</h1>
                            <h1>Bar</h1>
                        </body>
                    </html>";
                IDocument document = new TestDocument
                {
                    Content = input
                };
                IExecutionContext context  = new TestExecutionContext();
                Headings          headings = new Headings();

                // When
                List <IDocument> results = headings.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then

                CollectionAssert.AreEqual(
                    new string[] { null, null },
                    results[0].DocumentList(HtmlKeys.Headings).Select(x => x.String("HContent")).ToArray());
            }
예제 #3
0
            public void SetsHeadingIdAttribute()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Foo</h1>
                            <h1 id=""bar"">Bar</h1>
                        </body>
                    </html>";
                IDocument    document = new TestDocument
                {
                    Content = input
                };
                IExecutionContext context  = new TestExecutionContext();
                Headings          headings = new Headings();

                // When
                List <IDocument> results = headings.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                CollectionAssert.AreEqual(
                    new[] { null, "bar" },
                    results[0].DocumentList(HtmlKeys.Headings).Select(x => x.String(HtmlKeys.Id)).ToArray());
            }