Exemplo n.º 1
0
        public void UnlockAccount()
        {
            var userReadRepository            = new Mock <IUserReadRepository>();
            var sendAccountUnlockCodeStrategy = new Mock <ISendAccountUnlockCodeStrategy>();
            var userWriteRepository           = new Mock <IUserWriteRepository>();

            userReadRepository.Setup(urr => urr.Get(It.IsAny <string>(), true)).Returns(new User
            {
                AccountUnlockCodeExpiry = DateTime.Now.AddDays(1),
                Status            = UserStatuses.Locked,
                AccountUnlockCode = UnlockAccountCode
            });

            var unlockAccountStrategy = new UnlockAccountStrategy(userReadRepository.Object, userWriteRepository.Object,
                                                                  sendAccountUnlockCodeStrategy.Object);

            unlockAccountStrategy.UnlockAccount(Username, UnlockAccountCode);

            userWriteRepository.Verify(uwr => uwr.Save(It.Is <User>(u =>
                                                                    u.AccountUnlockCode == null &&
                                                                    u.AccountUnlockCodeExpiry == null &&
                                                                    u.LoginIncorrectAttempts == 0 &&
                                                                    u.Status == UserStatuses.Active
                                                                    )));
        }
Exemplo n.º 2
0
        public void RenewUnlockAccount()
        {
            var userReadRepository            = new Mock <IUserReadRepository>();
            var sendAccountUnlockCodeStrategy = new Mock <ISendAccountUnlockCodeStrategy>();

            userReadRepository.Setup(urr => urr.Get(It.IsAny <string>(), true)).Returns(new User
            {
                AccountUnlockCodeExpiry = DateTime.Now.AddDays(-1),
                Status = UserStatuses.Locked
            });

            var unlockAccountStrategy = new UnlockAccountStrategy(userReadRepository.Object, null,
                                                                  sendAccountUnlockCodeStrategy.Object);

            Action a = () => unlockAccountStrategy.UnlockAccount(Username, UnlockAccountCode);

            a.ShouldThrow <CustomException>()
            .WithMessage("Account unlock code has expired, new account unlock code has been sent.");
        }
Exemplo n.º 3
0
        public void InvalidUnlockAccountCode()
        {
            var userReadRepository            = new Mock <IUserReadRepository>();
            var sendAccountUnlockCodeStrategy = new Mock <ISendAccountUnlockCodeStrategy>();

            userReadRepository.Setup(urr => urr.Get(It.IsAny <string>(), true)).Returns(new User
            {
                AccountUnlockCodeExpiry = DateTime.Now.AddDays(1),
                Status            = UserStatuses.Locked,
                AccountUnlockCode = AnotherAccountUnlockCode
            });

            var unlockAccountStrategy = new UnlockAccountStrategy(userReadRepository.Object, null,
                                                                  sendAccountUnlockCodeStrategy.Object);

            Action a = () => unlockAccountStrategy.UnlockAccount(Username, UnlockAccountCode);

            a.ShouldThrow <CustomException>()
            .WithMessage(string.Format("Account unlock code \"{0}\" is invalid for user \"{1}\"", UnlockAccountCode, Username));
        }