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

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

问题描述

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

现在我没有得到的是为什么在单元测试项目中不可能?我是在这里忽略了什么还是我需要做一些不同的事情?

解决方案

建议 .

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

无论如何,既然你在评论部分说你的参考文献中已经有 System.Web.Http ,我会说在安装之前可能缺少一些依赖项NuGet 包.

WebApi.Core 依赖于

  • WebApi.Client(参见 链接),而这又取决于
  • Newtonsoft.Json(参见 链接)

这里.

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

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

A very, very similar question was also asked here.

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

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