-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HubConnection interface #14924
Comments
Having similar problems with mocking It's as if nobody considered unit testing when designing contracts for Signalr. |
We should definitely consider making more HubConnection methods virtual. As for WithUrl, that is already mockable. It's true you cannot override the static extension method yourself, but you can the configured URL as follows after calling WithUrl: HubConnectionBuilder.WithUrl("https://example.com/");
var configuredUri = HubConnectionBuilder.Services.BuildServiceProvider()
.GetService<IOptions<HttpConnectionOptions>>().Value.Url;
Assert.Equal(new Uri("https://example.com/"), configuredUri); This should work either with a real HubConnectionBuilder or any mocked IHubConnectionBuilder with a realistic IServiceCollection implementation. Even if you you wind up providing a custom IHubConnectionBuilder.Build() implementation, I would recommend just using the default IServiceCollection implementation which is really just a thin wrapper around |
@halter73 I think you should put it behind an interface and don't base your code architecture on extension methods as they are pain to work with. We build mission-critical systems that people's lives depend on. We simply cannot work with a technology that is not unit testable. |
@turowicz you can always wrap the hub connection in your own interface. |
Can you provide an example of the test you want to perform? Understanding what kind of mocking you want here would be helpful. Adding interfaces makes the framework code itself much more brittle to breaking changes over time, so we don't just introduce them for testability purposes (when it's always feasible to write a wrapper if you need to do this kind of unit testing). |
Closing this as we haven't heard from you and generally close issues with no response after some time. Please feel free to comment if you're able to get the information we're looking for and we can reopen the issue to investigate further! |
@anurse @davidfowl I will follow your best practice of wrapping everything into interfaces myself. |
In contrast to the "full" SignalR, Core one doesn't have a HubConnection that would be possible to Mock. There is no interface for it.
https://github.com/aspnet/AspNetCore/blob/master/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs#L36
The text was updated successfully, but these errors were encountered: