public async Task registers_html_formatter_for_explorer() { using CompositeKernel kernel = new CompositeKernel { new CSharpKernel().UseNugetDirective(), }; var extension = new MermaidKernelExtension(); await extension.OnLoadAsync(kernel); var explorer = typeof(List <string>).ExploreWithUmlClassDiagram(); var formatted = explorer.ToDisplayString(HtmlFormatter.MimeType); var markdown = explorer.ToMarkdown().ToString(); var doc = new HtmlDocument(); doc.LoadHtml(formatted.FixedGuid()); var scriptNode = doc.DocumentNode.SelectSingleNode("//div/script"); var renderTarget = doc.DocumentNode.SelectSingleNode("//div[@id='00000000000000000000000000000000']"); using var _ = new AssertionScope(); scriptNode.Should().NotBeNull(); scriptNode.InnerText.Should() .Contain(markdown); scriptNode.InnerText.Should() .Contain("configureRequireFromExtension('Mermaid','1.0.0')(['Mermaid/mermaidapi'], (mermaid) => {"); renderTarget.Should().NotBeNull(); }
public async Task registers_html_formatter_for_MermaidMarkdown() { using CompositeKernel kernel = new CompositeKernel { new CSharpKernel().UseNugetDirective(), }; var extension = new MermaidKernelExtension(); await extension.OnLoadAsync(kernel); var markdown = @"graph TD A[Client] --> B[Load Balancer] B --> C[Server1] B --> D[Server2]"; var formatted = new MermaidMarkdown(markdown).ToDisplayString(HtmlFormatter.MimeType); var doc = new HtmlDocument(); doc.LoadHtml(formatted.FixedGuid()); var scriptNode = doc.DocumentNode.SelectSingleNode("//div/script"); var renderTarget = doc.DocumentNode.SelectSingleNode("//div[@id='00000000000000000000000000000000']"); using var _ = new AssertionScope(); scriptNode.Should().NotBeNull(); scriptNode.InnerText.Should() .Contain(markdown); scriptNode.InnerText.Should() .Contain("configureRequireFromExtension('Mermaid','1.0.0')(['Mermaid/mermaidapi'], (mermaid) => {"); renderTarget.Should().NotBeNull(); }
public async Task can_use_extension_methods_from_the_kernel_extension() { using CompositeKernel kernel = new CompositeKernel { new CSharpKernel().UseNugetDirective(), }; var extension = new MermaidKernelExtension(); await extension.OnLoadAsync(kernel); await kernel.SendAsync(new SubmitCode($@"#r ""{typeof(MermaidKernelExtension).Assembly.Location}""", "csharp")); var result = await kernel.SendAsync(new SubmitCode(@" using System; typeof(List<string>).ExploreWithUmlClassDiagram().Display(); ", "csharp")); var events = result.KernelEvents.ToSubscribedList(); var formattedData = events .OfType <DisplayedValueProduced>() .Single() .FormattedValues .Single(fm => fm.MimeType == HtmlFormatter.MimeType) .Value; this.Assent(formattedData.FixedGuid(), _configuration); }
public async Task mermaid_kernel_handles_SubmitCode() { using CompositeKernel kernel = new CompositeKernel { new CSharpKernel().UseNugetDirective(), }; var extension = new MermaidKernelExtension(); await extension.OnLoadAsync(kernel); KernelCommandResult result = await kernel.SubmitCodeAsync(@" #!mermaid graph TD A[Client] --> B[Load Balancer] B --> C[Server1] B --> D[Server2] "); var events = result.KernelEvents.ToSubscribedList(); var formattedData = events .OfType <DisplayedValueProduced>() .Single() .FormattedValues .Single(fm => fm.MimeType == HtmlFormatter.MimeType) .Value; this.Assent(formattedData.FixedGuid(), _configuration); }
public async Task adds_mermaid_kernel() { using CompositeKernel kernel = new CompositeKernel { new CSharpKernel().UseNugetDirective(), }; var extension = new MermaidKernelExtension(); await extension.OnLoadAsync(kernel); kernel.ChildKernels .Should() .ContainSingle(k => k is MermaidKernel); }