public async Task RefreshTokenUserTestSuccess() { #region Mock Success TestRefreshSuccess.prarameter.Token = jwtService.GenerateToken(TestRefreshSuccess.user.Email, TestRefreshSuccess.user.Id.ToString()); TestRefreshSuccess.prarameter.RefreshToken = jwtService.GenerateRefreshToken(); var claimPrincipa = jwtService.GetPrincipalFromExpiredToken(TestRefreshSuccess.prarameter.Token); _jwtServiceMocking.Setup(s => s.GetPrincipalFromExpiredToken(TestRefreshSuccess.prarameter.Token)) .Returns(claimPrincipa); var emailFromClaim = jwtService.GetValueFromClaimType(claimPrincipa, JwtRegisteredClaimNames.Email); _jwtServiceMocking.Setup(s => s.GetValueFromClaimType(claimPrincipa, JwtRegisteredClaimNames.Email)) .Returns(emailFromClaim); var userIdFromClaim = jwtService.GetValueFromClaimType(claimPrincipa, JwtRegisteredClaimNames.NameId); _jwtServiceMocking.Setup(s => s.GetValueFromClaimType(claimPrincipa, JwtRegisteredClaimNames.NameId)) .Returns(userIdFromClaim); TestRefreshSuccess.response.Token = jwtService.GenerateToken(claimPrincipa.Claims.ToList()); TestRefreshSuccess.response.RefreshToken = jwtService.GenerateRefreshToken(); _jwtServiceMocking.Setup(s => s.GenerateToken(emailFromClaim, userIdFromClaim)) .Returns(TestRefreshSuccess.response.Token); _jwtServiceMocking.Setup(s => s.GenerateRefreshToken()) .Returns(TestRefreshSuccess.response.RefreshToken); _userLogicMocking.Setup(s => s.ValidateRefreshToken(TestRefreshSuccess.user.Email, TestRefreshSuccess.prarameter.RefreshToken)) .Returns(Task.FromResult(PandaResponse.CreateSuccessResponse(true))); _userLogicMocking.Setup(s => s.UpdateRefreshTokenToUser(TestRefreshSuccess.user.Email, TestRefreshSuccess.response.RefreshToken)) .Returns(Task.FromResult(PandaResponse.CreateSuccessResponse(true))); userFacade = new UserFacade(_jwtServiceMocking.Object, _userLogicMocking.Object); #endregion var result = await userFacade.RefreshToken(TestRefreshSuccess.prarameter); _jwtServiceMocking.Verify(v => v.GetPrincipalFromExpiredToken(TestRefreshSuccess.prarameter.Token)); _jwtServiceMocking.Verify(v => v.GetValueFromClaimType(claimPrincipa, JwtRegisteredClaimNames.NameId)); _jwtServiceMocking.Verify(v => v.GenerateToken(emailFromClaim, userIdFromClaim)); _jwtServiceMocking.Verify(v => v.GenerateRefreshToken()); _userLogicMocking.Verify(v => v.ValidateRefreshToken(TestRefreshSuccess.user.Email, TestRefreshSuccess.prarameter.RefreshToken)); _userLogicMocking.Verify(v => v.UpdateRefreshTokenToUser(TestRefreshSuccess.user.Email, TestRefreshSuccess.response.RefreshToken)); Assert.Equal(TestRefreshSuccess.response.RefreshToken, result.Data.RefreshToken); Assert.Equal(TestRefreshSuccess.response.Token, result.Data.Token); }
public void GenerateTokenSuccess() { var email = "*****@*****.**"; string id = "1"; var token = jwtService.GenerateToken(email, id); var principal = jwtService.GetPrincipalFromExpiredToken(token); var IdFromClaims = principal.Claims.Where(w => w.Type.Contains(JwtRegisteredClaimNames.NameId)) .Select(s => s.Value).FirstOrDefault(); var emailFromClaims = principal.Claims.Where(w => w.Type.Contains(JwtRegisteredClaimNames.Email)) .Select(s => s.Value).FirstOrDefault(); Assert.Equal(id, IdFromClaims); Assert.Equal(email, emailFromClaims); }