这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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