예제 #1
0
            public async Task HighlightFailsForMissingLanguage()
            {
                // Given
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code class=""language-zorg"">
    <html>
    <head>
    <title>Hi Mom!</title>
    </head>
    <body>
        <p>Hello, world! Pretty me up!
    </body>
    </html>
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode();

                // When, Then
                await Should.ThrowAsync <Exception>(async() => await ExecuteAsync(document, context, highlight));
            }
예제 #2
0
            public async Task CanHighlightAutoCodeBlocks()
            {
                // Given
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code>
        if (foo == bar)
        {
            DoTheFooBar();
        }
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode();

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

                // Then
                result.Content.ShouldContain("hljs");
            }
예제 #3
0
            public async Task CanHighlightAfterRazor()
            {
                // Given
                // if we execute razor before this, the code block will be escaped.
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code class=""language-html"">
    &lt;strong class=&quot;super-strong&quot;&gt;this is strong text&lt;/strong&gt;
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode();

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

                // Then
                result.Content.ShouldContain("language-html hljs");
            }
예제 #4
0
            public async Task CanHighlightCSharp()
            {
                // Given
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code class=""language-csharp"">
    class Program
    {
        static void Main(string[] args)
        {
            var invoices = new List&lt;Invoice&gt; { new Invoice { InvoiceId = 0 } };
            var oneTimeCharges = new List&lt;OneTimeCharge&gt; { new OneTimeCharge { Invoice = 0, OneTimeChargeId = 0 } };
            var otcCharges = invoices.Join(oneTimeCharges, inv =&gt; inv.InvoiceId, otc =&gt; otc.Invoice, (inv, otc) =&gt; inv.InvoiceId);
            Console.WriteLine(otcCharges.Count());
        }        
    }

    public class OneTimeCharge
    {
        public int OneTimeChargeId { get; set; }
        public int? Invoice { get; set; }
    }

    public class Invoice
    {
        public int InvoiceId { get; set; }
    }
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode();

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

                // Then
                result.Content.ShouldContain("language-csharp hljs");
            }
예제 #5
0
            public async Task HighlightSucceedsForMissingLanguageWhenConfiguredNotToWarn()
            {
                // Given
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code class=""language-zorg"">
    <html>
    <head>
    <title>Hi Mom!</title>
    </head>
    <body>
        <p>Hello, world! Pretty me up!
    </body>
    </html>
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode()
                                          .WithMissingLanguageWarning(false);

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

                // Then
                results.ShouldNotBeEmpty();
            }
예제 #6
0
            public async Task CanHighlightHtml()
            {
                const string input = @"
<html>
<head>
    <title>Foobar</title>
</head>
<body>
    <h1>Title</h1>
    <p>This is some Foobar text</p>
    <pre><code class=""language-html"">
    <html>
    <head>
    <title>Hi Mom!</title>
    </head>
    <body>
        <p>Hello, world! Pretty me up!
    </body>
    </html>
    </code></pre>
</body>
</html>";

                TestDocument         document = new TestDocument(input);
                TestExecutionContext context  = new TestExecutionContext()
                {
                    JsEngineFunc = () => new TestJsEngine()
                };

                HighlightCode highlight = new HighlightCode();

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

                // Then
                result.Content.ShouldContain("language-html hljs");
            }
예제 #7
0
 /// <summary>
 /// A utility method to execute modules in serial. The resulting documents will be materialized before returning.
 /// A new <see cref="TestExecutionContext"/> will be created.
 /// </summary>
 /// <param name="documents">The initial input documents.</param>
 /// <param name="context">The execution context to use.</param>
 /// <param name="modules">The modules to execute.</param>
 /// <returns>A materialized list of result documents from the last module.</returns>
 public static async Task <ImmutableArray <TestDocument> > ExecuteAsync(IEnumerable <TestDocument> documents, TestExecutionContext context, params IModule[] modules) =>
 (await context.ExecuteModulesAsync(modules, documents)).Cast <TestDocument>().ToImmutableDocumentArray();