This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
WebApplicationFactoryClientOptions.cs
83 lines (74 loc) · 3.33 KB
/
WebApplicationFactoryClientOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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
{
/// <summary>
/// The default options to use to when creating
/// <see cref="HttpClient"/> instances by calling
/// <see cref="WebApplicationFactory{TEntryPoint}.CreateClient(WebApplicationFactoryClientOptions)"/>.
/// </summary>
public class WebApplicationFactoryClientOptions
{
/// <summary>
/// Initializes a new instance of <see cref="WebApplicationFactoryClientOptions"/>.
/// </summary>
public WebApplicationFactoryClientOptions()
{
}
// Copy constructor
internal WebApplicationFactoryClientOptions(WebApplicationFactoryClientOptions clientOptions)
{
BaseAddress = clientOptions.BaseAddress;
AllowAutoRedirect = clientOptions.AllowAutoRedirect;
MaxAutomaticRedirections = clientOptions.MaxAutomaticRedirections;
HandleCookies = clientOptions.HandleCookies;
}
/// <summary>
/// Gets or sets the base address of <see cref="HttpClient"/> instances created by calling
/// <see cref="WebApplicationFactory{TEntryPoint}.CreateClient(WebApplicationFactoryClientOptions)"/>.
/// The default is <c>http://localhost</c>.
/// </summary>
public Uri BaseAddress { get; set; } = new Uri("http://localhost");
/// <summary>
/// Gets or sets whether or not <see cref="HttpClient"/> instances created by calling
/// <see cref="WebApplicationFactory{TEntryPoint}.CreateClient(WebApplicationFactoryClientOptions)"/>
/// should automatically follow redirect responses.
/// The default is <c>true</c>.
/// /// </summary>
public bool AllowAutoRedirect { get; set; } = true;
/// <summary>
/// Gets or sets the maximum number of redirect responses that <see cref="HttpClient"/> instances
/// created by calling <see cref="WebApplicationFactory{TEntryPoint}.CreateClient(WebApplicationFactoryClientOptions)"/>
/// should follow.
/// The default is <c>7</c>.
/// </summary>
public int MaxAutomaticRedirections { get; set; } = RedirectHandler.DefaultMaxRedirects;
/// <summary>
/// Gets or sets whether <see cref="HttpClient"/> instances created by calling
/// <see cref="WebApplicationFactory{TEntryPoint}.CreateClient(WebApplicationFactoryClientOptions)"/>
/// should handle cookies.
/// The default is <c>true</c>.
/// </summary>
public bool HandleCookies { get; set; } = true;
internal DelegatingHandler[] CreateHandlers()
{
return CreateHandlersCore().ToArray();
IEnumerable<DelegatingHandler> CreateHandlersCore()
{
if (AllowAutoRedirect)
{
yield return new RedirectHandler(MaxAutomaticRedirections);
}
if (HandleCookies)
{
yield return new CookieContainerHandler();
}
}
}
}
}