Skip to content

.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

skwasjer/MockHttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

da9a74f · Dec 18, 2024
Dec 18, 2024
Jan 11, 2020
Sep 5, 2024
Oct 1, 2024
Oct 6, 2024
Sep 10, 2024
Sep 29, 2024
Jun 4, 2019
Jan 31, 2024
Nov 22, 2021
Nov 22, 2021
Sep 29, 2024
Nov 18, 2023
Dec 18, 2024
Jun 4, 2019
Nov 18, 2023
Sep 10, 2024
Nov 18, 2023
Nov 18, 2023

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.


Main workflow Quality Gate Status Coverage

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.

Other info

While this library was inspired by Moq - it does not and will not include SponsorLink. I have no direct relation to Moq or its author.