Esempio n. 1
0
            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();
            }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
            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();
            }
Esempio n. 4
0
            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();
            }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
            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);
            }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
            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();
            }
Esempio n. 9
0
            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);
            }
Esempio n. 10
0
            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");
            }
Esempio n. 11
0
            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>");
            }
Esempio n. 12
0
            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>");
            }
Esempio n. 13
0
        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();
        }