Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skwasjer/mockhttp
.NET library to mock HTTP responses for any HTTP client and verify request expectations with an experience inspired by Moq.
https://github.com/skwasjer/mockhttp
dotnet dotnetcore http httpclient httpmock mock mockhttp mocking testing verifying-requests
Last synced: 6 days ago
JSON representation
.NET library to mock HTTP responses for any HTTP client and verify request expectations with an experience inspired by Moq.
- Host: GitHub
- URL: https://github.com/skwasjer/mockhttp
- Owner: skwasjer
- License: apache-2.0
- Created: 2019-07-03T20:16:52.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-07T16:36:21.000Z (about 1 year ago)
- Last Synced: 2024-05-16T08:04:41.782Z (9 months ago)
- Topics: dotnet, dotnetcore, http, httpclient, httpmock, mock, mockhttp, mocking, testing, verifying-requests
- Language: C#
- Homepage:
- Size: 915 KB
- Stars: 31
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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](https://github.com/skwasjer/MockHttp/actions/workflows/main.yml/badge.svg)](https://github.com/skwasjer/MockHttp/actions/workflows/main.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=skwasjer_MockHttp&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=skwasjer_MockHttp)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=skwasjer_MockHttp&metric=coverage)](https://sonarcloud.io/component_measures?id=skwasjer_MockHttp&metric=coverage)| | | |
|---|---|---|
| `skwas.MockHttp` | [![NuGet](https://img.shields.io/nuget/v/skwas.MockHttp.svg)](https://www.nuget.org/packages/skwas.MockHttp/) [![NuGet](https://img.shields.io/nuget/dt/skwas.MockHttp.svg)](https://www.nuget.org/packages/skwas.MockHttp/) | [Documentation](https://github.com/skwasjer/MockHttp/wiki) |
| `skwas.MockHttp.Json` | [![NuGet](https://img.shields.io/nuget/v/skwas.MockHttp.Json.svg)](https://www.nuget.org/packages/skwas.MockHttp.Json/) [![NuGet](https://img.shields.io/nuget/dt/skwas.MockHttp.Json.svg)](https://www.nuget.org/packages/skwas.MockHttp.Json/) | [Documentation](https://github.com/skwasjer/MockHttp/wiki) |
| `skwas.MockHttp.Server` | [![NuGet](https://img.shields.io/nuget/v/skwas.MockHttp.Server.svg)](https://www.nuget.org/packages/skwas.MockHttp.Server/) [![NuGet](https://img.shields.io/nuget/dt/skwas.MockHttp.Server.svg)](https://www.nuget.org/packages/skwas.MockHttp.Server/) | [Documentation](https://github.com/skwasjer/MockHttp/wiki/Stubbing-an-API) |## Documentation
Please see the [wiki for documentation](https://github.com/skwasjer/MockHttp/wiki).
## Usage example ###
```csharp
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](./CONTRIBUTING.md).
### Other info
> While this library was inspired by Moq - it does not and will not include [SponsorLink](https://github.com/moq/moq/issues/1372). I have no direct relation to Moq or its author.