Aspnetcore: [SignalR] Better integration with TestServer

Created on 4 Jul 2019  路  3Comments  路  Source: dotnet/aspnetcore

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.

5.0-candidate affected-few area-signalr enhancement severity-minor

Most helpful comment

Please, these characteristics are very important to be able to test SignalR with TestServer in integration or unit tests.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snebjorn picture snebjorn  路  3Comments

aurokk picture aurokk  路  3Comments

UweKeim picture UweKeim  路  3Comments

farhadibehnam picture farhadibehnam  路  3Comments

markrendle picture markrendle  路  3Comments