Closed hkashif closed 1 year ago
Is this because you're actually creating a new test factory in
factory
.WithWebHostBuilder(builder =>
{
builder.ConfigureTestServices(services =>
{
services.AddMvc().AddApplicationPart(typeof(Startup).Assembly);
});
})
.CreateClient();
So the controller endpoint is a different server instance than the signalr endpoing?
Yes. I just realized that. Thanks!
Is there an existing issue for this?
Describe the bug
Normal Operation: When running the project, and connecting an external SignalR client, the client receives messages as expected.
Tests - API Call: When running an integration test, and connecting a client for testing, it doesn't work. I can see during debugging that
_proxy._lifetimeManager._connections
is empty in the controller (what sends the signalHub message to clients).Tests - Direct Service Call: Interestingly, I created another test where I get an instance of the HubContext directly from the Test Web Application Factory. Sending a message through this HubContext instance works, and the message is received by the test client.
Expected Behavior
Tests - API Call: When running an integration test, and connecting a client for testing, after I trigger the API that sends a signalR message to connected clients, I expect the clients to receive the message. And I, accordingly, expect to see the right number of connections in
_proxy._lifetimeManager._connections
when debugging.Steps To Reproduce
Here is a minimal project that reproduces the issue: https://github.com/hkashif/signalr-integration-tests
There are two tests as described earlier:
Exceptions (if any)
No response
.NET Version
6.0.400
Anything else?
Target Framework: net6.0 IDE: VS Code
dotnet --info
: