-
Notifications
You must be signed in to change notification settings - Fork 368
/
ExplainCodeExtensionTest.cs
68 lines (57 loc) · 1.88 KB
/
ExplainCodeExtensionTest.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
// 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 Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Mermaid;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.ExtensionLab.Tests;
public class ExplainCodeExtensionTest
{
[Fact]
public async Task it_requires_mermaid_kernel_to_load()
{
using var kernel = new CompositeKernel
{
new CSharpKernel(),
};
var extension = new ExplainCodeExtension();
var executeTask = () => extension.OnLoadAsync(kernel);
await executeTask.Should().ThrowAsync<KernelException>();
}
[Fact]
public async Task generates_interaction_diagram_for_top_level_statements()
{
using var kernel = new CompositeKernel
{
new CSharpKernel(),
new MermaidKernel()
};
var events = kernel.KernelEvents.ToSubscribedList();
var extension = new ExplainCodeExtension();
await extension.OnLoadAsync(kernel);
await kernel.SendAsync(new SubmitCode(@"
#!explain
using System;
var data = new[] { 1, 2, 3 };
for (var i = 0; i < data.Length; i++)
{
Console.WriteLine(i.ToString());
}
", targetKernelName: "csharp"));
events.Should().ContainSingle<DisplayedValueProduced>()
.Which
.Value.ToString()
.Should()
.Contain(@"sequenceDiagram
loop
CodeSubmission->>+i: invoke ToString
i->>-CodeSubmission: return
CodeSubmission->>+Console: invoke WriteLine
Console->>-CodeSubmission: return
end".Replace("\r\n", "\n"));
}
}