public async Task Completions_suggest_existing_DataFrame_variables()
        {
            var kernel = new CSharpKernel()
                         .UseNugetDirective();

            await new DataFrameTypeGeneratorExtension().OnLoadAsync(kernel);

            await kernel.SubmitCodeAsync($@"
#r ""{typeof(DataFrame).Assembly.Location}""
using Microsoft.Data.Analysis;
");

            var dataFrameVariableName = "myDataFrame";
            await kernel.SetVariableAsync(dataFrameVariableName, CreateDataFrame());

            var code   = "#!linqify ";
            var result = await kernel.SendAsync(new RequestCompletions(code, new LinePosition(0, code.Length)));

            result.KernelEvents.ToSubscribedList().Should().ContainSingle <CompletionsProduced>()
            .Which
            .Completions
            .Select(c => c.DisplayText)
            .Should()
            .Contain(dataFrameVariableName);
        }
Ejemplo n.º 2
0
        public async Task Directive_handlers_are_invoked_in_the_order_in_which_they_occur_in_the_code_submission()
        {
            using var kernel = new CSharpKernel();
            var events = kernel.KernelEvents.ToSubscribedList();

            kernel.AddDirective(new Command("#increment")
            {
                Handler = CommandHandler.Create(async(KernelInvocationContext context) =>
                {
                    await context.HandlingKernel.SubmitCodeAsync("i++;");
                })
            });

            await kernel.SubmitCodeAsync(@"
var i = 0;
#increment
i");

            events
            .Should()
            .ContainSingle <ReturnValueProduced>()
            .Which
            .Value
            .Should()
            .Be(1);
        }
        public async Task pound_r_is_not_split_into_separate_command_from_csharp_code()
        {
            var receivedCommands = new List <IKernelCommand>();

            using var kernel = new CSharpKernel();

            kernel.AddMiddleware((command, context, next) =>
            {
                receivedCommands.Add(command);
                return(Task.CompletedTask);
            });

            kernel.UseNugetDirective();

            var path = Path.GetTempFileName();
            var poundR_and_usingStatement = $@"#r ""{path}""{Environment.NewLine}using Some.Namespace;";
            var nextSubmission            = "// the code";

            kernel.DeferCommand(new SubmitCode(poundR_and_usingStatement));

            await kernel.SubmitCodeAsync(nextSubmission);

            receivedCommands
            .Cast <SubmitCode>()
            .Select(c => c.Code.Trim())
            .Should()
            .BeEquivalentSequenceTo(
                poundR_and_usingStatement,
                nextSubmission);
        }
        private static async Task <CSharpKernel> CreateKernelAndGenerateType(
            string magicCommand = "#!linqify frame")
        {
            var kernel = new CSharpKernel()
                         .UseNugetDirective();

            await new DataFrameTypeGeneratorExtension().OnLoadAsync(kernel);

            await kernel.SubmitCodeAsync($@"
#r ""{typeof(DataFrame).Assembly.Location}""
using Microsoft.Data.Analysis;
");

            await kernel.SetVariableAsync("frame", CreateDataFrame());

            await kernel.SubmitCodeAsync(magicCommand);

            return(kernel);
        }
Ejemplo n.º 5
0
        public async Task It_outputs_diagnostic_log_events()
        {
            using var kernel = new CSharpKernel()
                               .UseLog();

            using var events = kernel.KernelEvents.ToSubscribedList();

            await kernel.SubmitCodeAsync("#!log\n123");

            events.Should()
            .ContainSingle <DiagnosticLogEntryProduced>(
                e => e.Message == "Logging enabled");
        }
        public async Task The_generated_source_code_can_be_displayed()
        {
            var kernel = new CSharpKernel()
                         .UseNugetDirective();

            await new DataFrameTypeGeneratorExtension().OnLoadAsync(kernel);

            await kernel.SubmitCodeAsync($@"
#r ""{typeof(DataFrame).Assembly.Location}""
using Microsoft.Data.Analysis;
");

            await kernel.SetVariableAsync("frame", CreateDataFrame());

            var result = await kernel.SubmitCodeAsync("#!linqify frame --show-code");

            result.KernelEvents
            .ToSubscribedList()
            .Should()
            .NotContainErrors();

            result.KernelEvents
            .ToSubscribedList()
            .Should()
            .ContainSingle <DisplayedValueProduced>()
            .Which
            .FormattedValues
            .Should()
            .ContainSingle()
            .Which
            .Value
            .Should()
            .ContainAll(
                "public class DataFrame_",
                "public System.String name => ");
        }
Ejemplo n.º 7
0
        public async Task magic_command_parse_errors_prevent_code_submission_from_being_run()
        {
            var command = new Command("%oops")
            {
                new Argument <string>()
            };

            using var kernel = new CSharpKernel();

            kernel.AddDirective(command);

            var events = kernel.KernelEvents.ToSubscribedList();

            await kernel.SubmitCodeAsync("%oops\n123");

            events.Should().NotContain(e => e is ReturnValueProduced);
        }
Ejemplo n.º 8
0
        private static async Task <CompositeKernel> CreateKernel()
        {
            var csharpKernel = new CSharpKernel().UseNugetDirective();
            await csharpKernel.SubmitCodeAsync(@"
#r ""nuget:microsoft.sqltoolsservice,3.0.0-release.163""
");

            var kernel = new CompositeKernel
            {
                new KqlDiscoverabilityKernel(),
                csharpKernel,
                new KeyValueStoreKernel()
            };

            kernel.DefaultKernelName = csharpKernel.Name;

            var kqlKernelExtension = new KqlKernelExtension();
            await kqlKernelExtension.OnLoadAsync(kernel);

            return(kernel);
        }
Ejemplo n.º 9
0
        public async Task magic_command_parse_errors_are_displayed()
        {
            var command = new Command("%oops")
            {
                new Argument <string>()
            };

            using var kernel = new CSharpKernel();

            kernel.AddDirective(command);

            var events = kernel.KernelEvents.ToSubscribedList();

            await kernel.SubmitCodeAsync("%oops");

            events.Should()
            .ContainSingle <ErrorProduced>()
            .Which
            .Message
            .Should()
            .Be("Required argument missing for command: %oops");
        }
Ejemplo n.º 10
0
        private async Task <CompositeKernel> CreateKernelAsync()
        {
            var csharpKernel = new CSharpKernel().UseNugetDirective().UseValueSharing();
            await csharpKernel.SubmitCodeAsync(@"
#r ""nuget:microsoft.sqltoolsservice,3.0.0-release.163""
");

            // TODO: remove SQLKernel it is used to test current patch
            var kernel = new CompositeKernel
            {
                new SqlDiscoverabilityKernel(),
                csharpKernel,
                new KeyValueStoreKernel()
            };

            kernel.DefaultKernelName = csharpKernel.Name;

            var sqlKernelExtension = new MsSqlKernelExtension();
            await sqlKernelExtension.OnLoadAsync(kernel);

            return(kernel);
        }