public void should_create_user_and_return_his_id(RegistrationInfo registrationInfo, Guid passwordSalt, string passwordHash, Guid userId) { identityGenerator.GetIdentity().Returns(passwordSalt, userId); cryptographyService.GetPasswordHash(registrationInfo.Password, passwordSalt).Returns(passwordHash); var result = userService.CreateUser(registrationInfo); result.Should().Be(userId); }
public void should_return_conflict_message_when_user_exists_on_signup(RegistrationInfo registrationInfo, User user) { userService.GetUserByLogin(registrationInfo.Login).Returns(user); var result = controller.Post(registrationInfo); var message = result as HttpResponseMessage; message.ReasonPhrase.Should().Be(AuthorizationController.UserAlreadyExistsMessage); }
public void should_create_user_and_insert_it_to_storage(RegistrationInfo registrationInfo, Guid passwordSalt, string passwordHash, Guid userId) { identityGenerator.GetIdentity().Returns(passwordSalt, userId); cryptographyService.GetPasswordHash(registrationInfo.Password, passwordSalt).Returns(passwordHash); userService.CreateUser(registrationInfo); storage.Received().Insert(Arg.Is<User>(user => user.Id == userId && user.Name == registrationInfo.Name && user.Login == registrationInfo.Login && user.PasswordHash == passwordHash && user.PasswordSalt == passwordSalt)); }
public void should_return_response_with_new_token_on_signup(RegistrationInfo registrationInfo, Guid userId, string token) { User user = null; userService.GetUserByLogin(registrationInfo.Login).Returns(user); userService.CreateUser(registrationInfo).Returns(userId); tokenService.CreateToken(userId, registrationInfo.Login).Returns(token); var result = controller.Post(registrationInfo); var response = result as TokenResponse; response.Id.Should().Be(userId); response.Token.Should().Be(token); response.Login.Should().Be(registrationInfo.Login); }
public Guid CreateUser(RegistrationInfo registrationInfo) { var passwordSalt = identityGenerator.GetIdentity(); var passwordHash = cryptographyService.GetPasswordHash(registrationInfo.Password, passwordSalt); var user = new User { Id = identityGenerator.GetIdentity(), Login = registrationInfo.Login, Name = registrationInfo.Name, PasswordSalt = passwordSalt, PasswordHash = passwordHash }; storage.Insert(user); return user.Id; }
public object Post(RegistrationInfo registrationInfo) { var user = userService.GetUserByLogin(registrationInfo.Login); if (user != null) return new HttpResponseMessage(HttpStatusCode.Conflict) { ReasonPhrase = UserAlreadyExistsMessage }; ; var userId = userService.CreateUser(registrationInfo); var token = tokenService.CreateToken(userId, registrationInfo.Login); var response = new TokenResponse { Id = userId, Login = registrationInfo.Login, Token = token, }; return response; }