Enable .NET SDK code analyzers (#41)

This commit is contained in:
Stephen Toub 2025-03-08 11:18:09 -05:00 • committed by GitHub
commit 587e05f057
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 301 additions and 151 deletions

View file

@ -89,7 +89,7 @@ public class AIFunctionUtilitiesTests
Assert.Equal("object", resultObj.GetProperty("type").GetString());
Assert.Equal("minimal", resultObj.GetProperty("title").GetString());
Assert.Equal("Minimal tool", resultObj.GetProperty("description").GetString());
Assert.True(resultObj.GetProperty("properties").GetRawText() == "{}");
Assert.Equal("{}", resultObj.GetProperty("properties").GetRawText());
Assert.Empty(resultObj.GetProperty("required").EnumerateArray());
}
}

View file

@ -27,7 +27,7 @@ internal static class Program
{
Log.Logger.Information("Starting server...");
McpServerOptions options = new McpServerOptions()
McpServerOptions options = new()
{
ServerInfo = new Implementation() { Name = "TestServer", Version = "1.0.0" },
Capabilities = new ServerCapabilities()
@ -41,7 +41,7 @@ internal static class Program
};
var loggerFactory = CreateLoggerFactory();
McpServerFactory factory = new McpServerFactory(new StdioServerTransport("TestServer", loggerFactory), options, loggerFactory);
McpServerFactory factory = new(new StdioServerTransport("TestServer", loggerFactory), options, loggerFactory);
IMcpServer server = factory.CreateServer();
Log.Logger.Information("Server object created, registering handlers.");

View file

@ -225,7 +225,7 @@ public class ClientIntegrationTests : IClassFixture<ClientIntegrationTestFixture
Assert.NotNull(result);
Assert.Single(result.Completion.Values);
Assert.True(result.Completion.Values[0] == "1");
Assert.Equal("1", result.Completion.Values[0]);
}
/// <summary>
@ -256,7 +256,7 @@ public class ClientIntegrationTests : IClassFixture<ClientIntegrationTestFixture
Assert.NotNull(result);
Assert.Single(result.Completion.Values);
Assert.True(result.Completion.Values[0] == "formal");
Assert.Equal("formal", result.Completion.Values[0]);
}
[Fact]

View file

@ -131,13 +131,13 @@ public class McpServerBuilderExtensionsToolsTests
private static class EchoTool
{
[McpTool(Description = "Echoes the input back to the client.")]
public static string Echo([McpParameter(true, Description = "the echoes message")] string message)
[McpTool(description: "Echoes the input back to the client.")]
public static string Echo([McpParameter(true, description: "the echoes message")] string message)
{
return "hello " + message;
}
[McpTool(Name = "double_echo", Description = "Echoes the input back to the client.")]
[McpTool(name: "double_echo", description: "Echoes the input back to the client.")]
public static string Echo2([McpParameter(true)] string message)
{
return "hello hello" + message;
@ -154,7 +154,7 @@ public class McpServerBuilderExtensionsToolsTests
{
}
[McpTool(Description = "Echoes the input back to the client.")]
[McpTool(description: "Echoes the input back to the client.")]
public Task<string> Echo([McpParameter(true)] string message)
{
return Task.FromResult("hello " + message);

View file

@ -179,7 +179,7 @@ public sealed class TestSseServer : IAsyncDisposable
/// Handle POST /message endpoint.
/// Echo the content back to the caller and broadcast it over SSE as well.
/// </summary>
private async Task HandlePostMessageAsync(HttpListenerContext context, CancellationToken ct)
private async Task HandlePostMessageAsync(HttpListenerContext context, CancellationToken cancellationToken)
{
var request = context.Request;
var response = context.Response;
@ -187,7 +187,7 @@ public sealed class TestSseServer : IAsyncDisposable
try
{
using var reader = new StreamReader(request.InputStream);
string content = await reader.ReadToEndAsync(ct);
string content = await reader.ReadToEndAsync(cancellationToken);
var jsonRpcNotification = JsonSerializer.Deserialize<JsonRpcNotification>(content);
if (jsonRpcNotification != null && jsonRpcNotification.Method != "initialize")
@ -200,7 +200,7 @@ public sealed class TestSseServer : IAsyncDisposable
// Write "accepted" as the response body
using var writer = new StreamWriter(response.OutputStream);
await writer.WriteAsync("accepted");
await writer.FlushAsync();
await writer.FlushAsync(cancellationToken);
return;
}
@ -220,7 +220,7 @@ public sealed class TestSseServer : IAsyncDisposable
// Write "accepted" as the response body
using var writer = new StreamWriter(response.OutputStream);
await writer.WriteAsync("accepted");
await writer.FlushAsync(ct);
await writer.FlushAsync(cancellationToken);
// Then process the message and send the response via SSE
if (jsonRpcRequest != null)