Answers for "Mock asp core controller User claims principal"

0

Mock asp core controller User claims principal

var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{
    new Claim(ClaimTypes.Name, "example name"),
    new Claim(ClaimTypes.NameIdentifier, "1"),
    new Claim("custom-claim", "example claim value"),
}, "mock"));

var controller = new SomeController(dependencies…);
controller.ControllerContext = new ControllerContext()
{
    HttpContext = new DefaultHttpContext() { User = user }
};
Posted by: Guest on April-24-2021

Code answers related to "Mock asp core controller User claims principal"

Browse Popular Code Answers by Language