未能在单元测试中包含 system.web.http? [英] Failure to Include system.web.http in unit tests?
问题描述
我目前正在尝试对我创建的 ApiController
进行单元测试.我绊倒的是,由于某种原因我不能使用"System.Web.Http
.在我的主项目中,虽然我可以毫无问题地使用 using
(因此使用 IHttpActionResult
).
现在我没有得到的是为什么在单元测试项目中不可能?我是在这里忽略了什么还是我需要做一些不同的事情?
建议 .
毕竟,System.Web
命名空间似乎不包含任何 Http
成员.
无论如何,既然你在评论部分说你的参考文献中已经有 System.Web.Http
,我会说在安装之前可能缺少一些依赖项NuGet 包.
WebApi.Core
依赖于
这里.
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?
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
A very, very similar question was also asked here.
这篇关于未能在单元测试中包含 system.web.http?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!