public void UserCreatedUserNotInDB_Register_NoErrorDetected()
        {
            //Arrange
            var UserUnderCreation = new UserDto()
            {
                FirstName = "Lars",
                LastName  = "MobbeDreng",
                Password  = "******",
                Email     = "*****@*****.**"
            };

            databaseController.FindUserByEmail(UserUnderCreation.Email).ReturnsNull();


            //Act
            var result = ((_uut.Register(UserUnderCreation).Result.Result) as ObjectResult);

            //Assert

            Assert.That(result.StatusCode, Is.EqualTo(201));
        }
예제 #2
0
        public async Task <ActionResult <UserDto> > Register(UserDto regUser)
        {
            regUser.Email = regUser.Email.ToLower();
            var emailExist = _dbController.FindUserByEmail(regUser.Email);

            if (emailExist != null)
            {
                return(BadRequest(new { errorMessage = "Email already in use" }));
            }
            User user = new User()
            {
                Email     = regUser.Email,
                FirstName = regUser.FirstName,
                LastName  = regUser.LastName
            };

            user.PwHash = HashPassword(regUser.Password, BcryptWorkfactor);
            user.Role   = Role.User;
            _dbController.AddAndSaveUser(user);
            return(CreatedAtAction("Get", new { id = user.UserId }, regUser));
        }