You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NotebookStudy.Test
|
|
{
|
|
public class CSharpKernelTest
|
|
{
|
|
|
|
private ITestOutputHelper _output;
|
|
public CSharpKernelTest(ITestOutputHelper output)
|
|
{
|
|
_output = output;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Test()
|
|
{
|
|
var kernel = new CSharpKernel();
|
|
|
|
var textCode = """
|
|
var msg = "我是C#";
|
|
Console.Write("Hello,");
|
|
Console.Write("C#!");
|
|
""";
|
|
var result = await kernel.SubmitCodeAsync(textCode);
|
|
|
|
//从结果中,找到标准输出对象
|
|
string outText = "";
|
|
var standardOutputValueProduceds = result.Events.Where(e => e.GetType().IsAssignableTo(typeof(StandardOutputValueProduced))).Cast<StandardOutputValueProduced>();
|
|
foreach (var produceds in standardOutputValueProduceds)
|
|
{
|
|
outText += produceds.FormattedValues.First().Value;
|
|
}
|
|
|
|
_output.WriteLine(outText);
|
|
|
|
Assert.Equal("Hello,C#!", outText);
|
|
|
|
}
|
|
}
|
|
}
|