Mock UserManager in unit tests (Student)
How should I mock the UserManager class when I want to make tests for a service which has the UserManager as a dependancy?
In my test i need to create an instance of TripsService:
Now I need to an instance of TripsService but I can't because I need to somehow mock the UserManager. I can't seem to find a way to.
Thank You!
3 Replies
I don't think you can mock it. I had this problem in the past, and I remember there was a solution for it on stackoverflow. The best I can do is link that answer: https://stackoverflow.com/a/52562694/14338059
Stack Overflow
How to mock UserManager in .Net Core testing?
I have following code. Im trying to running a test case for create user.Following is what i have tried so far.
public class CreateUserCommandHandlerTest
{
private Mock<UserManager<
If your class depends on something that is not easy to run in a unit test, and not easy to mock, you should consider introducing a wrapper interface + class which your SUT uses instead
Thanks to both of you! I've now added a wrapper and everything seems to work fine now.