2024-05-13 20:40:26 -07:00
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// DotnetInteractiveServiceTest.cs
|
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
//using FluentAssertions;
|
|
|
|
|
//using Xunit;
|
|
|
|
|
//using Xunit.Abstractions;
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
//namespace AutoGen.DotnetInteractive.Tests;
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
//public class DotnetInteractiveServiceTest : IDisposable
|
|
|
|
|
//{
|
|
|
|
|
// private ITestOutputHelper _output;
|
|
|
|
|
// private InteractiveService _interactiveService;
|
|
|
|
|
// private string _workingDir;
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// public DotnetInteractiveServiceTest(ITestOutputHelper output)
|
|
|
|
|
// {
|
|
|
|
|
// _output = output;
|
|
|
|
|
// _workingDir = Path.Combine(Path.GetTempPath(), "test", Path.GetRandomFileName());
|
|
|
|
|
// if (!Directory.Exists(_workingDir))
|
|
|
|
|
// {
|
|
|
|
|
// Directory.CreateDirectory(_workingDir);
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// _interactiveService = new InteractiveService(_workingDir);
|
|
|
|
|
// _interactiveService.StartAsync(_workingDir, default).Wait();
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// public void Dispose()
|
|
|
|
|
// {
|
|
|
|
|
// _interactiveService.Dispose();
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// [Fact]
|
|
|
|
|
// public async Task ItRunCSharpCodeSnippetTestsAsync()
|
|
|
|
|
// {
|
|
|
|
|
// var cts = new CancellationTokenSource();
|
|
|
|
|
// var isRunning = await _interactiveService.StartAsync(_workingDir, cts.Token);
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// isRunning.Should().BeTrue();
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// _interactiveService.IsRunning().Should().BeTrue();
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// // test code snippet
|
|
|
|
|
// var hello_world = @"
|
|
|
|
|
//Console.WriteLine(""hello world"");
|
|
|
|
|
//";
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// await this.TestCSharpCodeSnippet(_interactiveService, hello_world, "hello world");
|
|
|
|
|
// await this.TestCSharpCodeSnippet(
|
|
|
|
|
// _interactiveService,
|
|
|
|
|
// code: @"
|
|
|
|
|
//Console.WriteLine(""hello world""
|
|
|
|
|
//",
|
|
|
|
|
// expectedOutput: "Error: (2,32): error CS1026: ) expected");
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// await this.TestCSharpCodeSnippet(
|
|
|
|
|
// service: _interactiveService,
|
|
|
|
|
// code: "throw new Exception();",
|
|
|
|
|
// expectedOutput: "Error: System.Exception: Exception of type 'System.Exception' was thrown");
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// [Fact]
|
|
|
|
|
// public async Task ItRunPowershellScriptTestsAsync()
|
|
|
|
|
// {
|
|
|
|
|
// // test power shell
|
|
|
|
|
// var ps = @"Write-Output ""hello world""";
|
|
|
|
|
// await this.TestPowershellCodeSnippet(_interactiveService, ps, "hello world");
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// private async Task TestPowershellCodeSnippet(InteractiveService service, string code, string expectedOutput)
|
|
|
|
|
// {
|
|
|
|
|
// var result = await service.SubmitPowershellCodeAsync(code, CancellationToken.None);
|
|
|
|
|
// result.Should().StartWith(expectedOutput);
|
|
|
|
|
// }
|
2024-05-13 20:40:26 -07:00
|
|
|
|
|
2024-08-09 18:53:48 -07:00
|
|
|
|
// private async Task TestCSharpCodeSnippet(InteractiveService service, string code, string expectedOutput)
|
|
|
|
|
// {
|
|
|
|
|
// var result = await service.SubmitCSharpCodeAsync(code, CancellationToken.None);
|
|
|
|
|
// result.Should().StartWith(expectedOutput);
|
|
|
|
|
// }
|
|
|
|
|
//}
|