public async Task SeparatorInsideParagraphWithSiblings() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <p>This <b>is</b> some <!-- excerpt --><i>other</i> text</p> </body> </html>"; TestDocument document = new TestDocument(input); GenerateExcerpt excerpt = new GenerateExcerpt(); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result["Excerpt"].ToString().ShouldBe( @"<p>This is some Foobar text</p> <p>This <b>is</b> some </p>", StringCompareShould.IgnoreLineEndings); }
public async Task KeepsExisting() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <p>This is some other text</p> </body> </html>"; TestDocument document = new TestDocument(input) { { HtmlKeys.Excerpt, "Foobar" } }; GenerateExcerpt excerpt = new GenerateExcerpt(); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result["Excerpt"].ShouldBe("Foobar"); }
public void Removes_Html_Tags(string input, string expected) { // Arrange // Act var result = GenerateExcerpt.Create().Execute(input); // Assert Assert.Equal(expected, result); }
public void Removes_Square_Brackets_Without_Content(string options) { // Arrange var shortcode = Rnd.Str; var input = $"[{shortcode}{Environment.NewLine}{options}]"; // Act var result = GenerateExcerpt.Create().Execute(input); // Assert Assert.Equal(string.Empty, result); }
public void Removes_Multiple_Spaces_And_Trims() { // Arrange var t0 = Rnd.Str; var t1 = Rnd.Str; var input = $" {t0} {t1} "; // Act var result = GenerateExcerpt.Create().Execute(input); // Assert Assert.Equal($"{t0} {t1}", result); }
public void With_More_Cuts_At_More() { // Arrange var t0 = Rnd.Str; var t1 = Rnd.Str; var input = $"{t0}<!--more-->{t1}"; // Act var result = GenerateExcerpt.Create().Execute(input); // Assert Assert.Equal(t0, result); }
public void Removes_New_Lines(string newline) { // Arrange var t0 = Rnd.Str; var t1 = Rnd.Str; var input = t0 + newline + t1; // Act var result = GenerateExcerpt.Create().Execute(input); // Assert Assert.Equal($"{t0} {t1}", result); }
public async Task NoExcerptReturnsSameDocument() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <div>This is some Foobar text</div> </body> </html>"; TestDocument document = new TestDocument(input); GenerateExcerpt excerpt = new GenerateExcerpt("p"); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result.ShouldBe(document); }
public async Task ExcerptInnerHtml() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <p>This is some other text</p> </body> </html>"; TestDocument document = new TestDocument(input); GenerateExcerpt excerpt = new GenerateExcerpt().WithOuterHtml(false); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result["Excerpt"].ShouldBe("This is some Foobar text"); }
public async Task ExcerptAlternateQuerySelector() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <div>This is some other text</div> </body> </html>"; TestDocument document = new TestDocument(input); GenerateExcerpt excerpt = new GenerateExcerpt("div"); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result["Excerpt"].ShouldBe("<div>This is some other text</div>"); }
public async Task MultipleSeparatorComments() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some <!-- excerpt --> Foobar text</p> <p>This is <!-- excerpt --> other text</p> </body> </html>"; TestDocument document = new TestDocument(input); GenerateExcerpt excerpt = new GenerateExcerpt(); // When TestDocument result = await ExecuteAsync(document, excerpt).SingleAsync(); // Then result["Excerpt"].ShouldBe("<p>This is some </p>"); }