Add more tests (#51)

* Add more tests

* Fix some code smells

* Remove more code smells

* Combine "ServerIntegrationTests" and "ClientIntegrationTests" because both are client integration tests just using different servers

* Clean up resources after test

* Improve kill logic for spawned child processes

* Improved testability for Stdio

* Fix SseIntegration tests
This commit is contained in:
Toni Wenzel 2025-03-12 18:55:52 +01:00 • committed by GitHub
commit b5076263d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging;
namespace McpDotNet.Tests;
[Trait("Execution", "Manual")]
public class SseIntegrationTests
{
[Fact]
@ -37,7 +36,7 @@ public class SseIntegrationTests
Location = "http://localhost:5000/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory
@ -80,7 +79,7 @@ public class SseIntegrationTests
Location = "http://localhost:3001/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory
@ -128,7 +127,7 @@ public class SseIntegrationTests
Location = "http://localhost:3001/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory
@ -137,11 +136,10 @@ public class SseIntegrationTests
// Set up the sampling handler
int samplingHandlerCalls = 0;
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
client.SamplingHandler = async (_, _) =>
client.SamplingHandler = (_, _) =>
{
samplingHandlerCalls++;
return new CreateMessageResult
return Task.FromResult(new CreateMessageResult
{
Model = "test-model",
Role = "assistant",
@ -150,9 +148,8 @@ public class SseIntegrationTests
Type = "text",
Text = "Test response"
}
};
});
};
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
// Call the server's sampleLLM tool which should trigger our sampling handler
var result = await client.CallToolAsync(
@ -198,7 +195,7 @@ public class SseIntegrationTests
Location = "http://localhost:5000/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory
@ -243,7 +240,7 @@ public class SseIntegrationTests
Location = "http://localhost:5000/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory
@ -298,7 +295,7 @@ public class SseIntegrationTests
Location = "http://localhost:5000/sse"
};
var factory = new McpClientFactory(
using var factory = new McpClientFactory(
[defaultConfig],
defaultOptions,
loggerFactory