public void UnbanTest() { Mock <ControllerContext> controllerContext = new Mock <ControllerContext>(); Mock <IPrincipal> principal = new Mock <IPrincipal>(); principal.SetupGet(x => x.Identity.Name).Returns("user"); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); AppUser user = new AppUser { Email = "*****@*****.**", Id = "user", FirstName = "John", LastName = "Snow", IsBanned = true, UserName = "******" }; Mock <IMainRepository> repository = new Mock <IMainRepository>(); repository.Setup(x => x.GetUserById("user")).Returns( user ); BannedUsersController controller = new BannedUsersController(repository.Object) { ControllerContext = controllerContext.Object }; var result = (RedirectToRouteResult)controller.Unban("user"); repository.Verify(x => x.UpdateUser(user), Times.Once); Assert.AreEqual("ViewBannedUsers", result.RouteValues["action"]); }