-
Notifications
You must be signed in to change notification settings - Fork 367
/
KernelCommandNestingTests.cs
131 lines (110 loc) · 4.26 KB
/
KernelCommandNestingTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// 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.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.FSharp;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.Interactive.Tests
{
public class KernelCommandNestingTests : LanguageKernelTestBase
{
public KernelCommandNestingTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandSucceeded_to_the_outer_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel ( "cs1" ),
new CSharpKernel ( "cs2" )
};
var kernelEvents = kernel.KernelEvents.ToSubscribedList();
var command = new SubmitCode(@$"
#!cs1
using {typeof(Kernel).Namespace};
using {typeof(KernelCommand).Namespace};
await Kernel.Root.SendAsync(new SubmitCode(""1+1"", ""cs2""));
");
await kernel.SendAsync(command);
using var _ = new AssertionScope();
kernelEvents.Should()
.ContainSingle<CommandSucceeded>(e => e.Command == command);
kernelEvents.Should()
.NotContain(e =>
e is CommandSucceeded &&
e.Command.TargetKernelName == "cs2");
}
[Fact]
public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandFailed_to_the_outer_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel ( "cs1" ),
new CSharpKernel ( "cs2" )
};
var kernelEvents = kernel.KernelEvents.ToSubscribedList();
var command = new SubmitCode($@"
#!cs1
using {typeof(Kernel).Namespace};
using {typeof(KernelCommand).Namespace};
await Kernel.Root.SendAsync(new SubmitCode(""error"", ""cs2""));
");
await kernel.SendAsync(command);
kernelEvents.Should()
.ContainSingle<CommandSucceeded>(e => e.Command == command);
kernelEvents
.Should()
.NotContain(e => e is CommandFailed);
}
[Fact]
public async Task Commands_sent_within_the_code_of_another_command_publish_CommandSucceeded_to_the_inner_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel(),
new FSharpKernel()
};
var result = await kernel.SubmitCodeAsync(
@"
using System.Reactive.Linq;
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
var result = await Kernel.Root.SendAsync(new SubmitCode(""123"", ""fsharp""));
await result.KernelEvents.LastAsync()
");
var events = result.KernelEvents.ToSubscribedList();
events.Should().NotContainErrors();
events
.Should()
.ContainSingle<ReturnValueProduced>(e => e.Value is CommandSucceeded);
}
[Fact]
public async Task Commands_sent_within_the_code_of_another_command_publish_CommandFailed_to_the_inner_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel ( "cs1" ),
new CSharpKernel ( "cs2" )
};
var result = await kernel.SendAsync(new SubmitCode(
@"
using System.Reactive.Linq;
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
var result = await Kernel.Root.SendAsync(new SubmitCode(""nope"", ""cs2""));
await result.KernelEvents.LastAsync()
", "cs1"));
var events = result.KernelEvents.ToSubscribedList();
events
.Should()
.ContainSingle<ReturnValueProduced>(e => e.Value is CommandFailed);
}
}
}