コード例 #1
0
        public async void UpdateRefreshTokenThrowsExceptionWhenClaimsPrincipalIsInvalidAsync()
        {
            JwtTokenBl jwtService = new JwtTokenBl(_mockRefreshRepository.Object, _mockUserBl.Object, _mockAccountBl.Object, _mockConfigurations.Object);

            await Assert.ThrowsAsync <SecurityTokenException>(() => jwtService.UpdateRefreshTokenAsync("token", _mockClaimsPrincipal.Object));

            _mockRefreshRepository.Verify(refreshRepository => refreshRepository.UpdateAsync(It.IsAny <UserRefreshToken>()), Times.Never);
        }
コード例 #2
0
        public async void UpdateRefreshTokenThrowsExceptionWhenRefreshTokensIsNotEqualAsync()
        {
            var mockClaim = new Mock <Claim>("uid", "id");

            _mockClaimsPrincipal.Setup(claimsPrincipal => claimsPrincipal.HasClaim(It.IsAny <Predicate <Claim> >())).Returns(true);
            _mockClaimsPrincipal.Setup(claimsPrincipal => claimsPrincipal.FindFirst(It.IsAny <Predicate <Claim> >())).Returns(mockClaim.Object);
            _mockRefreshRepository.Setup(refreshRepository => refreshRepository.GetByUserIdAsync(It.IsAny <string>())).ReturnsAsync(_mockUserRefreshToken.Object);

            JwtTokenBl jwtService = new JwtTokenBl(_mockRefreshRepository.Object, _mockUserBl.Object, _mockAccountBl.Object, _mockConfigurations.Object);

            await Assert.ThrowsAsync <SecurityTokenException>(() => jwtService.UpdateRefreshTokenAsync("token", _mockClaimsPrincipal.Object));

            _mockRefreshRepository.Verify(refreshRepository => refreshRepository.UpdateAsync(It.IsAny <UserRefreshToken>()), Times.Never);
        }
コード例 #3
0
        public async void UpdateRefreshTokenMustUpdateRefreshTokenAndReturnNewRefreshTokenAsync()
        {
            var userRefreshToken = new UserRefreshToken {
                RefreshToken = "token"
            };
            var mockClaim = new Mock <Claim>("uid", "id");

            _mockClaimsPrincipal.Setup(claimsPrincipal => claimsPrincipal.HasClaim(It.IsAny <Predicate <Claim> >())).Returns(true);
            _mockClaimsPrincipal.Setup(claimsPrincipal => claimsPrincipal.FindFirst(It.IsAny <Predicate <Claim> >())).Returns(mockClaim.Object);
            _mockRefreshRepository.Setup(refreshRepository => refreshRepository.GetByUserIdAsync(It.IsAny <string>())).ReturnsAsync(userRefreshToken);

            JwtTokenBl jwtService         = new JwtTokenBl(_mockRefreshRepository.Object, _mockUserBl.Object, _mockAccountBl.Object, _mockConfigurations.Object);
            var        actualRefreshToken = await jwtService.UpdateRefreshTokenAsync("token", _mockClaimsPrincipal.Object);

            _mockRefreshRepository.Verify(refreshRepository => refreshRepository.UpdateAsync(userRefreshToken), Times.Once);
        }