From a0b79b97b695e7624a12e25bc176f00023458922 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 16 Sep 2019 20:36:25 +0100 Subject: [PATCH 1/2] #r nuget now completes the operation even when is the only content of code submission --- .../MagicCommandTests.cs | 1 + .../SubscribedList{T}.cs | 15 +++++-- Microsoft.DotNet.Interactive/KernelBase.cs | 1 + .../Kernel/CSharpKernelTests.cs | 39 +++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Microsoft.DotNet.Interactive.Jupyter.Tests/MagicCommandTests.cs b/Microsoft.DotNet.Interactive.Jupyter.Tests/MagicCommandTests.cs index 5ef85765f..766c0115c 100644 --- a/Microsoft.DotNet.Interactive.Jupyter.Tests/MagicCommandTests.cs +++ b/Microsoft.DotNet.Interactive.Jupyter.Tests/MagicCommandTests.cs @@ -167,6 +167,7 @@ public async Task markdown_renders_markdown_content_as_html() await kernel.SendAsync(new SubmitCode( $"%%markdown\n\n# Topic!\nContent")); + var formatted = events diff --git a/Microsoft.DotNet.Interactive.Tests/SubscribedList{T}.cs b/Microsoft.DotNet.Interactive.Tests/SubscribedList{T}.cs index f5c37012d..727b80b46 100644 --- a/Microsoft.DotNet.Interactive.Tests/SubscribedList{T}.cs +++ b/Microsoft.DotNet.Interactive.Tests/SubscribedList{T}.cs @@ -4,24 +4,31 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; namespace Microsoft.DotNet.Interactive.Tests { public class SubscribedList : IReadOnlyList, IDisposable { - private readonly List _list = new List(); + private ImmutableArray _list = ImmutableArray.Empty; private readonly IDisposable _subscription; public SubscribedList(IObservable source) { - _subscription = source.Subscribe(x => _list.Add(x)); + _subscription = source.Subscribe(x => + { + _list = _list.Add(x); + }); } - public IEnumerator GetEnumerator() => _list.GetEnumerator(); + public IEnumerator GetEnumerator() + { + return ((IEnumerable) _list).GetEnumerator(); + } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public int Count => _list.Count; + public int Count => _list.Length; public T this[int index] => _list[index]; diff --git a/Microsoft.DotNet.Interactive/KernelBase.cs b/Microsoft.DotNet.Interactive/KernelBase.cs index c79c674cb..f38b13f55 100644 --- a/Microsoft.DotNet.Interactive/KernelBase.cs +++ b/Microsoft.DotNet.Interactive/KernelBase.cs @@ -199,6 +199,7 @@ private async Task HandleDirectivesAndSubmitCode( } else { + context.Complete(); return; } } diff --git a/WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs b/WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs index a0ee9f416..2aa6cda1d 100644 --- a/WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs +++ b/WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs @@ -433,6 +433,45 @@ public async Task When_SubmitCode_command_adds_packages_to_csharp_kernel_then_Pa .ContainSingle(e => e is CommandHandled); } + [Fact] + public async Task When_SubmitCode_command_only_adds_packages_to_csharp_kernel_then_CommandHandled_event_is_raised() + { + var kernel = new CompositeKernel + { + new CSharpKernel().UseNugetDirective() + }; + + var command = new SubmitCode("#r \"nuget:Microsoft.Extensions.Logging, 2.2.0\""); + + var result = await kernel.SendAsync(command); + + using var events = result.KernelEvents.ToSubscribedList(); + + events + .First() + .Should() + .Match(e => e is DisplayedValueProduced && ((DisplayedValueProduced)e).Value.ToString().Contains("Attempting to install")); + + events + .Should() + .Contain(e => e is DisplayedValueUpdated); + + + events + .Should() + .ContainSingle(e => e is NuGetPackageAdded); + + events.OfType() + .Single() + .PackageReference + .Should() + .BeEquivalentTo(new NugetPackageReference("Microsoft.Extensions.Logging", "2.2.0")); + + events + .Should() + .ContainSingle(e => e is CommandHandled); + } + [Fact] public async Task The_extend_directive_can_be_used_to_load_a_kernel_extension() { From be73de53b19f6aa8f084f0ffe64dbfdee5fed992 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 16 Sep 2019 20:41:11 +0100 Subject: [PATCH 2/2] unused namespaces --- WorkspaceServer/Kernel/CSharpKernelExtensions.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WorkspaceServer/Kernel/CSharpKernelExtensions.cs b/WorkspaceServer/Kernel/CSharpKernelExtensions.cs index 620444851..71385455a 100644 --- a/WorkspaceServer/Kernel/CSharpKernelExtensions.cs +++ b/WorkspaceServer/Kernel/CSharpKernelExtensions.cs @@ -1,13 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Invocation; -using System.IO; -using System.Linq; using System.Threading.Tasks; -using System.Threading.Tasks.Dataflow; using Microsoft.CodeAnalysis; using Microsoft.DotNet.Interactive; using Microsoft.DotNet.Interactive.Commands;