-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Comments
It's not a mockable type. I'd suggest wrapping it in your own interface and mocking that. |
Thansk for reply @davidfowl Yeah thats whats im doing for now, https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/blob/b2c194df616d8bb319256ccdf551a92ab2655027/SignalR.EventAggregatorProxy.Client.DotNetCore/Bootstrap/Factories/HubProxyFactory.cs#L55 But it feels like a step back from the old aspnet version. |
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. |
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. |
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! |
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
The text was updated successfully, but these errors were encountered: