public void CreateUser_should_call_repository_add_func_when_check_passed()
        {
            // setup
            SetUpEmptyUserExpectationForCreateNewAccountWithValidConditions();

            var modelError = new ModelStateDictionary();
            var user = new User { UserName = _nonExistignUserName, Password = Guid.NewGuid().ToString() };
            _userAuthenticationServiceSUT.Create(user, _userName, modelError);

            // Assert
            Assert.True(modelError.Count == 0);
            _userRepositoryMock.Verify(a => a.Add(user));
            _userRepositoryMock.Verify(a => a.Save());
        }
        public User Create(User user, string creator, ModelStateDictionary stateDictionary)
        {
            if (user == null) user = new User();

            var createdUser = default(User);

            CheckCreatorHasRights(creator, stateDictionary);
            CheckUserNameCanNotBeNull(user, stateDictionary);
            CheckUserExist(user, stateDictionary);
            CheckPasswordRuleMatched(user, stateDictionary);

            if (stateDictionary.IsValid)
            {
                user.AvatarUrl = Avatar.GetAvatarUrl(user.UserName);
                createdUser = UserRepository.Add(user);

                UserRepository.Save();
            }

            return createdUser;
        }
示例#3
0
 public User Add(User user)
 {
     _documentSession.Store(user);
     return user;
 }
        private bool IsMatch(string userName, string password)
        {
            _user = UserRepository.GetUserByName(userName);

            return _user.Password == password;
        }
        private void CheckUserExist(User user, ModelStateDictionary modelErrors)
        {
            var existedUser = UserRepository.GetUserByName(user.UserName);

            if (existedUser != null && string.Compare(existedUser.UserName, user.UserName, System.StringComparison.OrdinalIgnoreCase) == 0)
            {
                modelErrors.AddModelError(PROP_USERNAME, AccountString.UserAlreadyExist);
            }
        }
 private static void CheckUserNameCanNotBeNull(User user, ModelStateDictionary modelErrors)
 {
     if (string.IsNullOrEmpty(user.UserName))
     {
         modelErrors.AddModelError(PROP_USERNAME, AccountString.UserNameCanNotBeNull);
     }
 }
        private static void CheckPasswordRuleMatched(User user, ModelStateDictionary modelErrors)
        {
            var valid = true;
            var password = user.Password;
            if (string.IsNullOrEmpty(password)) valid = false;

            if (string.IsNullOrEmpty(password) || password.Length < 6) valid = false;

            if (valid == false)
            {
                modelErrors.AddModelError(PROP_PASSWORD, AccountString.NotMatchPasswordRule);
            }
        }
示例#8
0
 public AccountCreateModel MapFromDomainToViewModel(User user)
 {
     return AutoMapper.Mapper.Map<User, AccountCreateModel>(user);
 }
        public void CreateUser_should_set_avatar_url()
        {
            //Arrange
            const string AVATAR_URL = "Avatar Url";
            SetUpEmptyUserExpectationForCreateNewAccountWithValidConditions();
            var modelError = new ModelStateDictionary();
            var user = new User { UserName = _nonExistignUserName, Password = Guid.NewGuid().ToString() };
            _avatar.Setup(a => a.GetAvatarUrl(user.UserName)).Returns(AVATAR_URL);

            _userAuthenticationServiceSUT.Create(user, _userName, modelError);

            _userRepositoryMock.Verify(r => r.Add(It.Is<User>(u => u.AvatarUrl == AVATAR_URL)));
        }