public void ControllerSpecSetUp() { BranchRepositoryMock = new Mock<IBranchRepository>(); GamingConsoleRepositoryMock = new Mock<IGamingConsoleRepository>(); User = new User { BranchName = "branch1" }; CustomUserIdentity = new CustomUserIdentity(User); }
public void Throws_Exception_if_password_mismatch(string samplePassword) { var expectedUser = new User { BranchName = branchName, Name = userName, Password = password }; userRepositoryMock.Setup(repo => repo.GetByUserName(userName)).Returns(expectedUser); var argumentException = Assert.Throws<ArgumentException>(() => authenticationService.Authenticate(userName, samplePassword, branchName)); argumentException.Message.ShouldEqual("Invalid User Credentials"); }
public void Returns_user_instance_upon_successful_authentication() { var expectedUser = new User {BranchName = branchName, Name = userName, Password = password}; userRepositoryMock.Setup(repo => repo.GetByUserName(userName)).Returns(expectedUser); var actualUser = authenticationService.Authenticate(userName, password, branchName); actualUser.ShouldEqual(expectedUser); }
public void Adds_new_User_to_the_User_repository() { var user = new User(); UserRepositoryMock.Setup(repo => repo.Add(user)).Verifiable(); UserController.Create(user); UserRepositoryMock.Verify(repo => repo.Add(user)); }
public void Dont_verify_branchName_if_the_authenticated_user_is_a_admin() { var expectedUser = new User { BranchName = branchName, Name = userName, Password = password , IsAdmin = true}; userRepositoryMock.Setup(repo => repo.GetByUserName(userName)).Returns(expectedUser); var actualUser = authenticationService.Authenticate(userName, password, "foo"); actualUser.ShouldEqual(expectedUser); }
public void Returns_create_view_if_new_user_name_already_exists() { SetupBranchRepositoryToReturnSomeRandomBranches(); var user = new User { Name = "foo", Password = "******", BranchName = "bar" }; UserRepositoryMock.Setup(repo => repo.IsUserNameExists("foo", "bar")).Returns(true); var viewResult = UserController.Create(user) as ViewResult; viewResult.Model.ShouldEqual(user); viewResult.ViewName.ShouldEqual(string.Empty); AssertModelError(UserController, "Name", "User name already exists in the selected branch"); AssertRandomBranchesPresentInViewBag(viewResult); }
public void Returns_create_view_if_new_User_is_invalid() { SetupBranchRepositoryToReturnSomeRandomBranches(); UserController.ModelState.AddModelError("Name", "The Name field is required"); var user = new User(); var viewResult = UserController.Create(user) as ViewResult; viewResult.Model.ShouldEqual(user); viewResult.ViewName.ShouldEqual(string.Empty); AssertRandomBranchesPresentInViewBag(viewResult); }
public ActionResult Create(User user) { if (ModelState.IsValid) { if (!userRepository.IsUserNameExists(user.Name, user.BranchName)) { userRepository.Add(user); return RedirectToAction("Index"); } ModelState.AddModelError("name", "User name already exists in the selected branch"); } ViewBag.Branches = MapBranchesToSelectListItems(branchRepository); return View(user); }
public void SetUp() { user = new User(); customUserIdentity = new CustomUserIdentity(user); customUserPrinciple = new CustomUserPrinciple(customUserIdentity); }
public CustomUserIdentity(User user) { this.user = user; }
public void SetUp() { user = new User(); customUserIdentity = new CustomUserIdentity(user); }
private ActionResult HandleRedirectionBasedOnUserRole(User user) { return user.IsAdmin ? RedirectToAction("Index", "Home", new { area = "Admin" }) : RedirectToAction("Index", "Game"); }