Address some static analysis and TODOs (#12)
This commit is contained in:
parent
3de19d38e4
commit
33b9582199
5 changed files with 132 additions and 123 deletions
|
|
@ -220,18 +220,17 @@ public class McpServerBuilderExtensionsToolsTests
|
|||
Assert.Contains("'NotRegisteredTool'", exception.Message);
|
||||
}
|
||||
|
||||
// TODO: https://github.com/dotnet/extensions/issues/6124
|
||||
//[Fact]
|
||||
//public async Task Throws_Exception_Missing_Parameter()
|
||||
//{
|
||||
// _builder.Object.WithTools(typeof(EchoTool));
|
||||
[Fact(Skip = "https://github.com/dotnet/extensions/issues/6124")]
|
||||
public async Task Throws_Exception_Missing_Parameter()
|
||||
{
|
||||
_builder.Object.WithTools(typeof(EchoTool));
|
||||
|
||||
// var serviceProvider = _services.BuildServiceProvider();
|
||||
// var options = serviceProvider.GetRequiredService<IOptions<McpServerHandlers>>().Value;
|
||||
var serviceProvider = _services.BuildServiceProvider();
|
||||
var options = serviceProvider.GetRequiredService<IOptions<McpServerHandlers>>().Value;
|
||||
|
||||
// var exception = await Assert.ThrowsAsync<McpServerException>(async () => await options.CallToolHandler!(new(Mock.Of<IMcpServer>(), new() { Name = "Echo" }), CancellationToken.None));
|
||||
// Assert.Equal("Missing required argument 'message'.", exception.Message);
|
||||
//}
|
||||
var exception = await Assert.ThrowsAsync<McpServerException>(async () => await options.CallToolHandler!(new(Mock.Of<IMcpServer>(), new() { Name = "Echo" }), CancellationToken.None));
|
||||
Assert.Equal("Missing required argument 'message'.", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Throws_Exception_For_Null_Types()
|
||||
|
|
@ -357,26 +356,6 @@ public class McpServerBuilderExtensionsToolsTests
|
|||
}
|
||||
}
|
||||
|
||||
public interface IDependendService
|
||||
{
|
||||
}
|
||||
|
||||
private class EchoToolWithDi
|
||||
{
|
||||
public EchoToolWithDi(IDependendService service)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[McpTool, Description("Echoes the input back to the client.")]
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
public Task<string> Echo(string message)
|
||||
#pragma warning restore CA1822 // Mark members as static
|
||||
{
|
||||
return Task.FromResult("hello " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public class ComplexObject
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ namespace ModelContextProtocol.Tests;
|
|||
|
||||
public class EverythingSseServerFixture : IAsyncDisposable
|
||||
{
|
||||
private int _port;
|
||||
private string _containerName;
|
||||
private readonly int _port;
|
||||
private readonly string _containerName;
|
||||
|
||||
public static bool IsDockerAvailable => _isDockerAvailable ??= CheckIsDockerAvailable();
|
||||
private static bool? _isDockerAvailable;
|
||||
|
|
|
|||
|
|
@ -44,9 +44,11 @@ public static class ProtocolTypeTests
|
|||
public static void ToolInputSchema_AcceptsValidSchemaDocuments(string validSchema)
|
||||
{
|
||||
using var document = JsonDocument.Parse(validSchema);
|
||||
var tool = new Tool();
|
||||
Tool tool = new()
|
||||
{
|
||||
InputSchema = document.RootElement
|
||||
};
|
||||
|
||||
tool.InputSchema = document.RootElement;
|
||||
Assert.True(JsonElement.DeepEquals(document.RootElement, tool.InputSchema));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class StdioServerTransportTests
|
|||
TextWriter oldOut = Console.Out;
|
||||
try
|
||||
{
|
||||
var output = new StringWriter();
|
||||
using var output = new StringWriter();
|
||||
|
||||
Console.SetIn(new StringReader(""));
|
||||
Console.SetOut(output);
|
||||
|
|
|
|||
|
|
@ -8,14 +8,12 @@ public class MockHttpHandler : HttpMessageHandler
|
|||
{
|
||||
if (RequestHandler == null)
|
||||
throw new InvalidOperationException($"No {nameof(RequestHandler)} was set! Please set handler first and make request afterwards.");
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
throw new OperationCanceledException(cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var result = await RequestHandler.Invoke(request);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
throw new OperationCanceledException(cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue