I have a .net web api that looks as follows:
[ApiController]
public class MyController : ControllerBase
{
[Authorize(Roles ="Admin")]
public IActionResult MyEndpoint()
{
//DO STUFF
return Ok();
}
}
My question is how to unit test the Authorize attribute? How to test that if the jwt token contains an Admin claim it should return 200 else it shall return 401 unauthorized.