标签:user http returns context name mock `` app use
在单元测试种模拟 User.identity.Name
```
OrdersController ordersController = new OrdersController(appDbContext, null);
Mock<ControllerContext> mockcontaxt = new Mock<ControllerContext>();
Mock<HttpContext> mockhttpcontaxt = new Mock<HttpContext>();
ordersController.ControllerContext = mockcontaxt.Object;
mockhttpcontaxt.SetupGet(t => t.User.Identity.Name).Returns("1");
ordersController.ControllerContext.HttpContext = mockhttpcontaxt.Object;![]
## 这是 .net core 3.1.4 的模拟
标签:user http returns context name mock `` app use
原文地址:https://blog.51cto.com/3478586/2516253