Very difficult to unit test with SignInManager
I am really struggling to add unit tests over a service I have developed which has a dependency on the SignInManager
I have similar concerns about the dependencies on classes rather than interfaces. they should get removed. Ie. the constructor of SignInManager has a hard dependency on UserManager<TUser>, rather than on IUserManager<TUser> (which doesn't exist either).
My workaround so far was to subclass everything and put proper interfaces on them.
The main reason was we wanted the ability to add new API to the managers without causing breaking changes. You can still mock the managers, see: https://github.com/aspnet/Identity/blob/dev/test/Microsoft.AspNetCore.Identity.Test/SignInManagerTest.cs#L197
What is it you are trying to do that an interface would let you do that you can't do today in your tests? Effectively the manager types are the interface, you can register your own manager type with DI which will take over the implementation.
If the UserManager and SignInManager had interfaces then it allows you to make fake implementations and therefore is easy to unit test and DI.
I tried to workaround this issue by creating subclasses and applying interfaces to them but I seem to run into issues in the SignInManager, as it must be supplied with a concrete UserManager class.
I am wondering whether or not to create a pull request.. do you think it would be worth it or is it not something that is wanted anyway?
We still unit test them and fake them in the tests whether or not they are interfaces or classes, you can still use something like Moq to fake and inject them, see:
https://github.com/aspnet/Identity/blob/dev/test/Shared/MockHelpers.cs#L19
all of these links are broken ...grrrrr!
For anyone searching, here is the current link: https://github.com/aspnet/Identity/blob/master/test/Shared/MockHelpers.cs