/// <summary>
        /// Determines whether the request matches the url.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="urlQuery">The url query.</param>
        /// <returns>
        ///   <c>true</c> if the requset uses the specified url; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// request
        /// or
        /// urlQuery
        /// </exception>
        public static bool HasUrl(this HttpRequestMessage request, UrlQuery urlQuery)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (urlQuery == null)
            {
                throw new ArgumentNullException(nameof(urlQuery));
            }

            return(urlQuery.Match(request.RequestUri));
        }
Пример #2
0
        /// <summary>
        /// Creates a rule that is run when the request url matches the specified url.
        /// </summary>
        /// <param name="self">The IWhenable.</param>
        /// <param name="url">The url query in the format accpeted by <see cref="UrlQuery"/>.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// self
        /// or
        /// url
        /// </exception>
        /// <exception cref="Exceptions.InvalidUrlQueryException">The url is not a valid format for <see cref="UrlQuery"/>.</exception>
        public static IThenable When(this IWhenable self, string url)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            //generate the urlQuery here so we can throw if they give an invalid string
            var urlQuery = new UrlQuery(url);

            return(self.When(x => x.HasUrl(urlQuery)));
        }