コード例 #1
0
        public void CreatePassword_ShouldReturnsPasswordForGivenUserId()
        {
            //Arrange
            Mock <IPasswordGenerator> passwordGenerator = new Mock <IPasswordGenerator>(MockBehavior.Strict);

            passwordGenerator.Setup(x => x.Generate()).Returns("password");

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator.Object);
            var password = passwordManager.CreatePassword("id");

            //Assert
            Assert.AreEqual("password", password);
        }
コード例 #2
0
        public void ValidatePassword_GivenCorrectPasswordForUserIdWithinTimeLimitShouldReturnValidatePassword()
        {
            //Arrange
            Mock <IPasswordGenerator> passwordGenerator = new Mock <IPasswordGenerator>(MockBehavior.Strict);

            passwordGenerator.Setup(x => x.Generate()).Returns("password");

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator.Object);
            var password      = passwordManager.CreatePassword("id");
            var passwordValid = passwordManager.IsPasswordCorrectAndValid("id", password);

            //Assert
            Assert.IsTrue(passwordValid);
        }
コード例 #3
0
        public void ValidatePassword_ShouldAllowOneTimeAccessWithPassword()
        {
            //Arrange
            IPasswordGenerator passwordGenerator = new Implementation.PasswordGenerator();

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator);
            var password      = passwordManager.CreatePassword("id");
            var passwordValid = passwordManager.IsPasswordCorrectAndValid("id", password);

            //Assert
            Assert.IsTrue(passwordValid);
            passwordValid = passwordManager.IsPasswordCorrectAndValid("id", password);
            Assert.IsFalse(passwordValid);
        }
コード例 #4
0
        public void ValidatePassword_GivenInvalidUserIdAndPassword()
        {
            //Arrange
            Mock <IPasswordGenerator> passwordGenerator = new Mock <IPasswordGenerator>(MockBehavior.Strict);

            passwordGenerator.Setup(x => x.Generate()).Returns("password");

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator.Object);
            var password      = passwordManager.CreatePassword("id");
            var passwordValid = passwordManager.IsPasswordCorrectAndValid("invalid id", password);

            //Assert
            Assert.IsFalse(passwordValid);
        }
コード例 #5
0
        public async Task ValidatePassword_GivenCorrectPasswordForUserIdOutsideTimeLimitShouldInvalidatePassword()
        {
            //Arrange
            Mock <IPasswordGenerator> passwordGenerator = new Mock <IPasswordGenerator>(MockBehavior.Strict);

            passwordGenerator.Setup(x => x.Generate()).Returns("password");

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator.Object);
            var password = passwordManager.CreatePassword("id", 1);
            await Task.Delay(1);

            var passwordValid = passwordManager.IsPasswordCorrectAndValid("id", password);

            //Assert
            Assert.IsFalse(passwordValid);
        }
コード例 #6
0
        public async Task CreatePassword_GivenUserIdMultipleTimes()
        {
            //Arrange
            IPasswordGenerator passwordGenerator = new Implementation.PasswordGenerator();

            //Act
            IPasswordManager passwordManager = new Implementation.PasswordManager(passwordGenerator);
            var passwordOne = passwordManager.CreatePassword("id");
            await Task.Delay(1);

            var passwordTwo   = passwordManager.CreatePassword("id");
            var passwordValid = passwordManager.IsPasswordCorrectAndValid("id", passwordOne);

            //Assert
            Assert.IsFalse(passwordValid);
            passwordValid = passwordManager.IsPasswordCorrectAndValid("id", passwordTwo);
            Assert.IsTrue(passwordValid);
        }