Mocking IPrincipal in ASP.NET Core
The controller’s User is accessed through the HttpContext of the controller. The latter is stored within the ControllerContext. The easiest way to set the user is by assigning a different HttpContext with a constructed user. We can use DefaultHttpContext for this purpose, that way we don’t have to mock everything. Then we just use that … Read more