我的申请中有以下单元测试:
[TestMethod]
public void Windsor_Can_Resolve_HomeController_Dependencies()
{
// Setup
WindsorContainer container = new WindsorContainer();
container.Install(FromAssembly.Containing<HomeController>());
// Act
container.Kernel.Resolve(typeof(HomeController));
}
Run Code Online (Sandbox Code Playgroud)
这一点是为了确保我没有任何windsor配置问题,在我访问该控制器上的操作之前我将无法实现.问题是我的所有对象注册都被注册为,PerWebRequestLifestyle所以我不会遇到我的实体框架数据上下文在Web请求之间共享的问题(这会在运行多个操作时导致错误).
但是,每当我运行此单元测试时,我都会遇到以下异常:
System.InvalidOperationException:HttpContext.Current为null.PerWebRequestLifestyle只能在ASP.Net中使用
如何在不改变对象注册命令的生活方式的情况下测试此场景?