parent
36a70a03f8
commit
5cc7c00456
1 changed files with 480 additions and 22 deletions
|
|
@ -92,21 +92,21 @@ public class McpServerTests : LoggedTest
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestSamplingAsync_Should_Throw_Exception_If_Client_Does_Not_Support_Sampling()
|
||||
public async Task SampleAsync_Should_Throw_Exception_If_Client_Does_Not_Support_Sampling()
|
||||
{
|
||||
// Arrange
|
||||
await using var transport = new TestServerTransport();
|
||||
await using var server = McpServerFactory.Create(transport, _options, LoggerFactory);
|
||||
SetClientCapabilities(server, new ClientCapabilities());
|
||||
|
||||
var action = async () => await server.RequestSamplingAsync(new CreateMessageRequestParams { Messages = [] }, CancellationToken.None);
|
||||
var action = async () => await server.SampleAsync(new CreateMessageRequestParams { Messages = [] }, CancellationToken.None);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(action);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestSamplingAsync_Should_SendRequest()
|
||||
public async Task SampleAsync_Should_SendRequest()
|
||||
{
|
||||
// Arrange
|
||||
await using var transport = new TestServerTransport();
|
||||
|
|
@ -116,7 +116,7 @@ public class McpServerTests : LoggedTest
|
|||
var runTask = server.RunAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
// Act
|
||||
var result = await server.RequestSamplingAsync(new CreateMessageRequestParams { Messages = [] }, CancellationToken.None);
|
||||
var result = await server.SampleAsync(new CreateMessageRequestParams { Messages = [] }, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.NotEmpty(transport.SentMessages);
|
||||
|
|
@ -161,6 +161,40 @@ public class McpServerTests : LoggedTest
|
|||
await runTask;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ElicitAsync_Should_Throw_Exception_If_Client_Does_Not_Support_Elicitation()
|
||||
{
|
||||
// Arrange
|
||||
await using var transport = new TestServerTransport();
|
||||
await using var server = McpServerFactory.Create(transport, _options, LoggerFactory);
|
||||
SetClientCapabilities(server, new ClientCapabilities());
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(async () => await server.ElicitAsync(new ElicitRequestParams(), CancellationToken.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ElicitAsync_Should_SendRequest()
|
||||
{
|
||||
// Arrange
|
||||
await using var transport = new TestServerTransport();
|
||||
await using var server = McpServerFactory.Create(transport, _options, LoggerFactory);
|
||||
SetClientCapabilities(server, new ClientCapabilities { Elicitation = new ElicitationCapability() });
|
||||
var runTask = server.RunAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
// Act
|
||||
var result = await server.ElicitAsync(new ElicitRequestParams(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotEmpty(transport.SentMessages);
|
||||
Assert.IsType<JsonRpcRequest>(transport.SentMessages[0]);
|
||||
Assert.Equal(RequestMethods.ElicitationCreate, ((JsonRpcRequest)transport.SentMessages[0]).Method);
|
||||
|
||||
await transport.DisposeAsync();
|
||||
await runTask;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Can_Handle_Ping_Requests()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue