{"id":30202954,"url":"https://github.com/kaliumhexacyanoferrat/mockh","last_synced_at":"2025-08-13T11:13:43.569Z","repository":{"id":40283849,"uuid":"431973120","full_name":"Kaliumhexacyanoferrat/MockH","owner":"Kaliumhexacyanoferrat","description":"This library allows to mock HTTP responses for integration, component and acceptance tests of your projects written in C# / .NET by hosting a webserver returning configured responses.","archived":false,"fork":false,"pushed_at":"2025-01-31T12:37:50.000Z","size":72,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-19T10:19:39.601Z","etag":null,"topics":["c-sharp","component-testing","csharp","dotnet","dotnet9","http","integration-testing","integration-tests","mock","mocking","mocking-framework","mocking-server","request","response","webserver"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kaliumhexacyanoferrat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Kaliumhexacyanoferrat"}},"created_at":"2021-11-25T20:47:02.000Z","updated_at":"2025-01-31T12:34:41.000Z","dependencies_parsed_at":"2024-06-04T09:11:19.214Z","dependency_job_id":null,"html_url":"https://github.com/Kaliumhexacyanoferrat/MockH","commit_stats":{"total_commits":40,"total_committers":3,"mean_commits":"13.333333333333334","dds":"0.42500000000000004","last_synced_commit":"1b1fcd1ae2bc89d0efc2bb3721e7c5af4f1ac4bf"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Kaliumhexacyanoferrat/MockH","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kaliumhexacyanoferrat%2FMockH","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kaliumhexacyanoferrat%2FMockH/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kaliumhexacyanoferrat%2FMockH/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kaliumhexacyanoferrat%2FMockH/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kaliumhexacyanoferrat","download_url":"https://codeload.github.com/Kaliumhexacyanoferrat/MockH/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kaliumhexacyanoferrat%2FMockH/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270228594,"owners_count":24548867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","component-testing","csharp","dotnet","dotnet9","http","integration-testing","integration-tests","mock","mocking","mocking-framework","mocking-server","request","response","webserver"],"created_at":"2025-08-13T11:13:40.377Z","updated_at":"2025-08-13T11:13:43.507Z","avatar_url":"https://github.com/Kaliumhexacyanoferrat.png","language":"C#","funding_links":["https://github.com/sponsors/Kaliumhexacyanoferrat"],"categories":[],"sub_categories":[],"readme":"# MockH\n\n[![CI](https://github.com/Kaliumhexacyanoferrat/MockH/actions/workflows/ci.yml/badge.svg)](https://github.com/Kaliumhexacyanoferrat/MockH/actions/workflows/ci.yml) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Kaliumhexacyanoferrat_MockH\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=Kaliumhexacyanoferrat_MockH) [![nuget Package](https://img.shields.io/nuget/v/MockH.svg)](https://www.nuget.org/packages/MockH/)\n\nThis library allows to mock HTTP responses for integration, component and acceptance tests of your projects written in C# / .NET 8/9 by hosting a webserver returning configured responses.\n\n- Fast and thread safe\n- Only a few dependencies\n- No configuration needed\n- Does not interfer with Kestrel or ASP.NET\n- Independent from the testing framework in place\n\n## Usage\n\n```csharp\nusing MockH;\n\n[TestMethod]\npublic async Task TestSomething() \n{\n   await using var server = await MockServer.RunAsync\n   (\n       On.Get(\"/users/1\").Return(new User(...)),\n       On.Get(\"/users/2\").Respond(ResponseStatus.NoContent)\n   );\n\n   // access the server in your code via HTTP\n   using var client = new HttpClient();\n\n   await client.GetStringAsync(server.Url(\"/users/1\"));\n}\n```\n\n## Basic Usage\n\n```csharp\n// return a specific status code\nOn.Get(\"/ifail\").Respond(ResponseStatus.InternalServerError);\n\n// redirect the client\nOn.Get().Redirect(\"https://github.com\");\n\n// execute logic and return some simple text value\nOn.Get().Run(() =\u003e \"42\");\n\n// execute logic and return some JSON\nprivate record MyClass(int IntValue, string StringValue);\n\nOn.Get().Run(() =\u003e new MyClass(42, \"The answer\"));\n\n// execute logic asynchronously\nOn.Get().Run(async () =\u003e await ...);\n\n// access query parameters (GET /increment?=1)\nOn.Get(\"/increment\").Run((int i) =\u003e i + 1);\n\n// access path parameters (GET /increment/1)\nOn.Get(\"/increment/:i\").Run((int i) =\u003e i + 1);\n\n// access request body\nOn.Post().Run((MyClass body) =\u003e body);\n\n// access request body as stream\nOn.Post().Run((Stream body) =\u003e body.Length);\n```\n\n## Advanced Usage\n\n```csharp\n// directly access request and response\nOn.Get().Run((IRequest request) =\u003e request.Respond().Status(ResponseStatus.BadRequest));\n\n// return a handler provided by the GenHTTP framework, e.g. a website\n// see https://genhttp.org/documentation/content/\n// can be useful if you want to test some kind of website crawler\nOn.Get().Run(() =\u003e Listing.From(ResourceTree.FromDirectory(\"/var/www\")));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaliumhexacyanoferrat%2Fmockh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaliumhexacyanoferrat%2Fmockh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaliumhexacyanoferrat%2Fmockh/lists"}