Beispiel #1
0
        public async Task Should_Remove_Expired_TokenValidityKeys()
        {
            //Arrange
            using (_unitOfWorkManager.Begin())
            {
                var user = await _abpUserManager.GetUserByIdAsync(AbpSession.GetUserId());

                await _abpUserManager.AddTokenValidityKeyAsync(user, Guid.NewGuid().ToString(), DateTime.UtcNow);

                await _abpUserManager.AddTokenValidityKeyAsync(user, Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1));

                await _abpUserManager.AddTokenValidityKeyAsync(user, Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1));

                _unitOfWorkManager.Current.SaveChanges();

                var allTokens = _userTokenRepository.GetAllList(t => t.UserId == user.Id);
                allTokens.Count.ShouldBe(3);
            }

            //Act
            _userTokenExpirationWorker.Start();

            //Assert
            using (_unitOfWorkManager.Begin())
            {
                var user = await _abpUserManager.GetUserByIdAsync(AbpSession.GetUserId());

                var allTokens = _userTokenRepository.GetAllList(t => t.UserId == user.Id);
                allTokens.Count.ShouldBe(2);
            }
        }
        public async Task Should_Valid_Non_Expired_TokenValidityKey()
        {
            using (var uow = Resolve <IUnitOfWorkManager>().Begin())
            {
                var user = await _abpUserManager.GetUserByIdAsync(AbpSession.GetUserId());

                var tokenValidityKey = Guid.NewGuid().ToString();
                await _abpUserManager.AddTokenValidityKeyAsync(user, tokenValidityKey, DateTime.UtcNow.AddDays(1));

                var isTokenValidityKeyValid = await _abpUserManager.IsTokenValidityKeyValidAsync(user, tokenValidityKey);

                isTokenValidityKeyValid.ShouldBeTrue();
            }
        }