-
Notifications
You must be signed in to change notification settings - Fork 4
Home
skwasjer edited this page Jan 17, 2020
·
11 revisions
Mock HTTP responses for HttpClient
and verify request expectations, with an experience inspired by Moq.
Install MockHttp via the Nuget package manager or dotnet
cli.
dotnet add package skwas.MockHttp
For JSON or MediaTypeFormatter
integration
dotnet add package skwas.MockHttp.Json
skwas.MockHttp |
||
skwas.MockHttp.Json |
||
skwas.MockHttp.Server |
WIP |
MockHttpHandler mockHttp = new MockHttpHandler();
// Configure setup(s).
mockHttp
.When(matching => matching
.Method("GET")
.RequestUri("http://localhost/controller/*")
)
.RespondJson(HttpStatusCode.OK, 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();