// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Microsoft.AspNetCore.Mvc.Testing.Handlers; namespace Microsoft.AspNetCore.Mvc.Testing { /// /// The default options to use to when creating /// instances by calling /// . /// public class WebApplicationFactoryClientOptions { /// /// Initializes a new instance of . /// public WebApplicationFactoryClientOptions() { } // Copy constructor internal WebApplicationFactoryClientOptions(WebApplicationFactoryClientOptions clientOptions) { BaseAddress = clientOptions.BaseAddress; AllowAutoRedirect = clientOptions.AllowAutoRedirect; MaxAutomaticRedirections = clientOptions.MaxAutomaticRedirections; HandleCookies = clientOptions.HandleCookies; } /// /// Gets or sets the base address of instances created by calling /// . /// The default is http://localhost. /// public Uri BaseAddress { get; set; } = new Uri("http://localhost"); /// /// Gets or sets whether or not instances created by calling /// /// should automatically follow redirect responses. /// The default is true. /// /// public bool AllowAutoRedirect { get; set; } = true; /// /// Gets or sets the maximum number of redirect responses that instances /// created by calling /// should follow. /// The default is 7. /// public int MaxAutomaticRedirections { get; set; } = RedirectHandler.DefaultMaxRedirects; /// /// Gets or sets whether instances created by calling /// /// should handle cookies. /// The default is true. /// public bool HandleCookies { get; set; } = true; internal DelegatingHandler[] CreateHandlers() { return CreateHandlersCore().ToArray(); IEnumerable CreateHandlersCore() { if (AllowAutoRedirect) { yield return new RedirectHandler(MaxAutomaticRedirections); } if (HandleCookies) { yield return new CookieContainerHandler(); } } } } }