Failure to Include system.web.http in unit tests?

感情迁移 提交于 2019-12-10 11:48:24

问题


I'm currently trying to unit test an ApiController I've created. What I'm stumbling over is that for some reason I can't "use" System.Web.Http. In my main project though I can use the using without any problem (and thus use IHttpActionResult).

Now what I'm not getting is why is it not possible in the unit test Project? Am I overlooking here something or do I need to do something differently?


回答1:


As suggested here, System.Web.Http can be installed via NuGet

Get-Project MyTestProject | Install-Package Microsoft.AspNet.WebApi.Core

I tested it in my Unit Test Project and it worked, actually downloading it. .

After all, the System.Web namespace doesn't seem to contain any Http member.

Anyway, since you said in the comments section that you already had System.Web.Http in your references, off the top of my head I'd say that maybe some dependencies were missing before installing the NuGet package.

WebApi.Core depends on

  • WebApi.Client (see link), which in turn depends on
  • Newtonsoft.Json (see link)

A very, very similar question was also asked here.



来源:https://stackoverflow.com/questions/49447891/failure-to-include-system-web-http-in-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!