/// <summary> /// Matches a request by matching the request message version. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="version">The message version.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Version(this RequestMatching builder, Version version) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new VersionMatcher(version))); }
/// <summary> /// Matches a request by query string. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="parameters">The query string parameters.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching QueryString(this RequestMatching builder, IEnumerable <KeyValuePair <string, IEnumerable <string> > > parameters) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new QueryStringMatcher(parameters))); }
/// <summary> /// Matches a request using a custom expression. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="expression">The expression.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Where(this RequestMatching builder, Expression <Func <HttpRequestMessage, bool> > expression) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new ExpressionMatcher(expression))); }
/// <summary> /// Matches a request explicitly that has no request content. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching WithoutContent(this RequestMatching builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new ContentMatcher())); }
/// <summary> /// Matches a request by query string. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="parameters">The query string parameters.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching QueryString(this RequestMatching builder, NameValueCollection parameters) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new QueryStringMatcher(parameters?.AsEnumerable()))); }
/// <summary> /// Matches a request by request content. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="content">The request content.</param> /// <param name="encoding">The request content encoding.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Content(this RequestMatching builder, string content, Encoding encoding) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new ContentMatcher(content, encoding))); }
/// <summary> /// Matches a request explicitly that has no request content. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching WithoutQueryString(this RequestMatching builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new QueryStringMatcher(""))); }
/// <summary> /// Matches a request by HTTP header. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="name">The header name.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Header(this RequestMatching builder, string name) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new HttpHeadersMatcher(name))); }
/// <summary> /// Matches a request by HTTP header. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="headers">The headers.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Headers(this RequestMatching builder, IEnumerable <KeyValuePair <string, IEnumerable <string> > > headers) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new HttpHeadersMatcher(headers))); }
/// <summary> /// Matches a request by HTTP header. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="name">The header name.</param> /// <param name="values">The header values.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Header(this RequestMatching builder, string name, IEnumerable <string> values) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new HttpHeadersMatcher(name, values))); }
/// <summary> /// Matches a request by HTTP header. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="name">The header name.</param> /// <param name="value">The header value.</param> /// <param name="allowWildcards"><see langword="true"/> to allow wildcards, or <see langword="false"/> if exact matching.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Header(this RequestMatching builder, string name, string value, bool allowWildcards) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new HttpHeadersMatcher(name, value, allowWildcards))); }
/// <summary> /// Matches a request by HTTP method. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="method">The HTTP method.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Method(this RequestMatching builder, HttpMethod method) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new HttpMethodMatcher(method))); }
/// <summary> /// Matches a request by form data. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="formData">The form data parameters.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching FormData(this RequestMatching builder, IEnumerable <KeyValuePair <string, IEnumerable <string> > > formData) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.With(new FormDataMatcher(formData))); }
/// <summary> /// Matches a request by partially matching the request content. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="partialContent">The request content.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching PartialContent(this RequestMatching builder, byte[] partialContent) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (partialContent is null) { throw new ArgumentNullException(nameof(partialContent)); } return(builder.With(new PartialContentMatcher(partialContent))); }
/// <summary> /// Matches a request by form data. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="urlEncodedFormData">The form data.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching FormData(this RequestMatching builder, string urlEncodedFormData) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrEmpty(urlEncodedFormData)) { throw new ArgumentException("Specify the url encoded form data.", nameof(urlEncodedFormData)); } return(builder.With(new FormDataMatcher(urlEncodedFormData))); }
/// <summary> /// Matches a request by specified <paramref name="requestUri"/>. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="requestUri">The relative or absolute request URI.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching RequestUri(this RequestMatching builder, Uri requestUri) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (requestUri is null) { throw new ArgumentNullException(nameof(requestUri)); } return(builder.With(new RequestUriMatcher(requestUri))); }
/// <summary> /// Matches a request by media type. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="mediaType">The media type.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching ContentType(this RequestMatching builder, MediaTypeHeaderValue mediaType) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (mediaType is null) { throw new ArgumentNullException(nameof(mediaType)); } return(builder.With(new MediaTypeHeaderMatcher(mediaType))); }
/// <summary> /// Matches a request by query string. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="queryString">The query string.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching QueryString(this RequestMatching builder, string queryString) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrEmpty(queryString)) { throw new ArgumentException("Specify a query string, or use 'WithoutQueryString'.", nameof(queryString)); } return(builder.With(new QueryStringMatcher(queryString))); }
/// <summary> /// Matches a request by verifying it against a list of constraints, for which at least one has to match the request. /// </summary> /// <param name="builder">The request matching builder instance.</param> /// <param name="anyBuilder">An action to configure an inner request matching builder.</param> /// <returns>The request matching builder instance.</returns> public static RequestMatching Any(this RequestMatching builder, Action <RequestMatching> anyBuilder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (anyBuilder is null) { throw new ArgumentNullException(nameof(anyBuilder)); } var anyRequestMatching = new AnyRequestMatching(); anyBuilder(anyRequestMatching); return(builder.With(new AnyMatcher(anyRequestMatching.Build()))); }