示例#1
0
        /// <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)));
        }
示例#2
0
        /// <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)));
        }
示例#3
0
        /// <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)));
        }
示例#4
0
        /// <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()));
        }
示例#5
0
        /// <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())));
        }
示例#6
0
        /// <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)));
        }
示例#7
0
        /// <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("")));
        }
示例#8
0
        /// <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)));
        }
示例#9
0
        /// <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)));
        }
示例#10
0
        /// <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)));
        }
示例#11
0
        /// <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)));
        }
示例#12
0
        /// <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)));
        }
示例#13
0
        /// <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)));
        }
示例#14
0
        /// <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)));
        }
示例#15
0
        /// <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)));
        }
示例#16
0
        /// <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)));
        }
示例#17
0
        /// <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)));
        }
示例#18
0
        /// <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)));
        }
示例#19
0
        /// <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())));
        }