Beispiel #1
0
 public RefreshTokenCommandHandlerTests()
 {
     _refreshTokenRepositoryMock = new Mock <IRefreshTokenRepository>();
     _userRepositoryMock         = new Mock <IUserRepository>();
     _tokenServiceMock           = new Mock <ITokenService>();
     _handler = new RefreshTokenCommandHandler(_userRepositoryMock.Object, _refreshTokenRepositoryMock.Object, _tokenServiceMock.Object);
 }
Beispiel #2
0
        public async Task Should_RefreshToken()
        {
            var request      = FakeRequest();
            var refreshToken = new RefreshTokenFake().Builder.Generate();

            var uowGeneralMock = new Mock <IUowGeneral>();

            uowGeneralMock.Setup(x => x.RefreshTokenRepository.FindByToken(request.Token))
            .ReturnsAsync(refreshToken);
            var accessTokenService  = new Mock <IAccessTokenService>();
            var refreshTokenService = new RefreshTokenService(uowGeneralMock.Object);

            var handler = new RefreshTokenCommandHandler(
                uowGeneralMock.Object, accessTokenService.Object, refreshTokenService);

            var response = await handler.Handle(request, default);

            Assert.NotNull(response);
            accessTokenService.Verify(x => x.GetAccessToken(refreshToken.User), Times.Once);
            uowGeneralMock.Verify(x =>
                                  x.RefreshTokenRepository.Create(It.IsNotIn(refreshToken)), Times.Once);
            uowGeneralMock.Verify(x =>
                                  x.RefreshTokenRepository.Delete(refreshToken), Times.Once);
            uowGeneralMock.Verify(x => x.SaveChanges(), Times.Once);
        }
 public TokenController(IConfiguration config, LoginRequestCommandHandler loginRequestCommandHandler, RefreshTokenCommandHandler refreshTokenCommandHandler, ForgotPasswordCommandHandler forgotPasswordCommandHandler, ResetPasswordCommandHandler resetPasswordCommandHandler)
 {
     this._loginRequestCommandHandler = loginRequestCommandHandler;
     this._config = config;
     this._refreshTokenCommandHandler   = refreshTokenCommandHandler;
     this._forgotPasswordCommandHandler = forgotPasswordCommandHandler;
     this._resetPasswordCommandHandler  = resetPasswordCommandHandler;
 }
Beispiel #4
0
        public async Task ShouldThrow_InvalidRefreshTokenException_OnNotFoundRefreshToken()
        {
            var request = FakeRequest();

            var uowGeneralMock = new Mock <IUowGeneral>();

            uowGeneralMock.Setup(x => x.RefreshTokenRepository.FindByToken(It.IsAny <string>()))
            .ReturnsAsync(default(RefreshToken));
            var accessTokenService  = new Mock <IAccessTokenService>();
            var refreshTokenService = new RefreshTokenService(uowGeneralMock.Object);

            var handler = new RefreshTokenCommandHandler(
                uowGeneralMock.Object, accessTokenService.Object, refreshTokenService);

            await Assert.ThrowsAsync <InvalidRefreshTokenException>(() =>
                                                                    handler.Handle(request, default));
        }
Beispiel #5
0
        public async Task ShouldThrow_InvalidRefreshTokenException_OnExpiredRefreshToken()
        {
            var request = FakeRequest();
            var refreshTokenFakeBuilder = new RefreshTokenFake().Builder;

            refreshTokenFakeBuilder.RuleFor(x => x.ExpiresAt, f => f.Date.Past());
            var refreshToken = refreshTokenFakeBuilder.Generate();

            var uowGeneralMock = new Mock <IUowGeneral>();

            uowGeneralMock.Setup(x => x.RefreshTokenRepository.FindByToken(request.Token))
            .ReturnsAsync(refreshToken);
            var accessTokenService  = new Mock <IAccessTokenService>();
            var refreshTokenService = new RefreshTokenService(uowGeneralMock.Object);

            var handler = new RefreshTokenCommandHandler(
                uowGeneralMock.Object, accessTokenService.Object, refreshTokenService);

            await Assert.ThrowsAsync <InvalidRefreshTokenException>(() =>
                                                                    handler.Handle(request, default));
        }