public async Task HighlightAsync_HighlightsCode(string dummyCode, string dummyLanguageName, string expectedResult)
        {
            // Arrange
            IHighlightJSService highlightJSService = CreateHighlightJSService();

            // Act
            string?result = await highlightJSService.HighlightAsync(dummyCode, dummyLanguageName).ConfigureAwait(false);

            // Assert
            Assert.Equal(expectedResult, result, ignoreLineEndingDifferences: true);
        }
        public async Task HighlightAsync_AppendsClassPrefixToClassesIfClassPrefixIsNotNullOtherwiseDoesNotAppendAnything(string dummyClassPrefix, string expectedResult)
        {
            // Arrange
            const string        dummyCode          = @"public string ExampleFunction(string arg)
{
    // Example comment
    return arg + ""dummyString"";
}";
            const string        dummyLanguageName  = "csharp";
            IHighlightJSService highlightJSService = CreateHighlightJSService();

            // Act
            string?result = await highlightJSService.HighlightAsync(dummyCode, dummyLanguageName, dummyClassPrefix).ConfigureAwait(false);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void HighlightAsync_IsThreadSafe()
        {
            // Arrange
            const string        dummyCode          = @"public string ExampleFunction(string arg)
{
    // Example comment
    return arg + ""dummyString"";
}";
            const string        dummyLanguageAlias = "csharp";
            IHighlightJSService testSubject        = CreateHighlightJSService();

            // Act
            var       results    = new ConcurrentQueue <string?>();
            const int numThreads = 5;
            var       threads    = new List <Thread>();

            for (int i = 0; i < numThreads; i++)
            {
                var thread = new Thread(() => results.Enqueue(testSubject.HighlightAsync(dummyCode, dummyLanguageAlias).GetAwaiter().GetResult()));
                threads.Add(thread);
                thread.Start();
            }
            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            // Assert
            Assert.Equal(numThreads, results.Count);
            foreach (string?result in results)
            {
                Assert.Equal(@"<span class=""hljs-function""><span class=""hljs-keyword"">public</span> <span class=""hljs-built_in"">string</span> <span class=""hljs-title"">ExampleFunction</span>(<span class=""hljs-params""><span class=""hljs-built_in"">string</span> arg</span>)</span>
{
    <span class=""hljs-comment"">// Example comment</span>
    <span class=""hljs-keyword"">return</span> arg + <span class=""hljs-string"">&quot;dummyString&quot;</span>;
}",
                             result);
            }
        }
예제 #4
0
 /// <summary>
 /// Creates a <see cref="FlexiCodeBlockRenderer"/>.
 /// </summary>
 /// <param name="prismService">The service that will handle syntax highlighting using Prism.</param>
 /// <param name="highlightJSService">The service that will handle syntax highlighting using HighlightJS.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="prismService"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="highlightJSService"/> is <c>null</c>.</exception>
 public FlexiCodeBlockRenderer(IPrismService prismService,
                               IHighlightJSService highlightJSService)
 {
     _prismService       = prismService ?? throw new ArgumentNullException(nameof(prismService));
     _highlightJSService = highlightJSService ?? throw new ArgumentNullException(nameof(highlightJSService));
 }
 public Mock <ExposedFlexiCodeBlockRenderer> CreateMockExposedFlexiCodeBlockRenderer(IPrismService prismService             = null,
                                                                                     IHighlightJSService highlightJSService = null)
 {
     return(_mockRepository.Create <ExposedFlexiCodeBlockRenderer>(prismService ?? _mockRepository.Create <IPrismService>().Object,
                                                                   highlightJSService ?? _mockRepository.Create <IHighlightJSService>().Object));
 }
 public FlexiCodeBlockRenderer CreateFlexiCodeBlockRenderer(IPrismService prismService             = null,
                                                            IHighlightJSService highlightJSService = null)
 {
     return(new FlexiCodeBlockRenderer(prismService ?? _mockRepository.Create <IPrismService>().Object,
                                       highlightJSService ?? _mockRepository.Create <IHighlightJSService>().Object));
 }
 public ExposedFlexiCodeBlockRenderer(IPrismService prismService, IHighlightJSService highlightJSService) : base(prismService, highlightJSService)
 {
 }