ASP.NET WebApi unit testing with Request.CreateResponse

后端 未结 5 1990
遇见更好的自我
遇见更好的自我 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:15

    WebAPI 1 here with a similar issue using VB.

    I managed to hybrid responses here to get this to work as simple as this:

    Dim request As HttpRequestMessage = New HttpRequestMessage()
    Return request.CreateResponse(HttpStatusCode.BadRequest, myCustomClassObject, GlobalConfiguration.Configuration)
    

    Just posting in case it helps anyone.

提交回复
热议问题