public void TestLoginWithNormalCorrectLogin()
        {
            // Prepare env.
            var users = this.GetPrepareUsers();
            var stub  = new UserManagerStub(users);

            var bizContext  = GetBizContext();
            var userManager = new UserManager(bizContext, stub);
            var token       = userManager.Login("admin", "123456");

            // Check
            var loginUser = bizContext.TokenHandler.GetAssociateObjectByToken <LoginUser>(token);

            Assert.AreEqual(loginUser.UserId, 1);
            Assert.AreEqual(users[0].FailTimes, 0);
        }
        public void TestLoginWithNormalIncorrectLogin()
        {
            var users      = this.GetPrepareUsers();
            var stub       = new UserManagerStub(users);
            var bizContext = GetBizContext();

            users[0].FailTimes = 0;

            var userManager = new UserManager(bizContext, stub);

            try
            {
                var token = userManager.Login("admin", "1234567");
            }
            catch (SpException ex)
            {
                Assert.AreEqual(ex.Message, "The user name and password incorrect");
                Assert.AreEqual(users[0].FailTimes, 1);
            }
        }
        public void TestLoginWithCorrectUserAndPwdButTrytimesExtend()
        {
            var users      = this.GetPrepareUsers();
            var stub       = new UserManagerStub(users);
            var bizContext = GetBizContext();

            users[0].FailTimes = 10;
            bizContext.Configuration.MaxLoginTryTimes = 10;

            var userManager = new UserManager(bizContext, stub);

            try
            {
                var token = userManager.Login("admin", "123456");
            }
            catch (SpException ex)
            {
                Assert.AreEqual(ex.Message, "The account locked, because login times reach maxinum");
                Assert.AreEqual(users[0].FailTimes, 11);
            }
        }
        public void TestLoginWithNormalIncorrectLoginAndTryMultipleTimes()
        {
            var users      = this.GetPrepareUsers();
            var stub       = new UserManagerStub(users);
            var bizContext = GetBizContext();

            users[0].FailTimes = 8;
            bizContext.Configuration.MaxLoginTryTimes = 10;

            var userManager = new UserManager(bizContext, stub);

            try
            {
                var token = userManager.Login("admin", "1234567");
            }
            catch (SpException ex)
            {
                Assert.AreEqual(ex.Message, "The user name and password incorrect. You have 1 time(s) to try");
                Assert.AreEqual(users[0].FailTimes, 9);
            }
        }