2024-08-08 10:49:58 -07:00
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// InProcessDotnetInteractiveKernelBuilderTest.cs
|
2024-08-08 10:49:58 -07:00
|
|
|
|
|
|
|
|
|
using AutoGen.DotnetInteractive.Extension;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AutoGen.DotnetInteractive.Tests;
|
|
|
|
|
|
2024-08-19 19:33:52 -07:00
|
|
|
|
[Collection("Sequential")]
|
2024-08-09 18:53:48 -07:00
|
|
|
|
public class InProcessDotnetInteractiveKernelBuilderTest
|
2024-08-08 10:49:58 -07:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItAddCSharpKernelTestAsync()
|
|
|
|
|
{
|
2024-08-19 19:33:52 -07:00
|
|
|
|
using var kernel = DotnetInteractiveKernelBuilder
|
2024-08-09 18:53:48 -07:00
|
|
|
|
.CreateEmptyInProcessKernelBuilder()
|
2024-08-08 10:49:58 -07:00
|
|
|
|
.AddCSharpKernel()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var csharpCode = """
|
|
|
|
|
#r "nuget:Microsoft.ML, 1.5.2"
|
|
|
|
|
Console.WriteLine("Hello, World!");
|
|
|
|
|
""";
|
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
var result = await kernel.RunSubmitCodeCommandAsync(csharpCode, "csharp");
|
2024-08-08 10:49:58 -07:00
|
|
|
|
result.Should().Contain("Hello, World!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItAddPowershellKernelTestAsync()
|
|
|
|
|
{
|
2024-08-19 19:33:52 -07:00
|
|
|
|
using var kernel = DotnetInteractiveKernelBuilder
|
2024-08-09 18:53:48 -07:00
|
|
|
|
.CreateEmptyInProcessKernelBuilder()
|
2024-08-08 10:49:58 -07:00
|
|
|
|
.AddPowershellKernel()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var powershellCode = @"
|
|
|
|
|
Write-Host 'Hello, World!'
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
var result = await kernel.RunSubmitCodeCommandAsync(powershellCode, "pwsh");
|
|
|
|
|
result.Should().Contain("Hello, World!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItAddFSharpKernelTestAsync()
|
|
|
|
|
{
|
2024-08-19 19:33:52 -07:00
|
|
|
|
using var kernel = DotnetInteractiveKernelBuilder
|
2024-08-09 18:53:48 -07:00
|
|
|
|
.CreateEmptyInProcessKernelBuilder()
|
2024-08-08 10:49:58 -07:00
|
|
|
|
.AddFSharpKernel()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fsharpCode = """
|
|
|
|
|
#r "nuget:Microsoft.ML, 1.5.2"
|
|
|
|
|
printfn "Hello, World!"
|
|
|
|
|
""";
|
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
var result = await kernel.RunSubmitCodeCommandAsync(fsharpCode, "fsharp");
|
2024-08-08 10:49:58 -07:00
|
|
|
|
result.Should().Contain("Hello, World!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ItAddPythonKernelTestAsync()
|
|
|
|
|
{
|
2024-08-19 19:33:52 -07:00
|
|
|
|
using var kernel = DotnetInteractiveKernelBuilder
|
2024-08-09 18:53:48 -07:00
|
|
|
|
.CreateEmptyInProcessKernelBuilder()
|
2024-08-08 10:49:58 -07:00
|
|
|
|
.AddPythonKernel("python3")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var pythonCode = """
|
|
|
|
|
%pip install numpy
|
|
|
|
|
print('Hello, World!')
|
|
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
var result = await kernel.RunSubmitCodeCommandAsync(pythonCode, "python");
|
|
|
|
|
result.Should().Contain("Hello, World!");
|
|
|
|
|
}
|
|
|
|
|
}
|