Answer the question
In order to leave comments, you need to log in
How to mock UserManager?
Hello, tell me how to properly mock UserManager from the Microsoft.AspNet.Identity library
Answer the question
In order to leave comments, you need to log in
//Arrange
var _userRepository = new Mock<IUserRepository>();
var _userStore = new Mock<IUserStore<ApplicationUser>>();
var userManager = new UserManager<ApplicationUser>(_userStore.Object);
var applicationUserManager = new ApplicationUserManager(_userStore.Object);
var _countersIdRepository = new Mock<ICountersIdRepository>();
var _userService = new Mock<IUserService>();
RegisterBindingModel registerModel = new RegisterBindingModel() { Email = "[email protected]", Password = "qweasd" };
ApplicationUser appUser = new ApplicationUser() { FirstName = "TestName", LastName = "TestLastName" };
UserService userService = new UserService(_userRepository.Object, _countersIdRepository.Object);
_userStore.Setup(x => x.CreateAsync(appUser)).Returns(Task.FromResult(IdentityResult.Success));
_countersIdRepository.Setup(x => x.GetUserLastId()).Returns(10);
_userService.Setup(x => x.Register(registerModel)).Returns(Task.FromResult(IdentityResult.Success));
userService.UserManager = applicationUserManager;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question