public async Task Login_IncorrectLogin() { var userManager = GetUserManager(); var signInManager = GetSignInManager(SignInIncorrectLogin); var jwtSettings = JwtSettings; var loginController = new AuthorizeController(userManager.Object, signInManager.Object, jwtSettings); var tokenResult = await loginController.AuthorizeJwt(LoginData.Authorize); Assert.IsType <BadRequestObjectResult>(tokenResult.Result); }
public async Task Login_GenerateToken() { var userManager = GetUserManager(); var signInManager = GetSignInManager(SignInSuccess); var jwtSettings = JwtSettings; var loginController = new AuthorizeController(userManager.Object, signInManager.Object, jwtSettings); var tokenResult = await loginController.AuthorizeJwt(LoginData.Authorize); var handler = new JwtSecurityTokenHandler(); var tokenDecode = handler.ReadToken(tokenResult.Value) as JwtSecurityToken; var claims = tokenDecode?.Claims.ToList(); var claimRole = claims?.First(claim => claim.Type == ClaimTypes.Role && claim.Value == LoginData.Roles.First()); Assert.True(!String.IsNullOrWhiteSpace(tokenResult.Value)); Assert.NotNull(claimRole); }