How to mock the CreateResponse extension method on HttpRequestMessage

后端 未结 2 720
时光说笑
时光说笑 2020-12-23 19:14

I\'m using ASP.Net MVC 4 RC\'s ApiController and I\'m trying to unit test a GET method.

This method uses the CreateResponse method that\'s on t

相关标签:
2条回答
  • 2020-12-23 19:26

    WebAPI 1 with VB here!

    I managed to hybrid responses from your link above 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.

    0 讨论(0)
  • 2020-12-23 19:27

    This was solved by specifying an empty configuration:

    request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
    

    I got the answer to that from here

    ASP.NET WebApi unit testing with Request.CreateResponse

    0 讨论(0)
提交回复
热议问题