Skip to content

Commit 1b33dc4

Browse files
committed
Add tests for PerRequestProvider
1 parent 3eb52f8 commit 1b33dc4

22 files changed

+265
-93
lines changed

src/Microsoft.Graph.Core/Extensions/BaseRequestExtensions.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public static class BaseRequestExtensions
2323
/// <returns></returns>
2424
internal static T WithDefaultAuthProvider<T>(this T baseRequest) where T : IBaseRequest
2525
{
26-
string authOptionKey = typeof(AuthOption).ToString();
26+
string authOptionKey = typeof(AuthenticationHandlerOption).ToString();
2727
if (baseRequest.MiddlewareOptions.ContainsKey(authOptionKey))
2828
{
29-
(baseRequest.MiddlewareOptions[authOptionKey] as AuthOption).AuthenticationProvider = baseRequest.Client.AuthenticationProvider;
29+
(baseRequest.MiddlewareOptions[authOptionKey] as AuthenticationHandlerOption).AuthenticationProvider = baseRequest.Client.AuthenticationProvider;
3030
}
3131
else
3232
{
33-
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthOption { AuthenticationProvider = baseRequest.Client.AuthenticationProvider });
33+
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthenticationHandlerOption { AuthenticationProvider = baseRequest.Client.AuthenticationProvider });
3434
}
3535
return baseRequest;
3636
}
@@ -48,14 +48,14 @@ public static T WithPerRequestAuthProvider<T>(this T baseRequest) where T : IBas
4848
{
4949
if (baseRequest.Client.PerRequestAuthProvider != null)
5050
{
51-
string authOptionKey = typeof(AuthOption).ToString();
51+
string authOptionKey = typeof(AuthenticationHandlerOption).ToString();
5252
if (baseRequest.MiddlewareOptions.ContainsKey(authOptionKey))
5353
{
54-
(baseRequest.MiddlewareOptions[authOptionKey] as AuthOption).AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider();
54+
(baseRequest.MiddlewareOptions[authOptionKey] as AuthenticationHandlerOption).AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider();
5555
}
5656
else
5757
{
58-
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthOption { AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider() });
58+
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthenticationHandlerOption { AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider() });
5959
}
6060
}
6161
return baseRequest;
@@ -72,14 +72,14 @@ public static T WithPerRequestAuthProvider<T>(this T baseRequest) where T : IBas
7272
/// <returns></returns>
7373
public static T WithShouldRetry<T>(this T baseRequest, Func<HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
7474
{
75-
string retryOptionKey = typeof(RetryOption).ToString();
75+
string retryOptionKey = typeof(RetryHandlerOption).ToString();
7676
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
7777
{
78-
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryOption).ShouldRetry = shouldRetry;
78+
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryHandlerOption).ShouldRetry = shouldRetry;
7979
}
8080
else
8181
{
82-
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryOption { ShouldRetry = shouldRetry });
82+
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryHandlerOption { ShouldRetry = shouldRetry });
8383
}
8484
return baseRequest;
8585
}
@@ -95,14 +95,14 @@ public static T WithShouldRetry<T>(this T baseRequest, Func<HttpResponseMessage,
9595
/// <returns></returns>
9696
public static T WithMaxRetry<T>(this T baseRequest, int maxRetry) where T : IBaseRequest
9797
{
98-
string retryOptionKey = typeof(RetryOption).ToString();
98+
string retryOptionKey = typeof(RetryHandlerOption).ToString();
9999
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
100100
{
101-
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryOption).MaxRetry = maxRetry;
101+
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryHandlerOption).MaxRetry = maxRetry;
102102
}
103103
else
104104
{
105-
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryOption { MaxRetry = maxRetry });
105+
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryHandlerOption { MaxRetry = maxRetry });
106106
}
107107
return baseRequest;
108108
}
@@ -118,14 +118,14 @@ public static T WithMaxRetry<T>(this T baseRequest, int maxRetry) where T : IBas
118118
/// <returns></returns>
119119
public static T WithMaxRedirects<T>(this T baseRequest, int maxRedirects) where T : IBaseRequest
120120
{
121-
string redirectOptionKey = typeof(RedirectOption).ToString();
121+
string redirectOptionKey = typeof(RedirectHandlerOption).ToString();
122122
if (baseRequest.MiddlewareOptions.ContainsKey(redirectOptionKey))
123123
{
124-
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectOption).MaxRedirects = maxRedirects;
124+
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirects = maxRedirects;
125125
}
126126
else
127127
{
128-
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectOption { MaxRedirects = maxRedirects });
128+
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirects = maxRedirects });
129129
}
130130
return baseRequest;
131131
}

src/Microsoft.Graph.Core/Requests/Handlers/AuthenticationHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class AuthenticationHandler: DelegatingHandler
2121
/// <summary>
2222
/// AuthOption property
2323
/// </summary>
24-
internal AuthOption AuthOption { get; set; }
24+
internal AuthenticationHandlerOption AuthOption { get; set; }
2525

2626
/// <summary>
2727
/// AuthenticationProvider property
@@ -32,20 +32,20 @@ public class AuthenticationHandler: DelegatingHandler
3232
/// Construct a new <see cref="AuthenticationHandler"/>
3333
/// <param name="authenticationProvider">An authentication provider to pass to <see cref="AuthenticationHandler"/> for authenticating requests.</param>
3434
/// </summary>
35-
/// <param name="authOption">An OPTIONAL <see cref="Microsoft.Graph.AuthOption"/> to configure <see cref="AuthenticationHandler"/></param>
36-
public AuthenticationHandler(IAuthenticationProvider authenticationProvider, AuthOption authOption = null)
35+
/// <param name="authOption">An OPTIONAL <see cref="Microsoft.Graph.AuthenticationHandlerOption"/> to configure <see cref="AuthenticationHandler"/></param>
36+
public AuthenticationHandler(IAuthenticationProvider authenticationProvider, AuthenticationHandlerOption authOption = null)
3737
{
3838
AuthenticationProvider = authenticationProvider;
39-
AuthOption = authOption ?? new AuthOption();
39+
AuthOption = authOption ?? new AuthenticationHandlerOption();
4040
}
4141

4242
/// <summary>
4343
/// Construct a new <see cref="AuthenticationHandler"/>
4444
/// </summary>
4545
/// <param name="authenticationProvider">An authentication provider to pass to <see cref="AuthenticationHandler"/> for authenticating requests.</param>
4646
/// <param name="innerHandler">A HTTP message handler to pass to the <see cref="AuthenticationHandler"/> for sending requests.</param>
47-
/// <param name="authOption">An OPTIONAL <see cref="Microsoft.Graph.AuthOption"/> to configure <see cref="AuthenticationHandler"/></param>
48-
public AuthenticationHandler(IAuthenticationProvider authenticationProvider, HttpMessageHandler innerHandler, AuthOption authOption = null)
47+
/// <param name="authOption">An OPTIONAL <see cref="Microsoft.Graph.AuthenticationHandlerOption"/> to configure <see cref="AuthenticationHandler"/></param>
48+
public AuthenticationHandler(IAuthenticationProvider authenticationProvider, HttpMessageHandler innerHandler, AuthenticationHandlerOption authOption = null)
4949
:this(authenticationProvider, authOption)
5050
{
5151
InnerHandler = innerHandler;
@@ -101,7 +101,7 @@ private async Task<HttpResponseMessage> SendRetryAsync(HttpResponseMessage httpR
101101
/// <returns></returns>
102102
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
103103
{
104-
AuthOption = httpRequestMessage.GetMiddlewareOption<AuthOption>() ?? AuthOption;
104+
AuthOption = httpRequestMessage.GetMiddlewareOption<AuthenticationHandlerOption>() ?? AuthOption;
105105

106106
// If default auth provider is not set, use the option
107107
var authProvider = AuthOption.AuthenticationProvider ?? AuthenticationProvider;

src/Microsoft.Graph.Core/Requests/Handlers/RedirectHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ public class RedirectHandler : DelegatingHandler
1818
/// <summary>
1919
/// RedirectOption property
2020
/// </summary>
21-
internal RedirectOption RedirectOption { get; set; }
21+
internal RedirectHandlerOption RedirectOption { get; set; }
2222

2323
/// <summary>
2424
/// Constructs a new <see cref="RedirectHandler"/>
2525
/// </summary>
26-
/// <param name="redirectOption">An OPTIONAL <see cref="Microsoft.Graph.RedirectOption"/> to configure <see cref="RedirectHandler"/></param>
27-
public RedirectHandler(RedirectOption redirectOption = null)
26+
/// <param name="redirectOption">An OPTIONAL <see cref="Microsoft.Graph.RedirectHandlerOption"/> to configure <see cref="RedirectHandler"/></param>
27+
public RedirectHandler(RedirectHandlerOption redirectOption = null)
2828
{
29-
RedirectOption = redirectOption ?? new RedirectOption();
29+
RedirectOption = redirectOption ?? new RedirectHandlerOption();
3030
}
3131

3232
/// <summary>
3333
/// Constructs a new <see cref="RedirectHandler"/>
3434
/// </summary>
3535
/// <param name="innerHandler">An HTTP message handler to pass to the <see cref="HttpMessageHandler"/> for sending requests.</param>
36-
/// <param name="redirectOption">An OPTIONAL <see cref="Microsoft.Graph.RedirectOption"/> to configure <see cref="RedirectHandler"/></param>
37-
public RedirectHandler(HttpMessageHandler innerHandler, RedirectOption redirectOption = null)
36+
/// <param name="redirectOption">An OPTIONAL <see cref="Microsoft.Graph.RedirectHandlerOption"/> to configure <see cref="RedirectHandler"/></param>
37+
public RedirectHandler(HttpMessageHandler innerHandler, RedirectHandlerOption redirectOption = null)
3838
:this(redirectOption)
3939
{
4040
InnerHandler = innerHandler;
@@ -48,7 +48,7 @@ public RedirectHandler(HttpMessageHandler innerHandler, RedirectOption redirectO
4848
/// <returns>The <see cref="HttpResponseMessage"/>.</returns>
4949
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
5050
{
51-
RedirectOption = request.GetMiddlewareOption<RedirectOption>() ?? RedirectOption;
51+
RedirectOption = request.GetMiddlewareOption<RedirectHandlerOption>() ?? RedirectOption;
5252

5353
// send request first time to get response
5454
var response = await base.SendAsync(request, cancellationToken);

src/Microsoft.Graph.Core/Requests/Handlers/RetryHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ public class RetryHandler : DelegatingHandler
2626
/// <summary>
2727
/// RetryOption property
2828
/// </summary>
29-
internal RetryOption RetryOption { get; set; }
29+
internal RetryHandlerOption RetryOption { get; set; }
3030

3131
/// <summary>
3232
/// Construct a new <see cref="RetryHandler"/>
3333
/// </summary>
34-
/// <param name="retryOption">An OPTIONAL <see cref="Microsoft.Graph.RetryOption"/> to configure <see cref="RetryHandler"/></param>
35-
public RetryHandler(RetryOption retryOption = null)
34+
/// <param name="retryOption">An OPTIONAL <see cref="Microsoft.Graph.RetryHandlerOption"/> to configure <see cref="RetryHandler"/></param>
35+
public RetryHandler(RetryHandlerOption retryOption = null)
3636
{
37-
RetryOption = retryOption ?? new RetryOption();
37+
RetryOption = retryOption ?? new RetryHandlerOption();
3838
}
3939

4040
/// <summary>
4141
/// Construct a new <see cref="RetryHandler"/>
4242
/// </summary>
4343
/// <param name="innerHandler">An HTTP message handler to pass to the <see cref="HttpMessageHandler"/> for sending requests.</param>
44-
/// <param name="retryOption">An OPTIONAL <see cref="Microsoft.Graph.RetryOption"/> to configure <see cref="RetryHandler"/></param>
45-
public RetryHandler(HttpMessageHandler innerHandler, RetryOption retryOption = null)
44+
/// <param name="retryOption">An OPTIONAL <see cref="Microsoft.Graph.RetryHandlerOption"/> to configure <see cref="RetryHandler"/></param>
45+
public RetryHandler(HttpMessageHandler innerHandler, RetryHandlerOption retryOption = null)
4646
:this(retryOption)
4747
{
4848
InnerHandler = innerHandler;
@@ -56,7 +56,7 @@ public RetryHandler(HttpMessageHandler innerHandler, RetryOption retryOption = n
5656
/// <returns></returns>
5757
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken)
5858
{
59-
RetryOption = httpRequest.GetMiddlewareOption<RetryOption>() ?? RetryOption;
59+
RetryOption = httpRequest.GetMiddlewareOption<RetryHandlerOption>() ?? RetryOption;
6060

6161
var response = await base.SendAsync(httpRequest, cancellationToken);
6262

src/Microsoft.Graph.Core/Requests/MiddlewareOptions/AuthOption.cs renamed to src/Microsoft.Graph.Core/Requests/MiddlewareOptions/AuthenticationHandlerOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.Graph
77
/// <summary>
88
/// The auth middleware option class
99
/// </summary>
10-
public class AuthOption : IMiddlewareOption
10+
public class AuthenticationHandlerOption : IMiddlewareOption
1111
{
1212
/// <summary>
1313
/// An Authentication Provider

src/Microsoft.Graph.Core/Requests/MiddlewareOptions/RedirectOption.cs renamed to src/Microsoft.Graph.Core/Requests/MiddlewareOptions/RedirectHandlerOption.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace Microsoft.Graph
77
/// <summary>
88
/// The redirect middleware option class
99
/// </summary>
10-
public class RedirectOption : IMiddlewareOption
10+
public class RedirectHandlerOption : IMiddlewareOption
1111
{
1212
/// <summary>
13-
/// Constructs a new <see cref="RedirectOption"/>
13+
/// Constructs a new <see cref="RedirectHandlerOption"/>
1414
/// </summary>
15-
public RedirectOption()
15+
public RedirectHandlerOption()
1616
{
1717

1818
}

src/Microsoft.Graph.Core/Requests/MiddlewareOptions/RetryOption.cs renamed to src/Microsoft.Graph.Core/Requests/MiddlewareOptions/RetryHandlerOption.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace Microsoft.Graph
1111
/// <summary>
1212
/// The retry middleware option class
1313
/// </summary>
14-
public class RetryOption : IMiddlewareOption
14+
public class RetryHandlerOption : IMiddlewareOption
1515
{
1616
/// <summary>
17-
/// Constructs a new <see cref="RetryOption"/>
17+
/// Constructs a new <see cref="RetryHandlerOption"/>
1818
/// </summary>
19-
public RetryOption()
19+
public RetryHandlerOption()
2020
{
2121
ShouldRetry = (response) => IsRetry(response);
2222
}

0 commit comments

Comments
 (0)