Thomas
Thomas

Reputation: 2984

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

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?

Upvotes: 1

Views: 2198

Answers (1)

Francesco B.
Francesco B.

Reputation: 3107

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.

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.

Upvotes: 4

Related Questions