public async Task GivenRefreshTokenQueryHandler_WhenUserIsNotFound_ThenShouldThrowRestException()
        {
            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsNullForAnyArgs();

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await Assert.ThrowsAsync <RestException>(() =>
                                                     refreshTokenQueryHandler.Handle(_query, CancellationToken.None));
        }
        public async Task GivenRefreshTokenQueryHandler_WhenCorrectQueryReceived_ThenShouldCallUserManagerToUpdateUser()
        {
            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await refreshTokenQueryHandler.Handle(_query, CancellationToken.None);

            await _mockUserManager.Received().UpdateAsync(Arg.Any <AppUser>());
        }
Esempio n. 3
0
        public void SetUp()
        {
            _service       = new Mock <IRefreshTokenService>();
            _commonService = new Mock <ICommonService>();
            _unitOfWork    = new Mock <IUnitOfWork>();
            _sut           = new RefreshTokenQueryHandler(_service.Object, _commonService.Object, _unitOfWork.Object);

            _query = new RefreshTokenQuery("currentRefreshToken");

            SetUpFields();
        }
        GivenRefreshTokenQueryHandler_WhenRefreshTokenHasExpired_ThenShouldThrowRestException()
        {
            _user.RefreshTokenExpiry = DateTime.Now.AddHours(-1);

            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await Assert.ThrowsAsync <RestException>(() =>
                                                     refreshTokenQueryHandler.Handle(_query, CancellationToken.None));
        }
        GivenRefreshTokenQueryHandler_WhenRefreshTokenDoesNotMatchStoredRefreshToken_ThenShouldThrowRestException()
        {
            _query.RefreshToken = "10101010";

            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await Assert.ThrowsAsync <RestException>(() =>
                                                     refreshTokenQueryHandler.Handle(_query, CancellationToken.None));
        }
        public async Task GivenRefreshTokenQueryHandler_WhenCorrectQueryReceived_ThenShouldReturnUser()
        {
            _user.RefreshToken = _fixture.UserRefreshToken;
            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            var updatedUser = await refreshTokenQueryHandler.Handle(_query, CancellationToken.None);

            Assert.NotNull(updatedUser);
        }
        public async Task GivenRefreshTokenQueryHandler_WhenCorrectQueryReceived_ThenShouldCallEventBus()
        {
            _user.RefreshToken = _fixture.UserRefreshToken;
            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await refreshTokenQueryHandler.Handle(_query, CancellationToken.None);

            _mockEventBus.Received().Publish(Arg.Any <UpdatedRefreshTokenEvent>());
        }
        GivenRefreshTokenQueryHandler_WhenCorrectQueryReceived_ThenShouldCallJwtGeneratorToCreateRefreshToken()
        {
            _user.RefreshToken = _fixture.UserRefreshToken;
            _mockUserManager.FindByEmailAsync(_query.Email).ReturnsForAnyArgs(_user);

            var refreshTokenQueryHandler =
                new RefreshTokenQueryHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus);

            await refreshTokenQueryHandler.Handle(_query, CancellationToken.None);

            _mockJwtGenerator.Received().GenerateRefreshToken();
        }