@@ -1067,6 +1067,54 @@ public static async Task Using_The_Same_Builder_For_Multiple_Registrations_On_Th
10671067 await HttpAssert . GetAsync ( options , "https://api.github.com:443/orgs/justeat" ) ;
10681068 }
10691069
1070+ [ Fact ]
1071+ public static async Task Using_The_Same_Builder_For_Multiple_Registrations_With_Custom_Ports ( )
1072+ {
1073+ // Arrange
1074+ var options = new HttpClientInterceptorOptions ( )
1075+ {
1076+ ThrowOnMissingRegistration = true
1077+ } ;
1078+
1079+ var builder = new HttpRequestInterceptionBuilder ( )
1080+ . ForPort ( 123 )
1081+ . ForHttps ( )
1082+ . ForHost ( "api.github.com" )
1083+ . ForPath ( "orgs/justeat" )
1084+ . RegisterWith ( options ) ;
1085+
1086+ // Change to a different scheme without changing the port
1087+ builder = builder
1088+ . ForHttp ( )
1089+ . RegisterWith ( options ) ;
1090+
1091+ // Change the port and not the scheme
1092+ builder = builder
1093+ . ForPort ( 456 )
1094+ . RegisterWith ( options ) ;
1095+
1096+ // Change the scheme and use an explicit port
1097+ builder = builder
1098+ . ForHttps ( )
1099+ . ForPort ( 443 )
1100+ . RegisterWith ( options ) ;
1101+
1102+ // Restore default scheme and port
1103+ builder = builder
1104+ . ForHttp ( )
1105+ . ForPort ( - 1 )
1106+ . RegisterWith ( options ) ;
1107+
1108+ // Act and Assert
1109+ await HttpAssert . GetAsync ( options , "https://api.github.com:123/orgs/justeat" ) ;
1110+ await HttpAssert . GetAsync ( options , "http://api.github.com:123/orgs/justeat" ) ;
1111+ await HttpAssert . GetAsync ( options , "http://api.github.com:456/orgs/justeat" ) ;
1112+ await HttpAssert . GetAsync ( options , "https://api.github.com/orgs/justeat" ) ;
1113+ await HttpAssert . GetAsync ( options , "https://api.github.com:443/orgs/justeat" ) ;
1114+ await HttpAssert . GetAsync ( options , "http://api.github.com/orgs/justeat" ) ;
1115+ await HttpAssert . GetAsync ( options , "http://api.github.com:80/orgs/justeat" ) ;
1116+ }
1117+
10701118 private sealed class CustomObject
10711119 {
10721120 internal enum Color
0 commit comments