Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Testing layer for Microsoft's HttpClient library. Create canned responses using a fluent API.
| Date | Stars |
|---|---|
| 2026-07-24 | 1764 |
| 2026-07-25 | 1764 |
| 2026-07-28 | 1764 |
| 2026-07-30 | 1764 |
| 2026-08-06 | 1764 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
[](https://www.nuget.org/packages/RichardSzalay.MockHttp/)[](https://www.nuget.org/packages/RichardSzalay.MockHttp/)
MockHttp for HttpClient
=====================
MockHttp is a testing layer for Microsoft's HttpClient library. It allows stubbed responses to be configured for matched HTTP requests and can be used to test your application's service layer.
## NuGet
PM> Install-Package RichardSzalay.MockHttp
## How?
MockHttp defines a replacement `HttpMessageHandler`, the engine that drives HttpClient, that provides a fluent configuration API and provides a canned response. The caller (eg. your application's service layer) remains unaware of its presence.
## Usage
```csharp
var mockHttp = new MockHttpMessageHandler();
// Setup a respond for the user api (including a wildcard in the URL)
mockHttp.When("http://localhost/api/user/*")
.Respond("application/json", "{'name' : 'Test McGee'}"); // Respond with JSON
// Inject the handler or client into your application code
var client = mockHttp.ToHttpClient();
var response = await client.GetAsync("http://localhost/api/user/1234");
// or without async: var response = client.GetAsync("http://localhost/api/user/1234").Result;
var json = await response.Content.ReadAsStringAsync();
// No network connection required
Console.Write(json); // {'name' : 'Test McGee'}
```
### When (Backend Definitions) vs Expect (Request Expectations)
`MockHttpMessageHandler` defines both `When` and `Expect`, which can be used to define responses. They both expose the same fluent API, but each works in a slightly different way.
Using `When` specifies a "Backend Definition". Backend Definitions can be matched against multiple times and in any order, but they won't match if there are any outstanding Request Expectations present (unless `BackendDefinitionBehavior.Always` is specified). If no Request Expectations match, `Fallback` will be used.
Using `Expect` specifies a "Request Expectation". Request Expectations match only once and in the order they were added in. Only once all expectations have been satisfied will Backend Definitions be evaluated. Calling `mockHttp.VerifyNoOutstandingExpectation()` will assert that there are no expectations that have yet to be called. Calling `ResetExpectations` clears the the queue of expectations.
This pattern is heavily inspired by [AngularJS's $httpBackend](https://docs.angularjs.org/api/ngMock/service/$httpBackend)
### Matchers (With*)
The `With` and `Expect` methods return a `MockedRequest`, which can have additional constraints (called matchers) placed on them before specifying a response with `Respond`.
Passing an HTTP method and URL to `When` or `Expect` is equivalent to applying a Method and Url matcher respectively. The following chart breaks down additional built in matchers and their usage:
| Method | Description |
| ------ | ----------- |
| <pre>WithQueryString("key", "value")<br /><br />WithQueryString("key=value&other=value")<br /><br />WithQueryString(new Dictionary<string,string><br />{<br /> { "key", "value" },<br /> { "other", "value" }<br />}<br /></pre> | Matches on one or more querystring values, ignoring additional values |
| <pre>WithExactQueryString("key=value&other=value")<br /><br />WithExactQueryString(new Dictionary<string,string><br />{<br /> { "key", "value" },<br /> { "other", "value" }<br />}<br /></pre> | Matches on one or more querystring values, rejecting additional values |
| <pre>WithFormData("key", "value")<br /><br />WithFormData("key=value&other=value")<br /><br />WithFormData(new Dictionary<string,string><br />{<br /> { "key", "value" },<br /> { "other", "value" }<br />})<br /></pre> | Matches on one or more form data values, ignoring additional values |
| <pre>WithExactFormData("key=value&other=value")<br /><br />WithExactForExcerpt of 10,231 characters
Read on GitHub134
2
1
1
1
1
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:1f587c3f26b6d45d, topic:testing