Skip to content

Commit cc85082

Browse files
committed
Update documentation
1 parent 9e7c30a commit cc85082

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Docs/pages/special-types/01-httpclient.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,32 @@ httpClient.SetupMock.Method
214214

215215
- Similar to the query parameter matching, the order of the form-data key-value pairs does not matter.
216216
- Add the `.Exactly()` modifier to also check that no other form-data is present.
217+
218+
### Header matching
219+
220+
To verify against the HTTP content headers, use the following methods:
221+
222+
- `.WithHeaders(string, HttpHeaderValue)`: checks that the content headers contain the provided key-value pair
223+
- `.WithHeaders(IEnumerable<(string, HttpHeaderValue)>)`: checks that the content headers contain all key-value pairs
224+
- `.WithHeaders(string)`: checks that the content headers contain the provided raw headers
225+
226+
```csharp
227+
httpClient.SetupMock.Method
228+
.PostAsync(
229+
It.IsAny<string>(),
230+
It.IsHttpContent().WithHeaders(("Content-Type", "application/json"), ("X-My-Header", "my-value")))
231+
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
232+
httpClient.SetupMock.Method
233+
.PostAsync(
234+
It.IsAny<string>(),
235+
It.IsHttpContent().WithHeaders("""
236+
Content-Type: application/json
237+
X-My-Header: my-value
238+
"""))
239+
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
240+
```
241+
242+
**Notes:**
243+
244+
- Per default only the content headers are checked, not the headers in the corresponding `HttpRequestMessage`.
245+
If you want to check both, add the `.IncludingRequestHeaders()` modifier.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,35 @@ httpClient.SetupMock.Method
11961196
- Similar to the query parameter matching, the order of the form-data key-value pairs does not matter.
11971197
- Add the `.Exactly()` modifier to also check that no other form-data is present.
11981198

1199+
**Header matching**
1200+
1201+
To verify against the HTTP content headers, use the following methods:
1202+
1203+
- `.WithHeaders(string, HttpHeaderValue)`: checks that the content headers contain the provided key-value pair
1204+
- `.WithHeaders(IEnumerable<(string, HttpHeaderValue)>)`: checks that the content headers contain all key-value pairs
1205+
- `.WithHeaders(string)`: checks that the content headers contain the provided raw headers
1206+
1207+
```csharp
1208+
httpClient.SetupMock.Method
1209+
.PostAsync(
1210+
It.IsAny<string>(),
1211+
It.IsHttpContent().WithHeaders(("Content-Type", "application/json"), ("X-My-Header", "my-value")))
1212+
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
1213+
httpClient.SetupMock.Method
1214+
.PostAsync(
1215+
It.IsAny<string>(),
1216+
It.IsHttpContent().WithHeaders("""
1217+
Content-Type: application/json
1218+
X-My-Header: my-value
1219+
"""))
1220+
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
1221+
```
1222+
1223+
*Notes:*
1224+
1225+
- Per default only the content headers are checked, not the headers in the corresponding `HttpRequestMessage`.
1226+
If you want to check both, add the `.IncludingRequestHeaders()` modifier.
1227+
11991228
### Delegates
12001229

12011230
Mockolate supports mocking delegates including `Action`, `Func<T>`, and custom delegates.

0 commit comments

Comments
 (0)