vendredi 20 novembre 2015

How do I mock UserManager.GetRoles()

How do I mock UserManager.GetRoles() in ASP.NET Identity? I know it's an extension method, so I can't mock it directly and I can't find the underlying methods/properties that need to be mocked.

In the past, I was able to mock the extension method UserManager.FindByName() by mocking the UserStore,

var mockUserStore = new Mock<IUserStore<ApplicationUser>>();
mockUserStore.Setup(x => x.FindByNameAsync(username))
                     .ReturnsAsync(new ApplicationUser() { OrganizationId = orgId });
var userManager = new ApplicationUserManager(mockUserStore.Object);

I don't see any way to assign Roles to the Users in the UserStore. Any ideas?

Aucun commentaire:

Enregistrer un commentaire