【发布时间】:2017-05-19 09:03:59
【问题描述】:
您好,我想在 ASP.NET Core 中模拟 IHttpConnectionFeature
在我的控制器中,我有:
var connectionId = HttpContext.Features.Get<IHttpConnectionFeature>().ConnectionId;
但是如何在我的单元测试中模拟它:
var controller = new MyController(logger.Object,
mockService.Object)
{
ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext()
}
};
我收到一条错误消息:
Message = "对象引用未设置为对象的实例。"
【问题讨论】:
标签: c# asp.net unit-testing asp.net-core httpcontext