Guest User

Untitled

a guest
Oct 29th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. [Test]
  2. public void TestCreateWithNewUser()
  3. {
  4.     const string salt = "saltdata";
  5.     const string password = "password";
  6.     const string hash = "hashdata";
  7.  
  8.     var role = new Role { Id = 123 };
  9.     var clientOrganization = new ClientOrganization { Id = 321 };
  10.     var user = new CreateUser {
  11.         Username = "username", FirstName = "First", LastName = "Last",
  12.         Email = "email", LocalService = "local", Password = password,
  13.         ConfirmPassword = password, Role = role, ClientOrganization = clientOrganization
  14.     };
  15.  
  16.     _mockUserService.Setup(x => x.Get(user.Username)).Returns((User)null);
  17.     _mockAuthenticationService.Setup(x => x.GenerateSalt()).Returns(salt);
  18.     _mockAuthenticationService.Setup(x => x.CalculateHash(user.Password, salt)).Returns(hash);
  19.     _mockRoleService.Setup(x => x.Get(role.Id)).Returns(role);
  20.     _mockClientOrganizationService.Setup(x => x.Get(clientOrganization.Id)).Returns(clientOrganization);
  21.  
  22.     _mockUserService.Setup(x => x.Add(It.Is<User>(u =>
  23.         u.Username == user.Username && u.FirstName == user.FirstName && u.LastName == user.LastName &&
  24.         u.Email == user.Email && u.LocalService == user.LocalService && u.Password == hash &&
  25.         u.Role == user.Role && u.ClientOrganization == user.ClientOrganization
  26.     )));
  27.  
  28.     var redirectResult = _userManagementController.Create(user) as RedirectToRouteResult;
  29.     Assert.NotNull(redirectResult);
  30.  
  31.     _mockUserService.VerifyAll();
  32.     _mockAuthenticationService.VerifyAll();
  33.     _mockRoleService.VerifyAll();
  34.     _mockClientOrganizationService.VerifyAll();
  35. }
Add Comment
Please, Sign In to add comment