Writing Unit Test for methods that use User.Identity.Name in ASP.NET Web API

后端 未结 8 634
醉梦人生
醉梦人生 2020-12-29 18:33

I am writing test cases using the Unit Test for ASP.NET Web API.

Now I have an action which makes a call to some method I have defined in the service layer, where I

8条回答
  •  悲哀的现实
    2020-12-29 19:06

    With WebApi 5.0 this is slightly different. You can now do:

    controller.User = new ClaimsPrincipal(
      new GenericPrincipal(new GenericIdentity("user"), null));
    

提交回复
热议问题