Skip to content
forked from skwasjer/MockHttp

.NET library to mock HTTP responses for any HTTP client and verify request expectations with an experience inspired by Moq.

License

Notifications You must be signed in to change notification settings

dhymik/MockHttp

 
 

Repository files navigation

MockHttp

Collection of .NET libraries to mock HTTP responses for any HTTP client (HttpClient, WebRequest, RestClient, etc.) and verify request expectations with an experience inspired by Moq.


Build status Tests codecov

skwas.MockHttp NuGet NuGet Documentation
skwas.MockHttp.Json NuGet NuGet Documentation
skwas.MockHttp.Server NuGet NuGet Documentation

Documentation

Please see the wiki for documentation.

Usage example

MockHttpHandler mockHttp = new MockHttpHandler();

// Configure setup(s).
mockHttp
    .When(matching => matching
        .Method("GET")
        .RequestUri("http://localhost/controller/*")
    )
    .Respond(with => with
        .StatusCode(200)
        .JsonBody(new { id = 123, firstName = "John", lastName = "Doe" })
    )
    .Verifiable();

var client = new HttpClient(mockHttp);

var response = await client.GetAsync("http://localhost/controller/action?test=1");

// Verify expectations.
mockHttp.Verify();

Contributions

Please check out the contribution guidelines.

About

.NET library to mock HTTP responses for any HTTP client and verify request expectations with an experience inspired by Moq.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%