Beispiel #1
0
 public void should_not_equal_different_string()
 {
     var stringUsename = "SomeUser2";
     var objectUsername = new Username("someuser");
     (stringUsename != objectUsername).ShouldBeTrue();
     (objectUsername != stringUsename).ShouldBeTrue();
 }
Beispiel #2
0
 public void should_equal_equivalent_mixed_case_string()
 {
     var stringUsename = "SomeUser";
     var objectUsername = new Username("someuser");
     (stringUsename == objectUsername).ShouldBeTrue();
     (objectUsername == stringUsename).ShouldBeTrue();
 }
Beispiel #3
0
        public User Create(Username username, string password, string email, bool administrator, string createdBy)
        {
            if (_userRepository.Any(x => x.Username == (string)username))
                throw new DuplicateUsernameException();
            if (username.IsEmpty) throw new EmptyUsernameException();
            if (string.IsNullOrEmpty(password)) throw new EmptyPasswordException();

            var user = new User
                {
                    Username = username,
                    PasswordHash = HashedPassword.Create(password).ToString(),
                    Email = email,
                    Administrator = administrator,
                    Created = DateTime.Now,
                    CreatedBy = createdBy
                };

            _userRepository.Add(user);
            return user;
        }
Beispiel #4
0
        public User Modify(Guid id, Username username, string email, bool administrator, string password = null)
        {
            if (string.IsNullOrEmpty(username))
                throw new EmptyUsernameException();

            var user = _userRepository.Get(id);

            if (user == null) throw new NotFoundException("User");

            if (user.Username != username && _userRepository.Any(x => x.Username == (string)username))
                throw new DuplicateUsernameException();

            user.Username = username;
            user.Email = email;
            if (!string.IsNullOrEmpty(password)) user.SetPassword(password);
            user.Administrator = administrator;
            _userRepository.Replace(user);

            if (_secureSession.IsLoggedIn() && _secureSession.GetCurrentToken().UserId == user.Id)
                _secureSession.Login(new Token(user.Id, user.Username, user.Administrator));

            return user;
        }
Beispiel #5
0
 public Token(Guid userId, Username username, bool administrator)
 {
     UserId = userId;
     Username = username;
     IsAdministrator = administrator;
 }
Beispiel #6
0
 public void should_implicitely_cast_username_to_string()
 {
     string stringUsename = new Username("someuser");
     stringUsename.ShouldEqual("someuser");
 }