Skip to content

Commit

Permalink
clarify test intent
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed Sep 30, 2021
1 parent b874d72 commit 7ee7db7
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/Microsoft.DotNet.Interactive.Tests/CancelCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Extensions;
using Markdig.Extensions.TaskLists;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Tests.Utility;
Expand Down Expand Up @@ -78,7 +80,7 @@ public async Task cancel_succeeds_when_there_is_command_in_progress_to_cancel()
}

[Fact]
public async Task can_cancel_user_loop_using_CancellationToken()
public async Task when_cancelling_command_it_reports_what_command_was_cancelled()
{
var kernel = CreateKernel();

Expand All @@ -96,18 +98,39 @@ public async Task can_cancel_user_loop_using_CancellationToken()
var result = await kernel.SendAsync(cancelCommand);

var cancellationEvents = result.KernelEvents.ToSubscribedList();

result = await resultForCommandToCancel;

var submitCodeEvents = result.KernelEvents.ToSubscribedList();
await resultForCommandToCancel;

cancellationEvents.Should()
.ContainSingle<CommandCancelled>()
.Which
.CancelledCommand
.Should()
.Be(commandToCancel);
}

[Fact]
public async Task can_cancel_user_loop_using_CancellationToken()
{
var kernel = CreateKernel();

var cancelCommand = new Cancel();

var commandToCancel = new SubmitCode(@"
using Microsoft.DotNet.Interactive;
var cancellationToken = KernelInvocationContext.Current.CancellationToken;
while(!cancellationToken.IsCancellationRequested){
await Task.Delay(10);
}", targetKernelName: "csharp");

var resultForCommandToCancel = kernel.SendAsync(commandToCancel);

await kernel.SendAsync(cancelCommand);

var result = await resultForCommandToCancel;

var submitCodeEvents = result.KernelEvents.ToSubscribedList();

submitCodeEvents.Should()
.ContainSingle<CommandFailed>()
.Which
Expand Down

0 comments on commit 7ee7db7

Please sign in to comment.