public void FindKernel_finds_a_subkernel_of_a_composite_kernel_by_alias() { var one = new FakeKernel("one"); var two = new FakeKernel("two"); using var compositeKernel = new CompositeKernel(); compositeKernel.Add(one, aliases: new[] { "one-alias" }); compositeKernel.Add(two); var found = compositeKernel.FindKernel("one-alias"); found.Should().BeSameAs(one); }
public async Task Directives_can_display_help(string kernelName) { var cSharpKernel = new CSharpKernel().UseDefaultMagicCommands(); using var compositeKernel = new CompositeKernel { cSharpKernel }; var command = new Command("#!hello") { new Option <bool>("--loudness") }; var findKernel = compositeKernel.FindKernel(kernelName); var kernelWithDirective = findKernel switch { Kernel k => k, _ => throw new ArgumentOutOfRangeException() }; kernelWithDirective.AddDirective(command); using var events = compositeKernel.KernelEvents.ToSubscribedList(); await compositeKernel.SubmitCodeAsync("#!hello -h"); var stdOut = string.Join( "", events .OfType <StandardOutputValueProduced>() .Select(e => e.Value.As <string>())); var stdErr = string.Join( "", events .OfType <StandardErrorValueProduced>() .Select(e => e.Value.As <string>())); stdOut .Should() .ContainAll("Usage", "#!hello", "[options]", "--loudness"); stdOut .Should() .NotContain(new RootCommand().Name, "RootCommand.Name is generally intended to reflect the command line tool's name but in this case it's just an implementation detail and it looks weird in the output."); stdErr.Should().BeEmpty(); }
public void FindKernel_returns_null_for_unknown_kernel() { var one = new FakeKernel("one"); var two = new FakeKernel("two"); using var compositeKernel = new CompositeKernel { one, two, }; var found = compositeKernel.FindKernel("three"); found.Should().BeNull(); }
public void FindKernel_finds_a_subkernel_of_a_composite_kernel_by_name() { var one = new FakeKernel("one"); var two = new FakeKernel("two"); using var compositeKernel = new CompositeKernel { one, two, }; var found = compositeKernel.FindKernel("two"); found.Should().BeSameAs(two); }
public async Task javascript_kernel_forwards_commands_to_frontend() { var client = new TestClient(); using var kernel = new CompositeKernel { new JavaScriptKernel(client) }; kernel.FindKernel(JavaScriptKernel.DefaultKernelName).RegisterCommandType <CustomCommand>(); using var events = kernel.KernelEvents.ToSubscribedList(); var command = new CustomCommand(JavaScriptKernel.DefaultKernelName); await kernel.SendAsync(command, CancellationToken.None); client.ForwardedCommands.Should().Contain(command); }
public async Task Directives_can_display_help(string kernelName) { var cSharpKernel = new CSharpKernel().UseDefaultMagicCommands(); using var compositeKernel = new CompositeKernel { cSharpKernel }; var command = new Command("#!hello") { new Option <bool>("--loudness") }; var kernel = compositeKernel.FindKernel(kernelName); kernel.AddDirective(command); using var events = compositeKernel.KernelEvents.ToSubscribedList(); await compositeKernel.SubmitCodeAsync("#!hello -h"); events.Should() .ContainSingle <StandardOutputValueProduced>() .Which .FormattedValues .Should() .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) .Which .Value .Should() .ContainAll("Usage", "#!hello", "[options]", "--loudness"); events.Should() .NotContainErrors(); }