Пример #1
0
        public void ConfirmUser_InvalidCode_ReturnsFalse()
        {
            byte[] salt = PasswordManagement.GenerateSalt();
            byte[] pass = PasswordManagement.GenerateSaltedPassword(Encoding.UTF8.GetBytes("Password"), salt);

            var mock = new Mock<IUnitOfWork>();
            mock.Setup(u => u.UserRepository.Get(It.IsAny<Expression<Func<User, bool>>>(), null, "")).Returns(
                new List<User>());

            RegisterService registerService = new RegisterService(mock.Object);

            bool result = registerService.ConfirmUser("code");

            Assert.IsFalse(result);
        }
Пример #2
0
        public void ConfirmUser_ValidCode_ReturnsTrue()
        {
            byte[] salt = PasswordManagement.GenerateSalt();
            byte[] pass = PasswordManagement.GenerateSaltedPassword(Encoding.UTF8.GetBytes("Password"), salt);

            var mock = new Mock<IUnitOfWork>();
            mock.Setup(u => u.UserRepository.Get(It.IsAny<Expression<Func<User, bool>>>(), null, "")).Returns(
                new List<User>
            {
                new User { UserId = 4, FirstName = "Test4", LastName = "LastName", Email = "*****@*****.**", Salt = salt, Password = pass, ConfirmCode = "code", AccountConfirmed = false },
            });

            RegisterService registerService = new RegisterService(mock.Object);

            bool result = registerService.ConfirmUser("code");

            Assert.IsTrue(result);
        }
Пример #3
0
        public void CreateUser_UserDoesExist_ReturnsFalse()
        {
            byte[] salt = PasswordManagement.GenerateSalt();
            byte[] pass = PasswordManagement.GenerateSaltedPassword(Encoding.UTF8.GetBytes("Password"), salt);

            var mock = new Mock<IUnitOfWork>();
            mock.Setup(u => u.UserRepository.Get(It.IsAny<Expression<Func<User, bool>>>(), null, "")).Returns(
                new List<User>
            {
                new User { UserId = 4, FirstName = "Test4", LastName = "LastName", Email = "*****@*****.**", Salt = salt, Password = pass },
            });

            RegisterService registerService = new RegisterService(mock.Object);

            UserDTO testUser = new UserDTO();
            testUser.Email = "*****@*****.**";

            bool result = registerService.createNewUser(testUser);

            Assert.IsFalse(result);
        }