Example #1
0
        public async Task when_a_KernelCommandEnvelope_is_received_it_reads_the_command()
        {
            var kernelCommand = new SubmitCode("x=1");
            var message       = KernelCommandEnvelope.Serialize(KernelCommandEnvelope.Create(kernelCommand));

            using var stringReader = new StringReader(message);
            var receiver = new KernelCommandAndEventTextReceiver(stringReader);

            var d = await receiver.CommandsAndEventsAsync(CancellationToken.None).FirstAsync();

            d.Command.Should().BeEquivalentTo(kernelCommand);
        }
Example #2
0
        public async Task when_a_KernelEventEnvelope_is_received_it_publishes_the_event()
        {
            var kernelEvent = new CommandSucceeded(new SubmitCode("x=1"));
            var message     = KernelEventEnvelope.Serialize(KernelEventEnvelope.Create(kernelEvent));

            using var stringReader = new StringReader(message);
            var receiver = new KernelCommandAndEventTextReceiver(stringReader);

            var d = await receiver.CommandsOrEventsAsync(CancellationToken.None).FirstAsync();

            d.Event.Should().BeEquivalentTo(kernelEvent);
        }
Example #3
0
        public async Task when_invalid_json_is_received_it_produces_DiagnosticLogEntryProduced()
        {
            var invalidJson = " { hello";

            using var stringReader = new StringReader(invalidJson);
            var receiver = new KernelCommandAndEventTextReceiver(stringReader);

            var d = await receiver.CommandsAndEventsAsync(CancellationToken.None).FirstAsync();

            d.Event.Should().BeOfType <DiagnosticLogEntryProduced>()
            .Which
            .Message
            .Should()
            .Contain(invalidJson);;
        }
Example #4
0
        private async Task <Kernel> CreateProxyKernel(Language language)
        {
            var psi = new ProcessStartInfo
            {
                FileName               = "dotnet-interactive",
                Arguments              = $"stdio --default-kernel {language.LanguageName()}",
                WorkingDirectory       = Directory.GetCurrentDirectory(),
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
            };

            var process = new Process {
                StartInfo = psi
            };
            TaskCompletionSource <bool> ready = new();

            process.Start();

            var receiver = new KernelCommandAndEventTextReceiver(process.StandardOutput);
            var sender   = new KernelCommandAndEventTextStreamSender(process.StandardInput);

            var kernel = new ProxyKernel("proxy", receiver, sender);

            kernel.RegisterForDisposal(() =>
            {
                process.Kill(true);
                process.Dispose();
            });

            var _ = kernel.RunAsync();

            var sub = kernel.KernelEvents.OfType <KernelReady>().Subscribe(_ =>
            {
                ready.SetResult(true);
            });

            await ready.Task;

            sub.Dispose();

            return(kernel);
        }