ASP.NET WebApi unit testing with Request.CreateResponse

后端 未结 5 1986
遇见更好的自我
遇见更好的自我 2020-12-04 06:42

I am trying to write some unit tests for my ApiController and faced some issues. There is a nice extension method called Request.CreateResponse that helps a lot with generat

5条回答
  •  不思量自难忘°
    2020-12-04 07:10

    In your test class, create an instance of the controller class. e.g var customerController= new CustomerController();

    customerController.Request = new HttpRequestMessage();
    customerController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
    

提交回复
热议问题