public void NoExcerptReturnsSameDocument() { // Given string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <div>This is some Foobar text</div> </body> </html>"; IDocument document = Substitute.For <IDocument>(); IExecutionContext context = Substitute.For <IExecutionContext>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt("p"); // When excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then context.DidNotReceiveWithAnyArgs().GetDocument((IDocument)null, (string)null); stream.Dispose(); }
public void ExcerptAlternateQuerySelector() { // Given 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>"; IDocument document = Substitute.For<IDocument>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt("div"); // When excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then document.Received(1).Clone(Arg.Any<IEnumerable<KeyValuePair<string, object>>>()); document.Received().Clone(Arg.Is<IEnumerable<KeyValuePair<string, object>>>(x => x.SequenceEqual(new[] { new KeyValuePair<string, object>("Excerpt", "<div>This is some other text</div>") }))); stream.Dispose(); }
public void ExcerptAlternateMetadataKey() { // Given 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>"; IDocument document = Substitute.For <IDocument>(); IExecutionContext context = Substitute.For <IExecutionContext>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt().SetMetadataKey("Baz"); // When excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then context.Received(1).GetDocument(Arg.Any <IDocument>(), Arg.Any <IEnumerable <KeyValuePair <string, object> > >()); context.Received().GetDocument(document, Arg.Is <IEnumerable <KeyValuePair <string, object> > >(x => x.SequenceEqual(new[] { new KeyValuePair <string, object>("Baz", "<p>This is some Foobar text</p>") }))); stream.Dispose(); }
public void ExcerptAlternateMetadataKey() { // Given 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>"; IDocument document = Substitute.For<IDocument>(); IExecutionContext context = Substitute.For<IExecutionContext>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt().SetMetadataKey("Baz"); // When excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then context.Received(1).GetDocument(Arg.Any<IDocument>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>()); context.Received().GetDocument(document, Arg.Is<IEnumerable<KeyValuePair<string, object>>>(x => x.SequenceEqual(new[] { new KeyValuePair<string, object>("Baz", "<p>This is some Foobar text</p>") }))); stream.Dispose(); }
public void ExcerptAlternateQuerySelector() { // Given 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>"; IDocument document = Substitute.For <IDocument>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt("div"); // When excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then document.Received(1).Clone(Arg.Any <IEnumerable <KeyValuePair <string, object> > >()); document.Received().Clone(Arg.Is <IEnumerable <KeyValuePair <string, object> > >(x => x.SequenceEqual(new[] { new KeyValuePair <string, object>("Excerpt", "<div>This is some other text</div>") }))); stream.Dispose(); }
public void SeparatorInsideParagraphWithSiblings() { // Given 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); TestExecutionContext context = new TestExecutionContext(); Excerpt excerpt = new Excerpt(); // When IEnumerable <IDocument> results = excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then results.Single()["Excerpt"].ToString().ShouldBe( @"<p>This is some Foobar text</p> <p>This <b>is</b> some </p>", StringCompareShould.IgnoreLineEndings); }
public void ExcerptAlternateMetadataKey() { // Given 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>"; IDocument document = Substitute.For<IDocument>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); IEnumerable<KeyValuePair<string, object>> metadata = null; document .When(x => x.Clone(Arg.Any<IEnumerable<KeyValuePair<string, object>>>())) .Do(x => metadata = x.Arg<IEnumerable<KeyValuePair<string, object>>>()); Excerpt excerpt = new Excerpt().SetMetadataKey("Baz"); // When excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then document.Received().Clone(Arg.Any<IEnumerable<KeyValuePair<string, object>>>()); CollectionAssert.AreEqual(new[] { new KeyValuePair<string, object>("Baz", "<p>This is some Foobar text</p>") }, metadata); stream.Dispose(); }
public void SeparatorBetweenParagraphs() { // Given 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> <!-- excerpt --> <p>This is some more text</p> </body> </html>"; IDocument document = Substitute.For <IDocument>(); IExecutionContext context = Substitute.For <IExecutionContext>(); string result = null; context.GetDocument(Arg.Any <IDocument>(), Arg.Any <IEnumerable <KeyValuePair <string, object> > >()) .ReturnsForAnyArgs( x => { result = (string)x.ArgAt <IEnumerable <KeyValuePair <string, object> > >(1) .First(y => y.Key == "Excerpt") .Value; return(null); }); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt(); // When excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then Assert.AreEqual("<p>This is some Foobar text</p>\n <p>This is some other text</p>", result); stream.Dispose(); }
public void NoExcerptReturnsSameDocument() { // Given 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); TestExecutionContext context = new TestExecutionContext(); Excerpt excerpt = new Excerpt("p"); // When IEnumerable <IDocument> results = excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then results.Single().ShouldBe(document); }
public void ExcerptInnerHtml() { // Given 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); TestExecutionContext context = new TestExecutionContext(); Excerpt excerpt = new Excerpt().WithOuterHtml(false); // When IEnumerable <IDocument> results = excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then results.Single()["Excerpt"].ShouldBe("This is some Foobar text"); }
public void MultipleSeparatorComments() { // Given 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); TestExecutionContext context = new TestExecutionContext(); Excerpt excerpt = new Excerpt(); // When IEnumerable <IDocument> results = excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then results.Single()["Excerpt"].ShouldBe("<p>This is some </p>"); }
public void 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); TestExecutionContext context = new TestExecutionContext(); Excerpt excerpt = new Excerpt("div"); // When IEnumerable <IDocument> results = excerpt.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then results.Single()["Excerpt"].ShouldBe("<div>This is some other text</div>"); }
public void NoExcerptReturnsSameDocument() { // Given string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <div>This is some Foobar text</div> </body> </html>"; IDocument document = Substitute.For<IDocument>(); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); document.GetStream().Returns(stream); Excerpt excerpt = new Excerpt("p"); // When excerpt.Execute(new[] { document }, null).ToList(); // Make sure to materialize the result list // Then document.DidNotReceiveWithAnyArgs().Clone((string)null); stream.Dispose(); }