-
Notifications
You must be signed in to change notification settings - Fork 368
/
KernelTests.SubmissionCount.cs
142 lines (114 loc) · 4.08 KB
/
KernelTests.SubmissionCount.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
132
133
134
135
136
137
138
139
140
141
142
// 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;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Tests.Connection;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.Tests;
public partial class KernelTests
{
public class SubmissionCount
{
[Fact]
public async Task Split_submissions_only_increment_count_by_one()
{
using var kernel = new CompositeKernel
{
new FakeKernel("one"),
new FakeKernel("two"),
};
await kernel.SubmitCodeAsync(@"
#!one
// do something
#!two
// do something
");
kernel.SubmissionCount.Should().Be(1);
}
[Fact]
public async Task SubmitCode_is_the_only_command_that_increments_submission_count()
{
using var kernel = new CompositeKernel
{
new FakeKernel("one"),
new FakeKernel("two"),
};
foreach (var command in SerializationTests.Commands().SelectMany(cs => cs).Where(c => c is not SubmitCode))
{
await kernel.SendAsync((KernelCommand)command);
}
kernel.SubmissionCount.Should().Be(0);
}
[Fact]
public async Task Deferred_commands_do_not_increment_count()
{
using var kernel = new CompositeKernel
{
new FakeKernel("one"),
new FakeKernel("two"),
};
kernel.DeferCommand(new SubmitCode(""));
await kernel.SendAsync(new RequestKernelInfo());
kernel.SubmissionCount.Should().Be(0);
}
[Fact]
public async Task Nested_submissions_do_not_increment_submission_count()
{
using var kernel = new CompositeKernel
{
new CSharpKernel(),
new FakeKernel("fake")
};
var result = await kernel.SendAsync(new SubmitCode(@"
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Commands;
await Kernel.Root.SendAsync(new SubmitCode(""123"", ""fake""));
await Kernel.Root.SendAsync(new SubmitCode(""456"", ""fake""));
", "csharp"));
result.Events.Should().NotContainErrors();
kernel.SubmissionCount.Should().Be(1);
}
[Fact]
public async Task Non_user_submissions_do_not_increment_submission_count()
{
var csharp2 = new CSharpKernel("csharp2");
using var kernel = new CompositeKernel
{
new CSharpKernel(),
csharp2
};
using var _ = kernel
.KernelEvents
.OfType<DisplayEvent>()
.Subscribe(@event =>
{
if (@event.Command.TargetKernelName == "csharp2")
{
return;
}
var command = new SubmitCode($"\"Received {@event.Value}\"");
csharp2.SendAsync(command).ConfigureAwait(false);
});
await kernel.SendAsync(new SubmitCode("1", "csharp"));
await kernel.SendAsync(new SubmitCode("2", "csharp"));
kernel.SubmissionCount.Should().Be(2);
}
[Fact]
public async Task Failed_commands_increment_submission_count()
{
using var kernel = new CompositeKernel
{
new CSharpKernel()
};
await kernel.SubmitCodeAsync("this does not compile");
kernel.SubmissionCount.Should().Be(1);
}
}
}