public void CanChangePasswordWhenMaxAttemptsIsExceeded()
        {
            const int maxLoginAttempts = 3;

            var testApplicationSettings = new TestApplicationSettings
            {
                MaxLoginAttempts = maxLoginAttempts,
                CoolOffPeriod = 1000
            };

            var userRepository = GetUserRepository(testApplicationSettings);

            var user = CreateUser(testApplicationSettings);

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));

            for (var ctr = 0; ctr < maxLoginAttempts; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsFalse(userRepository.Authenticate("*****@*****.**", "secret"));

            userRepository.ChangePassword(user, "newPassword");

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "newPassword"));
        }
        public void CanAuthenticateUser()
        {
            var testApplicationSettings = new TestApplicationSettings
            {
                MaxLoginAttempts = 3
            };

            var userRepository = GetUserRepository(testApplicationSettings);

            CreateUser(testApplicationSettings);

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));
            Assert.IsFalse(userRepository.Authenticate("[email protected]", "secret"));
            Assert.IsFalse(userRepository.Authenticate("*****@*****.**", "secre"));
        }
        public void UserLoginAttemptsAreResetAfterSuccessfullLogin()
        {
            const int maxLoginAttempts = 5;

            var testApplicationSettings = new TestApplicationSettings
            {
                MaxLoginAttempts = maxLoginAttempts
            };

            var userRepository = GetUserRepository(testApplicationSettings);

            CreateUser(testApplicationSettings);

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));

            for (var ctr = 0; ctr < maxLoginAttempts -1; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));

            for (var ctr = 0; ctr < maxLoginAttempts - 1; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));
        }
        public void UserLoginAttemptsAreResetAfterCoolOffPeriodExpires()
        {
            const int maxLoginAttempts = 5;
            const int coolOffPeriod = 2; // seconds

            var testApplicationSettings = new TestApplicationSettings
            {
                MaxLoginAttempts = maxLoginAttempts,
                CoolOffPeriod = coolOffPeriod
            };

            var userRepository = GetUserRepository(testApplicationSettings);

            CreateUser(testApplicationSettings);

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));

            for (var ctr = 0; ctr < maxLoginAttempts; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsFalse(userRepository.Authenticate("*****@*****.**", "secret"));

            // Cool off
            Thread.Sleep(coolOffPeriod * 1000);

            for (var ctr = 0; ctr < maxLoginAttempts - 1; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));
        }
        public void UserCannotLoginAfterExceedingMaxLoginAttempts()
        {
            const int maxLoginAttempts = 3;

            var testApplicationSettings = new TestApplicationSettings
            {
                MaxLoginAttempts = maxLoginAttempts
            };

            var userRepository = GetUserRepository(testApplicationSettings);

            CreateUser(testApplicationSettings);

            Assert.IsTrue(userRepository.Authenticate("*****@*****.**", "secret"));

            for (var ctr = 0; ctr < maxLoginAttempts; ctr++)
            {
                userRepository.Authenticate("*****@*****.**", "wrongPassword");
            }

            Assert.IsFalse(userRepository.Authenticate("*****@*****.**", "secret"));
        }
 protected BaseTestFixture()
 {
     DefaultTestApplicationSettings = new TestApplicationSettings();
 }