Make options types fully mutable (#107)

This commit is contained in:
Stephen Halter 2025-03-26 10:39:49 -07:00 • committed by GitHub
commit 95a017a03a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 97 additions and 172 deletions

View file

@ -15,7 +15,6 @@ public class SseServerIntegrationTestFixture : IAsyncDisposable
private readonly DelegatingTestOutputHelper _delegatingTestOutputHelper = new();
private readonly ILoggerFactory _redirectingLoggerFactory;
public McpClientOptions DefaultOptions { get; }
public McpServerConfig DefaultConfig { get; }
public SseServerIntegrationTestFixture()
@ -26,11 +25,6 @@ public class SseServerIntegrationTestFixture : IAsyncDisposable
builder.AddProvider(new XunitLoggerProvider(_delegatingTestOutputHelper));
});
DefaultOptions = new()
{
ClientInfo = new() { Name = "IntegrationTestClient", Version = "1.0.0" },
};
DefaultConfig = new McpServerConfig
{
Id = "test_server",
@ -43,6 +37,11 @@ public class SseServerIntegrationTestFixture : IAsyncDisposable
_serverTask = Program.MainAsync([], _redirectingLoggerFactory, _stopCts.Token);
}
public static McpClientOptions CreateDefaultClientOptions() => new()
{
ClientInfo = new() { Name = "IntegrationTestClient", Version = "1.0.0" },
};
public void Initialize(ITestOutputHelper output)
{
_delegatingTestOutputHelper.CurrentTestOutputHelper = output;

View file

@ -19,7 +19,7 @@ public class SseServerIntegrationTests : LoggedTest, IClassFixture<SseServerInte
{
return McpClientFactory.CreateAsync(
_fixture.DefaultConfig,
options ?? _fixture.DefaultOptions,
options ?? SseServerIntegrationTestFixture.CreateDefaultClientOptions(),
loggerFactory: LoggerFactory);
}
@ -201,28 +201,22 @@ public class SseServerIntegrationTests : LoggedTest, IClassFixture<SseServerInte
// Set up the sampling handler
int samplingHandlerCalls = 0;
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
var options = _fixture.DefaultOptions with
var options = SseServerIntegrationTestFixture.CreateDefaultClientOptions();
options.Capabilities ??= new();
options.Capabilities.Sampling ??= new();
options.Capabilities.Sampling.SamplingHandler = async (_, _) =>
{
Capabilities = new()
samplingHandlerCalls++;
return new CreateMessageResult
{
Sampling = new()
Model = "test-model",
Role = "assistant",
Content = new Content
{
SamplingHandler = async (_, _) =>
{
samplingHandlerCalls++;
return new CreateMessageResult
{
Model = "test-model",
Role = "assistant",
Content = new Content
{
Type = "text",
Text = "Test response"
}
};
}
Type = "text",
Text = "Test response"
}
}
};
};
var client = await GetClientAsync(options);
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously