3.0.0
New Features
- Assertion matching by URL query parameters #41
WebMock.Assert
.Get('/resource`)
.WithQueryParam('ParamName', 'Value')
.WasRequested;
- Request content matching by Form-Data #20
HTTP requests can be matched by form-data as submitted with content-type of application/x-www-form-urlencoded. Multiple matching field values can be combined. For example:
WebMock.StubRequest('*', '*')
.WithFormData('AField', 'A value.')
.WithFormData('AOtherField', 'Another value.');
To simply match the presence of a field, a wildcard * can be passed for the value.
- Request matching by JSON values
HTTP requests can be matched by JSON data as submitted with content-type of application/json using WithJSON. Multiple matching field values can be combined. For example:
WebMock.StubRequest('*', '*')
.WithJSON('ABoolean', True)
.WithJSON('AFloat', 0.123)
.WithJSON('AInteger', 1)
.WithJSON('AString', 'value');
The first argument can be a path. For example, in the following JSON, the path objects[0].key would match value 1.
{
"objects": [
{ "key": "value 1" },
{ "key": "value 2" }
]
}
Assertions can also be made with JSON values:
WebMock.Assert
.Patch('/resource`)
.WithJSON('key', 'value')
.WasRequested;