开发者

Unit Test Controller with PerWebRequest LifeStyle dependency

开发者 https://www.devze.com 2023-02-03 01:28 出处:网络
I am trying to write a unit test for a controller that has a dependency on a type whose lifestyle is \"PerWebRequest\".

I am trying to write a unit test for a controller that has a dependency on a type whose lifestyle is "PerWebRequest".

Castle throws the following exception:

System.InvalidOperationException: HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net.

Can I mock the HttpContext.开发者_开发问答Current property somehow to get around this?

I have tried to use MVCContrib's TestControllerBuilder to initialize this controller but it has no effect.

  SymptomTopicController controller = new SymptomTopicController();
        controller.WorkOrderFulfillment = workOrderFulfillment;

        TestControllerBuilder controllerBuilder = new TestControllerBuilder();
        controllerBuilder.InitializeController(controller);


Unit Test Controller with PerWebRequest LifeStyle dependency

Abstract the dependency and don't use container in your tests.


Have you seen this question: Mock HttpContext.Current in Test Init Method ?

0

精彩评论

暂无评论...
验证码 换一张
取 消