/// <summary>
 /// Sets the object to use as the response content.
 /// </summary>
 /// <param name="builder">The <see cref="HttpRequestInterceptionBuilder"/> to use.</param>
 /// <param name="content">The object to serialize as JSON as the content.</param>
 /// <returns>
 /// The value specified by <paramref name="builder"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="builder"/> or <paramref name="content"/> is <see langword="null"/>.
 /// </exception>
 public static HttpRequestInterceptionBuilder WithJsonContent(
     this HttpRequestInterceptionBuilder builder,
     object content)
 {
     return(builder.WithNewtonsoftJsonContent(content));
 }
 /// <summary>
 /// A convenience method that can be used to signify the start of response method calls for fluent registrations.
 /// </summary>
 /// <param name="builder">The <see cref="HttpRequestInterceptionBuilder"/> to use.</param>
 /// <returns>
 /// The value specified by <paramref name="builder"/>.
 /// </returns>
 public static HttpRequestInterceptionBuilder Responds(this HttpRequestInterceptionBuilder builder) => builder;
Esempio n. 3
0
        public static HttpRequestInterceptionBuilder FromItem(
            BundleItem item,
            IEnumerable <KeyValuePair <string, string> > templateValues)
        {
            // Override the template values in the JSON with any user-specified values
            if (item.TemplateValues?.Count > 0)
            {
                foreach (var pair in templateValues)
                {
                    item.TemplateValues[pair.Key] = pair.Value;
                }
            }

            ValidateItem(item, out Uri uri, out Version? version);

            var builder = new HttpRequestInterceptionBuilder().ForUri(uri);

            if (item.Method != null)
            {
                builder.ForMethod(new System.Net.Http.HttpMethod(item.Method));
            }

            if (item.RequestHeaders?.Count > 0)
            {
                builder.ForRequestHeaders(TemplateHeaders(item.RequestHeaders, item.TemplateValues));
            }

            if (version != null)
            {
                builder.WithVersion(version);
            }

            if (!string.IsNullOrEmpty(item.Status))
            {
                if (!Enum.TryParse(item.Status, true, out HttpStatusCode httpStatusCode))
                {
                    throw new InvalidOperationException($"Bundle item with Id '{item.Id}' has an invalid HTTP status code '{item.Status}' configured.");
                }

                builder.WithStatus(httpStatusCode);
            }

            if (item.ResponseHeaders?.Count > 0)
            {
                builder.WithResponseHeaders(TemplateHeaders(item.ResponseHeaders, item.TemplateValues));
            }

            if (item.ContentHeaders?.Count > 0)
            {
                builder.WithContentHeaders(TemplateHeaders(item.ContentHeaders, item.TemplateValues));
            }

            if (item.Priority.HasValue)
            {
                builder.HavingPriority(item.Priority.Value);
            }

            if (item.IgnorePath)
            {
                builder.IgnoringPath(ignorePath: true);
            }

            if (item.IgnoreQuery)
            {
                builder.IgnoringQuery(ignoreQuery: true);
            }

            return(builder.SetContent(item));
        }