public async Task SetsChildrenWhenNotNesting() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Foo</h1> <h2>Baz</h2> <h2>Boz</h2> <h1>Bar</h1> <h2>Boo</h2> </body> </html>"; TestDocument document = new TestDocument(input); GatherHeadings headings = new GatherHeadings(3); // When IDocument result = await ExecuteAsync(document, headings).SingleAsync(); // Then result.GetDocumentList(HtmlKeys.Headings).Cast <TestDocument>().Select(x => x.Content).ShouldBe(new[] { "Foo", "Baz", "Boz", "Bar", "Boo" }); result.GetDocumentList(HtmlKeys.Headings)[0].GetDocumentList(Keys.Children).Cast <TestDocument>().Select(x => x.Content).ShouldBe(new[] { "Baz", "Boz" }); result.GetDocumentList(HtmlKeys.Headings)[3].GetDocumentList(Keys.Children).Cast <TestDocument>().Select(x => x.Content).ShouldBe(new[] { "Boo" }); }
public async Task DoesNotSetHeadingMetadataIfNull() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Foo</h1> <h1>Bar</h1> </body> </html>"; TestDocument document = new TestDocument(input); GatherHeadings headings = new GatherHeadings(); // When IDocument result = await ExecuteAsync(document, headings).SingleAsync(); // Then result.GetDocumentList(HtmlKeys.Headings).Select(x => x.GetString("HContent")).ShouldBe(new string[] { null, null }); }
public async Task SetsHeadingIdAttribute() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Foo</h1> <h1 id=""bar"">Bar</h1> </body> </html>"; TestDocument document = new TestDocument(input); GatherHeadings headings = new GatherHeadings(); // When IDocument result = await ExecuteAsync(document, headings).SingleAsync(); // Then result.GetDocumentList(HtmlKeys.Headings).Select(x => x.GetString(HtmlKeys.HeadingId)).ShouldBe(new[] { null, "bar" }); }
public async Task OnlyGetsFirstLevelByDefault() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Foo</h1> <h2>Baz</h2> <h1>Bar</h1> </body> </html>"; TestDocument document = new TestDocument(input); GatherHeadings headings = new GatherHeadings(); // When IDocument result = await ExecuteAsync(document, headings).SingleAsync(); // Then result.GetDocumentList(HtmlKeys.Headings).Cast <TestDocument>().Select(x => x.Content).ShouldBe(new[] { "Foo", "Bar" }); }