Skip to content

Commit

Permalink
Merge pull request dotnet#448 from colombod/feature/nuget_loading_doe…
Browse files Browse the repository at this point in the history
…s_not_complete

#r nuget now completes the operation even when is the only content of code submission
  • Loading branch information
colombod authored Sep 16, 2019
2 parents f43d98c + be73de5 commit fbe41c0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions Microsoft.DotNet.Interactive.Tests/SubscribedList{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : IReadOnlyList<T>, IDisposable
{
private readonly List<T> _list = new List<T>();
private ImmutableArray<T> _list = ImmutableArray<T>.Empty;
private readonly IDisposable _subscription;

public SubscribedList(IObservable<T> source)
{
_subscription = source.Subscribe(x => _list.Add(x));
_subscription = source.Subscribe(x =>
{
_list = _list.Add(x);
});
}

public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
public IEnumerator<T> GetEnumerator()
{
return ((IEnumerable<T>) _list).GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => _list.Count;
public int Count => _list.Length;

public T this[int index] => _list[index];

Expand Down
1 change: 1 addition & 0 deletions Microsoft.DotNet.Interactive/KernelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private async Task HandleDirectivesAndSubmitCode(
}
else
{
context.Complete();
return;
}
}
Expand Down
39 changes: 39 additions & 0 deletions WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NuGetPackageAdded>()
.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()
{
Expand Down
4 changes: 0 additions & 4 deletions WorkspaceServer/Kernel/CSharpKernelExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit fbe41c0

Please sign in to comment.