Example #1
0
            public async Task NonWholeWords()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>abc Foo(baz) xyz</p>
                        </body>
                    </html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foo", "http://www.google.com" },
                    { "baz", "http://www.yahoo.com" },
                }).WithMatchOnlyWholeWord();

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

                // Then
                result.ShouldBeSameAs(document);
            }
Example #2
0
            public async Task AddsLinkWithoutImpactingEscapes()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This A&lt;string, List&lt;B&gt;&gt; is some Foobar text</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This A&lt;string, List&lt;B&gt;&gt; is some <a href=""http://www.google.com"">Foobar</a> text</p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foobar", "http://www.google.com" }
                });

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #3
0
            public async Task AdjacentWords()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>abc Foo(baz) xyz</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>abc <a href=""http://www.google.com"">Foo</a>(<a href=""http://www.yahoo.com"">baz</a>) xyz</p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foo", "http://www.google.com" },
                    { "baz", "http://www.yahoo.com" },
                });

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #4
0
            public async Task WordAtTheEndAfterPreviousWord()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>sdfg asdf aasdf asf asdf asdf asdf aabc Fuzz bazz def efg baz x</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>sdfg asdf aasdf asf asdf asdf asdf aabc <a href=""http://www.google.com"">Fuzz</a> bazz def efg <a href=""http://www.yahoo.com"">baz</a> x</p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Fuzz", "http://www.google.com" },
                    { "baz", "http://www.yahoo.com" },
                }).WithMatchOnlyWholeWord();

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #5
0
            public async Task IgnoreSubstringIfSearchingForWholeWords()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This is some <i>Foo</i> text Foobaz</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This is some <i><a href=""http://www.google.com"">Foo</a></i> text Foobaz</p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foo", "http://www.google.com" },
                }).WithMatchOnlyWholeWord();

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #6
0
            public async Task AddLinkMethodTakesPrecedence()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This is some <i>Foobar</i> text Foobaz</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Title</h1>
                            <p>This is some <i><a href=""http://www.google.com"">Foobar</a></i> text <a href=""http://www.yahoo.com"">Foobaz</a></p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foobar", "http://www.google.com" },
                    { "Foobaz", "http://www.bing.com" }
                }).WithLink("Foobaz", "http://www.yahoo.com");

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #7
0
            public async Task AddsMultipleLinksInDifferentElements()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Foobaz</h1>
                            <p>This is some <i>Foobar</i> text Foobaz</p>
                            <p>Another Foobaz paragraph</p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Foobaz</h1>
                            <p>This is some <i><a href=""http://www.google.com"">Foobar</a></i> text <a href=""http://www.bing.com"">Foobaz</a></p>
                            <p>Another <a href=""http://www.bing.com"">Foobaz</a> paragraph</p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foobar", "http://www.google.com" },
                    { "Foobaz", "http://www.bing.com" }
                });

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #8
0
            public async Task DoesNotReplaceInAttributes()
            {
                // Given
                const string input    = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1 title=""Foobar"">Title</h1>
                            <p attr=""Foobar"">This is some Foobar <b ref=""Foobar"">text</b></p>
                        </body>
                    </html>";
                const string output   = @"<html><head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1 title=""Foobar"">Title</h1>
                            <p attr=""Foobar"">This is some <a href=""http://www.google.com"">Foobar</a> <b ref=""Foobar"">text</b></p>
                        
                    </body></html>";
                TestDocument document = new TestDocument(input);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foobar", "http://www.google.com" }
                });

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

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
            }
Example #9
0
            public async Task NoReplacementWithQuerySelectorReturnsSameDocument()
            {
                // Given
                string       inputContent         = $"<div>@x.Select(x => x) <code>Foo bar</code></div>";
                TestDocument document             = new TestDocument(inputContent);
                Dictionary <string, string> links = new Dictionary <string, string>();
                InsertLinks autoLink = new InsertLinks(links)
                                       .WithQuerySelector("code")
                                       .WithMatchOnlyWholeWord()
                                       .WithStartWordSeparators('<')
                                       .WithEndWordSeparators('>');

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

                // Then
                result.ShouldBeSameAs(document);
            }
Example #10
0
            public async Task AddLinksToGenericWordsInsideAngleBrackets(string input, string expected)
            {
                // Given
                string       inputContent         = $"<html><head></head><body><foo></foo><ul>{input}</ul></body></html>";
                string       expectedContent      = $"<html><head></head><body><foo></foo><ul>{expected}</ul></body></html>";
                TestDocument document             = new TestDocument(inputContent);
                Dictionary <string, string> links = new Dictionary <string, string>()
                {
                    { "Foo&lt;T&gt;", "http://www.fooOfT.com" },
                    { "Foo", "http://www.foo.com" },
                };
                InsertLinks autoLink = new InsertLinks(links)
                                       .WithQuerySelector("code")
                                       .WithMatchOnlyWholeWord()
                                       .WithStartWordSeparators('<')
                                       .WithEndWordSeparators('>');

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

                // Then
                result.Content.ShouldBe(expectedContent);
            }
Example #11
0
            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);
                InsertLinks  autoLink = new InsertLinks(new Dictionary <string, string>()
                {
                    { "Foobaz", "http://www.google.com" }
                });

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

                // Then
                result.ShouldBeSameAs(document);
            }