public void Throws_when_URI_is_empty()
 {
     Should.Throw<ArgumentNullException>(() =>
     {
         var bad = new CanonicalUri(string.Empty);
     });
 }
 public DefaultResourceDataResult(ResourceAction action, Type returnType, CanonicalUri uri, int httpStatus, Map body)
 {
     this.action = action;
     this.type = returnType;
     this.uri = uri;
     this.httpStatus = httpStatus;
     this.body = body;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CanonicalUri"/> class
        /// with the <see cref="resourcePath"/> overridden by the specified <see cref="Uri"/>.
        /// </summary>
        /// <param name="existing">An existing <see cref="CanonicalUri"/> to copy.</param>
        /// <param name="overrideResourcePath">A replacement for <see cref="ResourcePath"/>.</param>
        internal CanonicalUri(CanonicalUri existing, Uri overrideResourcePath)
        {
            this.resourcePath = overrideResourcePath == null
                ? new Uri(existing.ResourcePath.WithoutQueryAndFragment().ToString())
                : overrideResourcePath.WithoutQueryAndFragment();

            this.query = new QueryString(existing.QueryString);
        }
 // Copy constructor
 public DefaultHttpRequest(IHttpRequest existingRequest, Uri overrideUri = null)
 {
     this.body = existingRequest.Body;
     this.bodyContentType = existingRequest.BodyContentType;
     this.headers = new HttpHeaders(existingRequest.Headers);
     this.method = existingRequest.Method.Clone();
     this.canonicalUri = new CanonicalUri(existingRequest.CanonicalUri, overrideResourcePath: overrideUri);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CanonicalUri"/> class
        /// with the <see cref="resourcePath"/> overridden by the specified <see cref="Uri"/>.
        /// </summary>
        /// <param name="existing">An existing <see cref="CanonicalUri"/> to copy.</param>
        /// <param name="overrideResourcePath">A replacement for <see cref="ResourcePath"/>.</param>
        internal CanonicalUri(CanonicalUri existing, Uri overrideResourcePath)
        {
            this.resourcePath = overrideResourcePath == null
                ? new Uri(existing.ResourcePath.WithoutQueryAndFragment().ToString())
                : overrideResourcePath.WithoutQueryAndFragment();

            this.query = new QueryString(existing.QueryString);
        }
 public DefaultResourceDataRequest(ResourceAction action, Type resourceType, CanonicalUri uri, HttpHeaders requestHeaders, Map properties, bool skipCache)
 {
     this.action = action;
     this.uri = uri;
     this.requestHeaders = requestHeaders;
     this.resourceType = resourceType;
     this.properties = properties;
     this.skipCache = skipCache;
 }
        public void Throws_when_URI_is_not_fully_qualified()
        {
            var notFullyQualified = "/path/to/resource";

            Should.Throw<ArgumentException>(() =>
            {
                var bad = new CanonicalUri(notFullyQualified);
            });

            Should.Throw<ArgumentException>(() =>
            {
                var bad = new CanonicalUri(notFullyQualified, new QueryString("foo=bar&baz=123"));
            });
        }
        public DefaultHttpRequest(HttpMethod method, CanonicalUri canonicalUri, QueryString queryParams, HttpHeaders headers, string body, string bodyContentType)
        {
            this.method = method;
            this.canonicalUri = canonicalUri;

            bool queryParamsWerePassed = queryParams?.Any() ?? false;
            if (queryParamsWerePassed)
            {
                var mergedQueryString = this.canonicalUri.QueryString.Merge(queryParams);
                this.canonicalUri = new CanonicalUri(this.canonicalUri.ResourcePath.ToString(), mergedQueryString);
            }

            this.headers = headers;
            if (headers == null)
            {
                this.headers = new HttpHeaders();
            }

            this.body = body;
            this.bodyContentType = bodyContentType;
        }
 public DefaultResourceDataRequest(ResourceAction action, Type resourceType, CanonicalUri uri, bool skipCache)
     : this(action, resourceType, uri, null, null, skipCache)
 {
 }
 public DefaultHttpRequest(HttpMethod method, CanonicalUri canonicalUri)
     : this(method, canonicalUri, null, null, null, null)
 {
 }
 IHttpRequestBuilder IHttpRequestBuilder.WithUri(string uri)
 {
     this.uri = new CanonicalUri(uri);
     return this;
 }
 IHttpRequestBuilder IHttpRequestBuilder.WithUri(Uri uri)
 {
     this.uri = new CanonicalUri(uri.ToString());
     return this;
 }