public void BanTest() { var user = new UserProfile { Id = "1", UserName = "******", LockoutEnabled = false }; // Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "users") .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var context = new ApplicationDbContext(options); var emailSender = new Mock <IEmailSender>(); var taskRep = new Mock <TaskRepository>(context); var userRep = new Mock <UserRepository>(context); var mapper = new Mock <IMapper>(); var userService = new Mock <UserService>(userRep.Object, mapper.Object); userService.Setup(i => i.GetUserProfile("1")).Returns(user); var catRep = new Mock <CategoryRepository>(context); var taskCatRep = new Mock <TaskCategoryRepository>(context); var service = new Mock <TaskService>(taskRep.Object, userRep.Object, catRep.Object, taskCatRep.Object, mapper.Object); var mockUserManager = new Mock <UserManager <UserProfile> >( new Mock <IUserStore <UserProfile> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <UserProfile> >().Object, new IUserValidator <UserProfile> [0], new IPasswordValidator <UserProfile> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <UserProfile> > >().Object); var controller = new UserManagementController(mockUserManager.Object, service.Object, userService.Object, emailSender.Object); var view = controller.Ban("1"); Assert.IsType <JsonResult>(view); }