Skip to content

Testing your code that makes HTTP requests is even easier with this library of fakes.

Notifications You must be signed in to change notification settings

markmelville/FakeHttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FakeHttp - because there's a lot of real HTTP going on, and we need to test it.

FakeHttp contains helpers that allow isolated testing of code that makes HTTP requests. Even though the code thinks it has a real object, all the responses are faked and so no actual HTTP request is made.

NuGet

This project is found on NuGet.org at [https://nuget.org/packages/FakeHttp]

HttpClient

The only currently supported object is System.Net.Http.HttpClient, which is new as of .NET 4.0. If this object implemented an interface, you could use your favorite mock library as a fake. Since it doesn't, we provide a FakeHttpClient which can be configured to return the desired responses.

HttpClient client = new FakeHttpClient();
client.AddRule(r => r.RequestUri.Host == "www.google.com", new HttpResponseMessage(HttpStatusCode.OK));

var response = await client.GetAsync("http://www.google.com");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

Source Code

To compile the project, you'll need Visual Studio 2012.

If you find a bug, please create an issue in the Issue tracker (https://github.com/markmelville/FakeHttp/issues).

About

Testing your code that makes HTTP requests is even easier with this library of fakes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages