Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Test]
- public void TestCreateWithNewUser()
- {
- const string salt = "saltdata";
- const string password = "password";
- const string hash = "hashdata";
- var role = new Role { Id = 123 };
- var clientOrganization = new ClientOrganization { Id = 321 };
- var user = new CreateUser {
- Username = "username", FirstName = "First", LastName = "Last",
- Email = "email", LocalService = "local", Password = password,
- ConfirmPassword = password, Role = role, ClientOrganization = clientOrganization
- };
- _mockUserService.Setup(x => x.Get(user.Username)).Returns((User)null);
- _mockAuthenticationService.Setup(x => x.GenerateSalt()).Returns(salt);
- _mockAuthenticationService.Setup(x => x.CalculateHash(user.Password, salt)).Returns(hash);
- _mockRoleService.Setup(x => x.Get(role.Id)).Returns(role);
- _mockClientOrganizationService.Setup(x => x.Get(clientOrganization.Id)).Returns(clientOrganization);
- _mockUserService.Setup(x => x.Add(It.Is<User>(u =>
- u.Username == user.Username && u.FirstName == user.FirstName && u.LastName == user.LastName &&
- u.Email == user.Email && u.LocalService == user.LocalService && u.Password == hash &&
- u.Role == user.Role && u.ClientOrganization == user.ClientOrganization
- )));
- var redirectResult = _userManagementController.Create(user) as RedirectToRouteResult;
- Assert.NotNull(redirectResult);
- _mockUserService.VerifyAll();
- _mockAuthenticationService.VerifyAll();
- _mockRoleService.VerifyAll();
- _mockClientOrganizationService.VerifyAll();
- }
Add Comment
Please, Sign In to add comment