csharp-sdk/tests/mcpdotnet.Tests/EverythingSseServerFixture.cs
Peder Holdgaard Pedersen 30f3f192ca
SSE ClientTransport fixes and tests (#27)
SSE fixes
Additional SSE integration tests with everything server
2025-02-27 21:14:20 +01:00

63 lines
No EOL
1.9 KiB
C#

using System.Diagnostics;
namespace McpDotNet.Tests;
public class EverythingSseServerFixture : IAsyncDisposable
{
private Process _process;
public async Task StartAsync()
{
var processStartInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = "run -p 3001:3001 --rm tzolov/mcp-everything-server:v1",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
};
_process = Process.Start(processStartInfo);
// Wait for the server to start
await Task.Delay(10000);
}
public async ValueTask DisposeAsync()
{
try
{
// Find the container ID
var psInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = "ps -q --filter ancestor=tzolov/mcp-everything-server:v1",
RedirectStandardOutput = true,
UseShellExecute = false
};
using var psProcess = Process.Start(psInfo);
string containerId = await psProcess.StandardOutput.ReadToEndAsync();
containerId = containerId.Trim();
if (!string.IsNullOrEmpty(containerId))
{
// Stop the container
var stopInfo = new ProcessStartInfo
{
FileName = "docker",
Arguments = $"stop {containerId}",
UseShellExecute = false
};
using var stopProcess = Process.Start(stopInfo);
await stopProcess.WaitForExitAsync();
}
}
catch (Exception ex)
{
// Log the exception but don't throw
Console.Error.WriteLine($"Error stopping Docker container: {ex.Message}");
}
}
}