Exemplo n.º 1
0
        public void CanSendEmailNotificationTo_UserDisabled_False()
        {
            var user = new User() { Email = "*****@*****.**", Enabled = false, Role = new Role() { EmailNotificationEnabled = true } };
            m_userRepository.Add(user);
            m_unitOfWork.Commit();

            var actual = m_target.CanSendEmailNotificationTo("*****@*****.**");
            Assert.IsFalse(actual);
        }
Exemplo n.º 2
0
        public void KeepImmutableValues_OldUser_KeepUsername()
        {
            var oldUser = new User()
            {
                UserName = "******"
            };

            var target = new User()
            {
                UserName = "******"
            };

            target.KeepImmutableValues(oldUser);
            Assert.AreEqual("New username", target.UserName);

            target.Id = 1;
            target.KeepImmutableValues(oldUser);
            Assert.AreEqual("Old username", target.UserName);
        }
Exemplo n.º 3
0
        public void Clone_Properties_PropertiesCloned()
        {
            var target = new User()
            {
                Email = "*****@*****.**",
                Enabled = true,
                FullName = "test fullname",
                Id = 1,
                Role = new Role() { Id = 2 },
                UserName = "******"
            };

            var cloned = target.Clone() as User;

            Assert.IsFalse(object.ReferenceEquals(target, cloned));
            Assert.AreEqual("*****@*****.**", cloned.Email);
            Assert.IsTrue(cloned.Enabled);
            Assert.AreEqual("test fullname", cloned.FullName);
            Assert.AreEqual(0, cloned.Id);
            Assert.AreEqual(2, cloned.Role.Id);
            Assert.AreEqual("test username", cloned.UserName);
            Assert.AreEqual(cloned.FullName, ((INamedEntity)cloned).Name);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Mantém os valores imutáveis se o usuário já existe.
 /// </summary>
 /// <param name="oldUser">A versão anterior do usuário.</param>
 internal void KeepImmutableValues(User oldUser)
 {
     if (!IsNew)
     {
         UserName = oldUser.UserName;
     }
 }
 public UserPasswordHistory(User user)
 {
     UserId = user.Id;
     Password = user.Password;
 }
        public void GeneratePasswordResetToken_ThereNoOtherTokenForUser_GenerateNewOne()
        {
            var user = new User() { Id = 1, Email = "*****@*****.**" };
            m_tokenRepository.Add(new UserPasswordResetToken() { UserId = 2 });
            m_unitOfWork.Commit();
            var originalTokenCount = m_tokenRepository.CountAll();

            var token = m_target.GeneratePasswordResetToken(user.Email);
            m_unitOfWork.Commit();
            Assert.AreEqual(1, token.UserId);
            Assert.AreEqual(DateTime.UtcNow.Date, token.Created.Date.Date);
            Assert.IsNotNull(token.Code);

            Assert.AreEqual(originalTokenCount + 1, m_tokenRepository.CountAll());
        }
        public void GeneratePasswordResetToken_ThereIsOtherTokenForUser_RemoveTheOldOneAndGenerateNewOne()
        {
            var user = new User() { Id = 1, Email = "*****@*****.**" };
            m_tokenRepository.Add(new UserPasswordResetToken() { UserId = user.Id });
            m_tokenRepository.Add(new UserPasswordResetToken() { UserId = 2 });
            m_unitOfWork.Commit();
            var originalTokenCount = m_tokenRepository.CountAll();
            var originalToken = m_tokenRepository.FindFirst(t => t.UserId.Equals(user.Id));

            var token = m_target.GeneratePasswordResetToken(user.Email);
            m_unitOfWork.Commit();

            Assert.AreEqual(1, token.UserId);
            Assert.AreEqual(DateTime.UtcNow.Date, token.Created.Date.Date);
            Assert.IsNotNull(token.Code);

            Assert.AreEqual(originalTokenCount, m_tokenRepository.CountAll());
            Assert.IsNull(m_tokenRepository.FindBy(originalToken.Id));
        }
        private void ChangePassword(User user, string newPassword)
        {
            if (!user.Enabled)
            {
                throw new InvalidOperationException(Texts.UserDisabledCannotChangePassword);
            }

            var encryptedPassword = Encrypt(newPassword);
            SpecService.Assert(newPassword, new PasswordMustBeStrongSpec(user.Id, this));
            user.Password = encryptedPassword;
            m_userService.Save(user);
            m_historyRepository.Add(new UserPasswordHistory(user));
        }