-
Notifications
You must be signed in to change notification settings - Fork 188
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
How to unit test ServerlessHub #2818
Comments
You could have a constructor specially for testing calling the public SignalRMessageProcessor(
ServiceHubContext serviceHubContext,
IAuthenticationManager authenticationManager,
ILogger<SignalRMessageProcessor> logger) : base(serviceHubContext)
{
_authenticationManager = authenticationManager;
_logger = logger;
} You can mock the implementation of |
@Y-Sindo Thanks a lot for the reply. I don't think I follow your suggestion, the code you provided is injecting the Thanks again for the feedback! |
Yes. This is a common practice that we use a different constructor for testing. You may find many examples in other .NET codes. As the main purpose of |
I was able to add coverage by doing this. Thanks for your suggestion! |
What version of .NET does your existing project use?
.NET 6
What version of .NET are you attempting to target?
.NET 8
Description
After the migration to .NET 8, in order to use SignalR with Azure Functions, it's required to inherit from ServerlessHub. This is no longer unit testable or at least I couldn't find a way to do so.
Here's an example code that I want to unit test.
Any guidance on this is appreciated. I tried mocking IServiceProvider with no luck.
Project configuration and dependencies
No response
Link to a repository that reproduces the issue
No response
The text was updated successfully, but these errors were encountered: