Skip to content
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

Need example on stubbing client HubConnection #8133

Closed
AndersMalmgren opened this issue Mar 3, 2019 · 5 comments
Closed

Need example on stubbing client HubConnection #8133

AndersMalmgren opened this issue Mar 3, 2019 · 5 comments
Labels
area-signalr Includes: SignalR clients and servers
Milestone

Comments

@AndersMalmgren
Copy link

Describe the bug

None core version had a interface IHubProxy which we could Mock easily, the new client has a none abstract concrete typ called HubConnection, I've spent the last two hours trying to mock all its dependecnies so we can Unit test. But without success, can you point me to en example how to mock the HubConnection? Thanks

@davidfowl
Copy link
Member

It's not a mockable type. I'd suggest wrapping it in your own interface and mocking that.

@AndersMalmgren
Copy link
Author

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Mar 3, 2019
@halter73 halter73 added this to the Discussions milestone Mar 4, 2019
@drmathias
Copy link

drmathias commented Sep 5, 2019

Using HubConnection it is really horrible to test. Wrapping it in a class is not ideal as it is preferable to verify actual calls to HubConnection. It would be easier to test if it had an interface, then you could mock the 'Core' methods, but you're mostly using all these static extension methods which could be overloading methods but aren't. I really wonder what the design decisions for this were.

@bradygaster
Copy link
Member

Like @davidfowl articulated above, the HubConnection isn't really mockable, nor did we really intend on it being mockable. My feeling on this is that it's an functional detail, and thought unfortunate it prevents 100% test coverage, I'd argue that when I've wanted to test scenarios using a hub, my interest was in validating that "an event fired" when I'd expect it to fire more often than not. In those cases i'd wrap it in a class, or even abstract it into an interface as @davidfowl proposed, and use eventing tests.

I am interested in other scenarios here and ideas, but I don't foresee us changing this implementation.

@ghost
Copy link

ghost commented Nov 12, 2020

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Nov 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

6 participants