public async Task ReturnsInputDocumentForNoXref()
            {
                // Given
                TestDocument target = new TestDocument(new NormalizedPath("/a/b/c.html"), new NormalizedPath("a/b/c.html"))
                {
                    { WebKeys.Xref, "fizzbuzz" }
                };
                TestExecutionContext context = new TestExecutionContext();

                context.Outputs.Dictionary.Add(
                    nameof(Content),
                    new IDocument[] { target }.ToImmutableArray());
                TestDocument document = new TestDocument(
                    @"<html>
                        <body>
                            Foo
                        </body>
                    </html>");
                ResolveXrefs module = new ResolveXrefs();

                // When
                TestDocument result = await ExecuteAsync(document, context, module).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
Beispiel #2
0
            public async Task DoesNotCloneDocumentIfNothingChanged()
            {
                // 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);
                ConcurrentBag <string> content  = new ConcurrentBag <string>();
                ProcessHtml            process  = new ProcessHtml("p", x => content.Add(x.TextContent));

                // When
                IReadOnlyList <TestDocument> results = await ExecuteAsync(document, process);

                // Then
                content.ShouldBe(
                    new[]
                {
                    "This is some Foobar text",
                    "This is some other text"
                },
                    true);
                TestDocument result = results.ShouldHaveSingleItem();

                result.ShouldBe(document);
            }
Beispiel #3
0
            public async Task OutputsOriginalDocumentForNullContent()
            {
                // Given
                TestDocument   document = new TestDocument("Original");
                ReplaceContent replace  = new ReplaceContent((string)null);

                // When
                TestDocument result = await ExecuteAsync(document, replace).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
            public async Task ContextConfigReturnsDocumentForSingleResultDocument()
            {
                // Given
                TestDocument  document = new TestDocument();
                ExecuteConfig execute  = new ExecuteConfig(Config.FromContext(_ => document));

                // When
                TestDocument result = await ExecuteAsync(Array.Empty <TestDocument>(), execute).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
            public async Task DoesNothingIfMetadataKeyDoesNotExist()
            {
                // Given
                TestDocument   document = new TestDocument();
                RenderMarkdown markdown = new RenderMarkdown("meta");

                // When
                TestDocument result = await ExecuteAsync(document, markdown).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
            public async Task DoesNothingIfMetadataKeyDoesNotExist()
            {
                // Given
                TestDocument     document   = new TestDocument();
                RenderHandlebars handlebars = new RenderHandlebars("meta");

                // When
                TestDocument result = await ExecuteAsync(document, handlebars).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
            public async Task ShouldReturnOriginalDocumentForFailedPredicate()
            {
                // Given
                TestDocument         input      = new TestDocument("Test");
                TestExecutionContext context    = GetExecutionContext(input.Yield());
                WriteFiles           writeFiles = new WriteFiles().Where(false);

                // When
                TestDocument result = await ExecuteAsync(context, writeFiles).SingleAsync();

                // Then
                result.ShouldBe(input);
            }
            public async Task ReturnsDocumentOnError()
            {
                // Given
                TestDocument         document = new TestDocument("asdf");
                ParseJson            json     = new ParseJson("MyJson");
                TestExecutionContext context  = new TestExecutionContext(document);

                context.TestLoggerProvider.ThrowLogLevel = LogLevel.None;

                // When
                TestDocument result = await ExecuteAsync(context, json).SingleAsync();

                // Then
                result.ShouldBe(document);
            }
            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 NoReplacementReturnsSameDocument()
            {
                // Given
                const string input      = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This is some Foobar text</p>
                        </body>
                    </html>";
                TestDocument document   = new TestDocument(input);
                EscapeHtml   htmlEscape = new EscapeHtml();

                // When
                TestDocument result = await ExecuteAsync(document, htmlEscape).SingleAsync();

                // Then
                result.ShouldBe(document);
            }