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:
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.
Bear in mind that WebHostBuilder will be deprecated in future releases.
Yes, we're aware :). The focus is on better integration with TestServer, not necessarily using WebHostBuilder.
Please, these characteristics are very important to be able to test SignalR with TestServer in integration or unit tests.
Most helpful comment
Please, these characteristics are very important to be able to test SignalR with TestServer in integration or unit tests.