Beispiel #1
0
    public async Task kernel_server_honors_log_path()
    {
        using var logPath = DisposableDirectory.Create();

        _output.WriteLine($"Created log file: {logPath.Directory.FullName}");

        var waitTime = TimeSpan.FromSeconds(10);

        using (var kernel = new CompositeKernel())
        {
            kernel.AddKernelConnector(new ConnectStdIoCommand());

            await kernel.SendAsync(new SubmitCode($"#!connect stdio --kernel-name proxy --command \"{Dotnet.Path}\" \"{typeof(Program).Assembly.Location}\" stdio --log-path \"{logPath.Directory.FullName}\" --verbose"));

            await kernel.SendAsync(new SubmitCode("1+1", "proxy"));
        }

        // wait for log file to be created
        var logFile = await logPath.Directory.WaitForFile(
            timeout : waitTime,
            predicate : _file => true); // any matching file is the one we want

        logFile.Should().NotBeNull($"a log file should have been created at {logFile.FullName}");

        // check log file for expected contents
        (await logFile.WaitForFileCondition(
             timeout: waitTime,
             predicate: file => file.Length > 0))
        .Should()
        .BeTrue($"expected non-empty log file within {waitTime.TotalSeconds}s");
        var logFileContents = File.ReadAllText(logFile.FullName);

        logFileContents.Should().Contain("CodeSubmissionReceived: 1+1");
    }
        public async Task It_can_connect_and_query_data()
        {
            using var kernel = new CompositeKernel
                  {
                      new CSharpKernel().UseNugetDirective(),
                      new SqlDiscoverabilityKernel(),
                      new KeyValueStoreKernel()
                  };

            kernel.AddKernelConnector(new ConnectSQLiteCommand());

            using var _ = CreateInMemorySQLiteDb(out var connectionString);

            var result = await kernel.SubmitCodeAsync(
                $"#!connect --kernel-name mydb sqlite \"{connectionString}\"");

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

            result = await kernel.SubmitCodeAsync(@"
#!sql-mydb
SELECT * FROM fruit
");

            var events = result.KernelEvents.ToSubscribedList();

            events.Should().NotContainErrors();

            events.Should()
            .ContainSingle <DisplayedValueProduced>()
            .Which
            .FormattedValues
            .Should()
            .ContainSingle(f => f.MimeType == HtmlFormatter.MimeType);
        }
        public async Task SQLKernel_suggests_SQLite_connection_when_statements_are_submitted_to_it()
        {
            using var kernel = new CompositeKernel
                  {
                      new CSharpKernel().UseNugetDirective(),
                      new SqlDiscoverabilityKernel(),
                      new KeyValueStoreKernel()
                  };

            kernel.AddKernelConnector(new ConnectSQLiteCommand());

            using var _ = CreateInMemorySQLiteDb(out var connectionString);

            var result = await kernel.SubmitCodeAsync(
                $"#!connect --kernel-name mydb sqlite \"{connectionString}\"");

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

            result = await kernel.SubmitCodeAsync(@"
#!sql
SELECT * FROM fruit
");

            var events = result.KernelEvents.ToSubscribedList();

            events.Should().NotContainErrors();
            events.Should()
            .ContainSingle <DisplayedValueProduced>()
            .Which
            .FormattedValues
            .Should()
            .ContainSingle(v => v.Value.Contains("#!sql-mydb") &&
                           v.MimeType == "text/html");
        }
Beispiel #4
0
 protected override void ConfigureConnectCommand(CompositeKernel compositeKernel)
 {
     compositeKernel.AddKernelConnector(new ConnectStdIoCommand());
 }