Closed gopala000 closed 5 years ago
I'm afraid that is not possible. However, you probably shouldn't use those tables directly as the preferred way is to use the UserManager<T>
and SignInManager<T>
, in which case you can mock those instead. See https://samueleresca.net/2017/03/unit-testing-asp-net-core-identity/
Thanks for your response. That will work. I ended up using https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory. Need to do some refactoring to do like you suggested.
My db context is derived from EF Core's IdentityDbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid>
When I tried to mock like in your sample:
I get the exception, System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: x => x.Users
Is there a workaround? (I understand that it is coming from Moq. IdentityDbContext is part of EF Core that I can't make Users as virtual)