未能在单元测试中包含system.web.http吗? [英] Failure to Include system.web.http in unit tests?

查看:107
本文介绍了未能在单元测试中包含system.web.http吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试对我创建的ApiController进行单元测试. 我绊倒的是由于某种原因我不能使用" System.Web.Http.尽管在我的主项目中,我可以毫无问题地使用using(因此可以使用IHttpActionResult).

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?

推荐答案

根据建议此处System.Web.Http可以通过NuGet安装

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. .

毕竟,System.Web名称空间似乎不包含任何Http成员.

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

无论如何,由于您在评论部分中说您的引用中已经包含System.Web.Http,因此,我想说的是在安装NuGet软件包之前可能缺少某些依赖项.

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取决于

  • WebApi.Client(请参见链接),其中转向取决于
  • Newtonsoft.Json(请参阅链接)
  • >
  • WebApi.Client (see link), which in turn depends on
  • Newtonsoft.Json (see link)

也有人在此处.

这篇关于未能在单元测试中包含system.web.http吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆