示例#1
0
        public void verifyUsernameIsInvalid()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //User is clear
            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));

            //Test User
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");
        }
示例#2
0
        public void verifyThatAfterCorrectingPropertiesAndUserValidNoErrorMessagesExist()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //Test User - Fail
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");

            //Test User - Pass
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsTrue(target.IsAuthenticated, "User should be valid");
            Assert.IsTrue(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should not be an error message");
        }
示例#3
0
        public void addingNewUserUserHashingFunction()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(hasherAlgorithm.VerifyHash("teste", target.Users[0].Password, "mige"));
        }
示例#4
0
        public void verifyThatAfterAddingUserUIisCleared()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));
        }
示例#5
0
        public void verifyThatAddingUserWithErrorsFails()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            string error = (target as IDataErrorInfo)["Username"];

            Assert.IsFalse(String.IsNullOrEmpty(error), "Should have received error message");

            target.AddUser();
            Assert.AreEqual(0, target.Users.Count, "Should have not addded the user");
        }