private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessagesCheck check, object?jsonObject, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } var jsonString = JsonSerializer.Serialize(jsonObject); return(check.WithFilter(x => x.HasContent(jsonString) && x.HasContentHeader("Content-Type", "application/json*"), expectedNumberOfRequests, $"json content '{jsonString}'")); }
private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCheck check, string pattern, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } return(check.WithFilter(x => x.HasContent(pattern), expectedNumberOfRequests, $"content '{pattern}'")); }
private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesCheck check, string headerName, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (string.IsNullOrEmpty(headerName)) { throw new ArgumentNullException(nameof(headerName)); } return(check.WithFilter(x => x.HasRequestHeader(headerName) || x.HasContentHeader(headerName), expectedNumberOfRequests, $"header '{headerName}'")); }
private static IHttpRequestMessagesCheck WithHttpVersion(this IHttpRequestMessagesCheck check, Version httpVersion, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (httpVersion == null) { throw new ArgumentNullException(nameof(httpVersion)); } return(check.WithFilter(x => x.HasHttpVersion(httpVersion), expectedNumberOfRequests, $"HTTP Version '{httpVersion}'")); }
private static IHttpRequestMessagesCheck WithHttpMethod(this IHttpRequestMessagesCheck check, HttpMethod httpMethod, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (httpMethod == null) { throw new ArgumentNullException(nameof(httpMethod)); } return(check.WithFilter(x => x.HasHttpMethod(httpMethod), expectedNumberOfRequests, $"HTTP Method '{httpMethod}'")); }
private static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpRequestMessagesCheck check, IEnumerable <KeyValuePair <string?, string?> > nameValueCollection, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (nameValueCollection == null) { throw new ArgumentNullException(nameof(nameValueCollection)); } using var content = new FormUrlEncodedContent(nameValueCollection); var contentString = content.ReadAsStringAsync().Result; return(check.WithFilter(x => x.HasContent(contentString) && x.HasContentHeader("Content-Type", "application/x-www-form-urlencoded*"), expectedNumberOfRequests, $"form url encoded content '{contentString}'")); }
private static IHttpRequestMessagesCheck WithQueryString(this IHttpRequestMessagesCheck check, string pattern, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } var condition = pattern switch { "" => "no querystring", "*" => "any querystring", _ => $"querystring pattern '{pattern}'" }; return(check.WithFilter(x => x.HasQueryString(pattern), expectedNumberOfRequests, condition)); }
private static IHttpRequestMessagesCheck WithRequestUri(this IHttpRequestMessagesCheck check, string pattern, int?expectedNumberOfRequests) { if (check == null) { throw new ArgumentNullException(nameof(check)); } if (string.IsNullOrEmpty(pattern)) { throw new ArgumentNullException(nameof(pattern)); } var condition = string.Empty; if (pattern != "*") { condition = $"uri pattern '{pattern}'"; } return(check.WithFilter(x => x.HasMatchingUri(pattern), expectedNumberOfRequests, condition)); }