-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw an exception in ConfigureHttpClient when custom IForwarderHttpC…
…lientFactory is already present (#1805)
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/ReverseProxy.Tests/Forwarder/ReverseProxyServiceCollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Net.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Yarp.ReverseProxy.Forwarder; | ||
|
||
public class ReverseProxyServiceCollectionTests | ||
{ | ||
|
||
[Fact] | ||
public void ConfigureHttpClient_Works() | ||
{ | ||
new ServiceCollection() | ||
.AddReverseProxy() | ||
.ConfigureHttpClient((_, _) => { }); | ||
} | ||
|
||
[Fact] | ||
public void ConfigureHttpClient_ThrowIfCustomServiceAdded() | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
new ServiceCollection() | ||
.AddSingleton<IForwarderHttpClientFactory, CustomForwarderHttpClientFactory>() | ||
.AddReverseProxy() | ||
.ConfigureHttpClient((_, _) => { }); | ||
}); | ||
} | ||
|
||
private class CustomForwarderHttpClientFactory : IForwarderHttpClientFactory | ||
{ | ||
public HttpMessageInvoker CreateClient(ForwarderHttpClientContext context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |