Skip to content

Commit 77c485a

Browse files
committed
Revert remnants of previous testing approach
1 parent 3e5cce5 commit 77c485a

File tree

7 files changed

+25
-373
lines changed

7 files changed

+25
-373
lines changed

tests/ModelContextProtocol.AspNetCore.Tests/HttpServerIntegrationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace ModelContextProtocol.AspNetCore.Tests;
66

7-
public abstract class HttpServerIntegrationTests : LoggedTest, IClassFixture<SseServerWithXunitLoggerFixture>
7+
public abstract class HttpServerIntegrationTests : LoggedTest, IClassFixture<SseServerIntegrationTestFixture>
88
{
9-
protected readonly SseServerWithXunitLoggerFixture _fixture;
9+
protected readonly SseServerIntegrationTestFixture _fixture;
1010

11-
public HttpServerIntegrationTests(SseServerWithXunitLoggerFixture fixture, ITestOutputHelper testOutputHelper)
11+
public HttpServerIntegrationTests(SseServerIntegrationTestFixture fixture, ITestOutputHelper testOutputHelper)
1212
: base(testOutputHelper)
1313
{
1414
_fixture = fixture;
@@ -303,4 +303,4 @@ public async Task CallTool_Sse_EchoServer_Concurrently()
303303
Assert.Equal($"Echo: Hello MCP! {i}", textContent.Text);
304304
}
305305
}
306-
}
306+
}

tests/ModelContextProtocol.AspNetCore.Tests/SseServerIntegrationTestFixture.cs

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@
77

88
namespace ModelContextProtocol.AspNetCore.Tests;
99

10-
public abstract class SseServerIntegrationTestFixture : IAsyncDisposable
10+
public class SseServerIntegrationTestFixture : IAsyncDisposable
1111
{
1212
private readonly KestrelInMemoryTransport _inMemoryTransport = new();
13+
1314
private readonly Task _serverTask;
1415
private readonly CancellationTokenSource _stopCts = new();
1516

17+
// XUnit's ITestOutputHelper is created per test, while this fixture is used for
18+
// multiple tests, so this dispatches the output to the current test.
19+
private readonly DelegatingTestOutputHelper _delegatingTestOutputHelper = new();
20+
1621
private HttpClientTransportOptions DefaultTransportOptions { get; set; } = new()
1722
{
1823
Endpoint = new("http://localhost:5000/"),
1924
};
2025

21-
protected SseServerIntegrationTestFixture()
26+
public SseServerIntegrationTestFixture()
2227
{
2328
var socketsHttpHandler = new SocketsHttpHandler
2429
{
@@ -34,10 +39,8 @@ protected SseServerIntegrationTestFixture()
3439
BaseAddress = new("http://localhost:5000/"),
3540
};
3641

37-
_serverTask = Program.MainAsync([], CreateLoggerProvider(), _inMemoryTransport, _stopCts.Token);
42+
_serverTask = Program.MainAsync([], new XunitLoggerProvider(_delegatingTestOutputHelper), _inMemoryTransport, _stopCts.Token);
3843
}
39-
40-
protected abstract ILoggerProvider CreateLoggerProvider();
4144

4245
public HttpClient HttpClient { get; }
4346

@@ -50,17 +53,21 @@ public Task<McpClient> ConnectMcpClientAsync(McpClientOptions? options, ILoggerF
5053
TestContext.Current.CancellationToken);
5154
}
5255

53-
public virtual void Initialize(ITestOutputHelper output, HttpClientTransportOptions clientTransportOptions)
56+
public void Initialize(ITestOutputHelper output, HttpClientTransportOptions clientTransportOptions)
5457
{
58+
_delegatingTestOutputHelper.CurrentTestOutputHelper = output;
5559
DefaultTransportOptions = clientTransportOptions;
5660
}
5761

58-
public virtual void TestCompleted()
62+
public void TestCompleted()
5963
{
64+
_delegatingTestOutputHelper.CurrentTestOutputHelper = null;
6065
}
6166

62-
public virtual async ValueTask DisposeAsync()
67+
public async ValueTask DisposeAsync()
6368
{
69+
_delegatingTestOutputHelper.CurrentTestOutputHelper = null;
70+
6471
HttpClient.Dispose();
6572
_stopCts.Cancel();
6673

@@ -74,50 +81,4 @@ public virtual async ValueTask DisposeAsync()
7481

7582
_stopCts.Dispose();
7683
}
77-
}
78-
79-
/// <summary>
80-
/// SSE server fixture that routes logs to xUnit test output.
81-
/// </summary>
82-
public class SseServerWithXunitLoggerFixture : SseServerIntegrationTestFixture
83-
{
84-
// XUnit's ITestOutputHelper is created per test, while this fixture is used for
85-
// multiple tests, so this dispatches the output to the current test.
86-
private readonly DelegatingTestOutputHelper _delegatingTestOutputHelper = new();
87-
88-
protected override ILoggerProvider CreateLoggerProvider()
89-
=> new XunitLoggerProvider(_delegatingTestOutputHelper);
90-
91-
public override void Initialize(ITestOutputHelper output, HttpClientTransportOptions clientTransportOptions)
92-
{
93-
_delegatingTestOutputHelper.CurrentTestOutputHelper = output;
94-
base.Initialize(output, clientTransportOptions);
95-
}
96-
97-
public override void TestCompleted()
98-
{
99-
_delegatingTestOutputHelper.CurrentTestOutputHelper = null;
100-
base.TestCompleted();
101-
}
102-
103-
public override async ValueTask DisposeAsync()
104-
{
105-
_delegatingTestOutputHelper.CurrentTestOutputHelper = null;
106-
await base.DisposeAsync();
107-
}
108-
}
109-
110-
/// <summary>
111-
/// Fixture for tests that need to inspect server logs using MockLoggerProvider.
112-
/// Use <see cref="SseServerWithXunitLoggerFixture"/> for tests that just need xUnit output.
113-
/// </summary>
114-
public class SseServerWithMockLoggerFixture : SseServerIntegrationTestFixture
115-
{
116-
private readonly MockLoggerProvider _mockLoggerProvider = new();
117-
118-
protected override ILoggerProvider CreateLoggerProvider()
119-
=> _mockLoggerProvider;
120-
121-
public IEnumerable<(string Category, LogLevel LogLevel, EventId EventId, string Message, Exception? Exception)> ServerLogs
122-
=> _mockLoggerProvider.LogMessages;
123-
}
84+
}

tests/ModelContextProtocol.AspNetCore.Tests/SseServerIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ModelContextProtocol.AspNetCore.Tests;
66

7-
public class SseServerIntegrationTests(SseServerWithXunitLoggerFixture fixture, ITestOutputHelper testOutputHelper)
7+
public class SseServerIntegrationTests(SseServerIntegrationTestFixture fixture, ITestOutputHelper testOutputHelper)
88
: HttpServerIntegrationTests(fixture, testOutputHelper)
99

1010
{

tests/ModelContextProtocol.AspNetCore.Tests/StatelessServerIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ModelContextProtocol.AspNetCore.Tests;
44

5-
public class StatelessServerIntegrationTests(SseServerWithXunitLoggerFixture fixture, ITestOutputHelper testOutputHelper)
5+
public class StatelessServerIntegrationTests(SseServerIntegrationTestFixture fixture, ITestOutputHelper testOutputHelper)
66
: StreamableHttpServerIntegrationTests(fixture, testOutputHelper)
77
{
88
protected override HttpClientTransportOptions ClientTransportOptions => new()

tests/ModelContextProtocol.AspNetCore.Tests/StreamableHttpServerIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace ModelContextProtocol.AspNetCore.Tests;
55

6-
public class StreamableHttpServerIntegrationTests(SseServerWithXunitLoggerFixture fixture, ITestOutputHelper testOutputHelper)
6+
public class StreamableHttpServerIntegrationTests(SseServerIntegrationTestFixture fixture, ITestOutputHelper testOutputHelper)
77
: HttpServerIntegrationTests(fixture, testOutputHelper)
88

99
{

0 commit comments

Comments
 (0)