Unit Test PerWebRequest LifeStyle Dependent Controller

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

The lock 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 to get around this?

I tried using MVCContrib TestControllerBuilder to initialize this controller, but it has no effect.

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

        TestControllerBuilder controllerBuilder = new TestControllerBuilder();
        controllerBuilder.InitializeController(controller);
+3
source share
2 answers
+1
source

You're doing it wrong

.

+7

Source: https://habr.com/ru/post/1783499/


All Articles