1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System ;
4
5
using System . Threading . Tasks ;
5
6
using FluentAssertions ;
6
7
using FluentAssertions . Execution ;
@@ -20,95 +21,122 @@ public KernelCommandNestingTests(ITestOutputHelper output) : base(output)
20
21
{
21
22
}
22
23
23
- [ Fact ]
24
- public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandSucceeded_to_the_outer_result ( )
24
+ public class KernelEvents
25
25
{
26
- using var kernel = new CompositeKernel
26
+ [ Fact ]
27
+ public async Task Commands_sent_within_the_code_of_another_command_publish_error_events_on_CompositeKernel_for_failures ( )
27
28
{
28
- new CSharpKernel ( "cs1" ) ,
29
- new CSharpKernel ( "cs2" )
30
- } ;
31
- var kernelEvents = kernel . KernelEvents . ToSubscribedList ( ) ;
32
- var command = new SubmitCode ( @$ "
29
+ using var kernel = new CompositeKernel
30
+ {
31
+ new CSharpKernel ( "cs1" ) ,
32
+ new CSharpKernel ( "cs2" )
33
+ } ;
34
+ var kernelEvents = kernel . KernelEvents . ToSubscribedList ( ) ;
35
+ var command = new SubmitCode ( $@ "
33
36
#!cs1
34
37
using { typeof ( Kernel ) . Namespace } ;
35
38
using { typeof ( KernelCommand ) . Namespace } ;
36
- await Kernel.Root.SendAsync(new SubmitCode(""1+1 "", ""cs2""));
39
+ await Kernel.Root.SendAsync(new SubmitCode(""error "", ""cs2""));
37
40
" ) ;
38
- await kernel . SendAsync ( command ) ;
39
41
40
- using var _ = new AssertionScope ( ) ;
41
- kernelEvents . Should ( )
42
- . ContainSingle < CommandSucceeded > ( e => e . Command == command ) ;
42
+ await kernel . SendAsync ( command ) ;
43
43
44
- kernelEvents . Should ( )
45
- . NotContain ( e =>
46
- e is CommandSucceeded &&
47
- e . Command . TargetKernelName == "cs2" ) ;
44
+ kernelEvents . Should ( )
45
+ . ContainSingle < ErrorProduced > ( )
46
+ . Which
47
+ . Message
48
+ . Should ( )
49
+ . Be ( "(1,1): error CS0103: The name 'error' does not exist in the current context" ) ;
50
+ }
48
51
}
49
52
50
- [ Fact ]
51
- public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandFailed_to_the_outer_result ( )
53
+ public class KernelCommandResultEvents
52
54
{
53
- using var kernel = new CompositeKernel
55
+ [ Fact ]
56
+ public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandSucceeded_to_the_outer_result ( )
54
57
{
55
- new CSharpKernel ( "cs1" ) ,
56
- new CSharpKernel ( "cs2" )
57
- } ;
58
- var kernelEvents = kernel . KernelEvents . ToSubscribedList ( ) ;
59
- var command = new SubmitCode ( $@ "
58
+ using var kernel = new CompositeKernel
59
+ {
60
+ new CSharpKernel ( "cs1" ) ,
61
+ new CSharpKernel ( "cs2" )
62
+ } ;
63
+ var command = new SubmitCode ( @$ "
60
64
#!cs1
61
65
using { typeof ( Kernel ) . Namespace } ;
62
66
using { typeof ( KernelCommand ) . Namespace } ;
63
- await Kernel.Root.SendAsync(new SubmitCode(""error "", ""cs2""));
67
+ await Kernel.Root.SendAsync(new SubmitCode(""1+1 "", ""cs2""));
64
68
" ) ;
65
- await kernel . SendAsync ( command ) ;
69
+ var result = await kernel . SendAsync ( command ) ;
66
70
67
- kernelEvents . Should ( )
68
- . ContainSingle < CommandSucceeded > ( e => e . Command == command ) ;
71
+ using var _ = new AssertionScope ( ) ;
69
72
70
- kernelEvents
71
- . Should ( )
72
- . NotContain ( e => e is CommandFailed ) ;
73
- }
73
+ result . Events . Should ( ) . ContainSingle < CommandSucceeded > ( e => e . Command == command ) ;
74
74
75
- [ Fact ]
76
- public async Task Commands_sent_within_the_code_of_another_command_publish_error_events_on_CompositeKernel_for_failures ( )
77
- {
78
- using var kernel = new CompositeKernel
79
- {
80
- new CSharpKernel ( "cs1" ) ,
81
- new CSharpKernel ( "cs2" )
82
- } ;
75
+ result . Events . Should ( )
76
+ . NotContain ( e =>
77
+ e is CommandSucceeded &&
78
+ e . Command . TargetKernelName == "cs2" ) ;
79
+ }
83
80
84
- var command = new SubmitCode ( $@ "
81
+ [ Fact ]
82
+ public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_CommandFailed_to_the_outer_result ( )
83
+ {
84
+ using var kernel = new CompositeKernel
85
+ {
86
+ new CSharpKernel ( "cs1" ) ,
87
+ new CSharpKernel ( "cs2" )
88
+ } ;
89
+ var command = new SubmitCode ( $@ "
85
90
#!cs1
86
91
using { typeof ( Kernel ) . Namespace } ;
87
92
using { typeof ( KernelCommand ) . Namespace } ;
88
93
await Kernel.Root.SendAsync(new SubmitCode(""error"", ""cs2""));
89
94
" ) ;
90
- var result = await kernel . SendAsync ( command ) ;
91
-
92
- result . Events . Should ( )
93
- . ContainSingle < ErrorProduced > ( )
94
- . Which
95
- . Message
96
- . Should ( )
97
- . Be ( "(1,1): error CS0103: The name 'error' does not exist in the current context" ) ;
98
- }
95
+ var result = await kernel . SendAsync ( command ) ;
99
96
100
- [ Fact ]
101
- public async Task Commands_sent_within_the_code_of_another_command_publish_CommandSucceeded_to_the_inner_result ( )
102
- {
103
- using var kernel = new CompositeKernel
104
- {
105
- new CSharpKernel ( ) ,
106
- new FSharpKernel ( )
107
- } ;
108
- kernel . DefaultKernelName = "csharp" ;
97
+ result . Events . Should ( )
98
+ . ContainSingle < CommandSucceeded > ( e => e . Command == command ) ;
109
99
110
- var result = await kernel . SubmitCodeAsync (
111
- @"
100
+ result . Events
101
+ . Should ( )
102
+ . NotContain ( e => e is CommandFailed ) ;
103
+ }
104
+
105
+ [ Fact ]
106
+ public async Task Commands_sent_within_the_code_of_another_command_do_not_publish_events_to_the_outer_result ( )
107
+ {
108
+ using var kernel = new CompositeKernel
109
+ {
110
+ new CSharpKernel ( "cs1" ) ,
111
+ new CSharpKernel ( "cs2" )
112
+ } ;
113
+
114
+ var command = new SubmitCode ( $ """
115
+ using { typeof ( Kernel ) . Namespace } ;
116
+ using { typeof ( KernelCommand ) . Namespace } ;
117
+ var result = await Kernel.Root.SendAsync(new SubmitCode("123.Display();\n456", "cs2"));
118
+ """ , "cs1" ) ;
119
+
120
+ var result = await kernel . SendAsync ( command ) ;
121
+
122
+ using var _ = new AssertionScope ( ) ;
123
+ result . Events . Should ( ) . NotContainErrors ( ) ;
124
+ result . Events . Should ( ) . NotContain ( e => e is DisplayedValueProduced ) ;
125
+ result . Events . Should ( ) . NotContain ( e => e is ReturnValueProduced ) ;
126
+ }
127
+
128
+ [ Fact ]
129
+ public async Task Commands_sent_within_the_code_of_another_command_publish_CommandSucceeded_to_the_inner_result ( )
130
+ {
131
+ using var kernel = new CompositeKernel
132
+ {
133
+ new CSharpKernel ( ) ,
134
+ new FSharpKernel ( )
135
+ } ;
136
+ kernel . DefaultKernelName = "csharp" ;
137
+
138
+ var result = await kernel . SubmitCodeAsync (
139
+ @"
112
140
using System.Reactive.Linq;
113
141
using Microsoft.DotNet.Interactive;
114
142
using Microsoft.DotNet.Interactive.Commands;
@@ -118,24 +146,24 @@ public async Task Commands_sent_within_the_code_of_another_command_publish_Comma
118
146
result.Events.Last()
119
147
" ) ;
120
148
121
- result . Events . Should ( ) . NotContainErrors ( ) ;
149
+ result . Events . Should ( ) . NotContainErrors ( ) ;
122
150
123
- result . Events
124
- . Should ( )
125
- . ContainSingle < ReturnValueProduced > ( e => e . Value is CommandSucceeded ) ;
126
- }
151
+ result . Events
152
+ . Should ( )
153
+ . ContainSingle < ReturnValueProduced > ( e => e . Value is CommandSucceeded ) ;
154
+ }
127
155
128
- [ Fact ]
129
- public async Task Commands_sent_within_the_code_of_another_command_publish_CommandFailed_to_the_inner_result ( )
130
- {
131
- using var kernel = new CompositeKernel
156
+ [ Fact ]
157
+ public async Task Commands_sent_within_the_code_of_another_command_publish_CommandFailed_to_the_inner_result ( )
132
158
{
133
- new CSharpKernel ( "cs1" ) ,
134
- new CSharpKernel ( "cs2" )
135
- } ;
136
-
137
- var result = await kernel . SendAsync ( new SubmitCode (
138
- @"
159
+ using var kernel = new CompositeKernel
160
+ {
161
+ new CSharpKernel ( "cs1" ) ,
162
+ new CSharpKernel ( "cs2" )
163
+ } ;
164
+
165
+ var result = await kernel . SendAsync ( new SubmitCode (
166
+ @"
139
167
using System.Reactive.Linq;
140
168
using Microsoft.DotNet.Interactive;
141
169
using Microsoft.DotNet.Interactive.Commands;
@@ -145,8 +173,9 @@ public async Task Commands_sent_within_the_code_of_another_command_publish_Comma
145
173
result.Events.Last()
146
174
" , "cs1" ) ) ;
147
175
148
- result . Events
149
- . Should ( )
150
- . ContainSingle < ReturnValueProduced > ( e => e . Value is CommandFailed ) ;
176
+ result . Events
177
+ . Should ( )
178
+ . ContainSingle < ReturnValueProduced > ( e => e . Value is CommandFailed ) ;
179
+ }
151
180
}
152
181
}
0 commit comments