File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
src/Microsoft.Extensions.ServiceDiscovery.Yarp
tests/Microsoft.Extensions.ServiceDiscovery.Yarp.Tests Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public static class ServiceDiscoveryReverseProxyServiceCollectionExtensions
1717 /// </summary>
1818 public static IReverseProxyBuilder AddServiceDiscoveryDestinationResolver ( this IReverseProxyBuilder builder )
1919 {
20+ ArgumentNullException . ThrowIfNull ( builder ) ;
21+
2022 builder . Services . AddServiceDiscoveryCore ( ) ;
2123 builder . Services . AddSingleton < IDestinationResolver , ServiceDiscoveryDestinationResolver > ( ) ;
2224 return builder ;
@@ -27,6 +29,8 @@ public static IReverseProxyBuilder AddServiceDiscoveryDestinationResolver(this I
2729 /// </summary>
2830 public static IServiceCollection AddHttpForwarderWithServiceDiscovery ( this IServiceCollection services )
2931 {
32+ ArgumentNullException . ThrowIfNull ( services ) ;
33+
3034 return services . AddHttpForwarder ( ) . AddServiceDiscoveryForwarderFactory ( ) ;
3135 }
3236
@@ -35,6 +39,8 @@ public static IServiceCollection AddHttpForwarderWithServiceDiscovery(this IServ
3539 /// </summary>
3640 public static IServiceCollection AddServiceDiscoveryForwarderFactory ( this IServiceCollection services )
3741 {
42+ ArgumentNullException . ThrowIfNull ( services ) ;
43+
3844 services . AddServiceDiscoveryCore ( ) ;
3945 services . AddSingleton < IForwarderHttpClientFactory , ServiceDiscoveryForwarderHttpClientFactory > ( ) ;
4046 return services ;
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using Microsoft . Extensions . DependencyInjection ;
5+ using Xunit ;
6+
7+ namespace Microsoft . Extensions . ServiceDiscovery . Yarp . Tests ;
8+
9+ #pragma warning disable IDE0200
10+
11+ public class YarpServiceDiscoveryPublicApiTests
12+ {
13+ [ Fact ]
14+ public void AddServiceDiscoveryDestinationResolverShouldThrowWhenBuilderIsNull ( )
15+ {
16+ IReverseProxyBuilder builder = null ! ;
17+
18+ var action = ( ) => builder . AddServiceDiscoveryDestinationResolver ( ) ;
19+
20+ var exception = Assert . Throws < ArgumentNullException > ( action ) ;
21+ Assert . Equal ( nameof ( builder ) , exception . ParamName ) ;
22+ }
23+
24+ [ Fact ]
25+ public void AddHttpForwarderWithServiceDiscoveryShouldThrowWhenServicesIsNull ( )
26+ {
27+ IServiceCollection services = null ! ;
28+
29+ var action = ( ) => services . AddHttpForwarderWithServiceDiscovery ( ) ;
30+
31+ var exception = Assert . Throws < ArgumentNullException > ( action ) ;
32+ Assert . Equal ( nameof ( services ) , exception . ParamName ) ;
33+ }
34+
35+ [ Fact ]
36+ public void AddServiceDiscoveryForwarderFactoryShouldThrowWhenServicesIsNull ( )
37+ {
38+ IServiceCollection services = null ! ;
39+
40+ var action = ( ) => services . AddServiceDiscoveryForwarderFactory ( ) ;
41+
42+ var exception = Assert . Throws < ArgumentNullException > ( action ) ;
43+ Assert . Equal ( nameof ( services ) , exception . ParamName ) ;
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments