dotnet / dotnet/aspnetcore

[SignalR] Better integration with TestServer

Open
#11,888 24 comments 33 reactions 0 assignees View on GitHub
affected-few area-signalr enhancement severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Right now, it's only possible to use TestServer with the non-WebSockets transports because we only provide a way to replace the `HttpMessageHandler`. We should consider providing a way to provide a `WebSocket` "factory" so that we can integrate properly with TestServer.

It might be most appropriate here to add an alternative to `WithUrl` on `HubConnectionBuilder`. Consider this possible test code:

```csharp
var server = new TestServer(webHostBuilder);
var connection = new HubConnectionBuilder()
.WithTestServer(server, HttpTransportType.WebSockets, o => {
// Assorted other HttpConnectionOptions
})
.Build();
```

It would be relatively simple to add this API once we have a way to swap out the WebSocket, though we'd probably need to do so in a new assembly to avoid layering issues.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.