@@ -787,5 +787,69 @@ public async Task HttpTesterMultipleHeadersAlreadyExist_Success()
787787 Assert . True ( client . GetRequestHeaders ( ) . Count == 1 ) ;
788788 }
789789 }
790+
791+ [ Fact ]
792+ public async Task HttpAgentHeaders_Success ( )
793+ {
794+ using ( var client = new HttpTesterClient ( ) )
795+ {
796+ client
797+ . CreateHttpRequest ( new Uri ( "http://swagger-demo.qatoolkit.io/" ) , true )
798+ . WithQueryParams ( new Dictionary < string , string > ( ) { { "api-version" , "1" } } )
799+ . WithMethod ( HttpMethod . Get )
800+ . WithHttpAgent ( "testapp" , "1.0" , "https://myapp.com" )
801+ . WithPath ( "/api/bicycles/1" ) ;
802+
803+ Assert . True ( client . HttpClient . DefaultRequestHeaders . Count ( ) == 1 ) ;
804+ }
805+ }
806+
807+ [ Theory ]
808+ [ InlineData ( "" ) ]
809+ public async Task HttpAgentHeadersNameNull_Fails ( string name )
810+ {
811+ using ( var client = new HttpTesterClient ( ) )
812+ {
813+ client
814+ . CreateHttpRequest ( new Uri ( "http://swagger-demo.qatoolkit.io/" ) , true )
815+ . WithQueryParams ( new Dictionary < string , string > ( ) { { "api-version" , "1" } } )
816+ . WithMethod ( HttpMethod . Get )
817+ . WithPath ( "/api/bicycles/1" ) ;
818+
819+ Assert . Throws < ArgumentNullException > ( ( ) => client . WithHttpAgent ( name , "1.0" , "https://myapp.com" ) ) ;
820+ }
821+ }
822+
823+ [ Theory ]
824+ [ InlineData ( "" ) ]
825+ public async Task HttpAgentHeadersVersionNull_Fails ( string version )
826+ {
827+ using ( var client = new HttpTesterClient ( ) )
828+ {
829+ client
830+ . CreateHttpRequest ( new Uri ( "http://swagger-demo.qatoolkit.io/" ) , true )
831+ . WithQueryParams ( new Dictionary < string , string > ( ) { { "api-version" , "1" } } )
832+ . WithMethod ( HttpMethod . Get )
833+ . WithPath ( "/api/bicycles/1" ) ;
834+
835+ Assert . Throws < ArgumentNullException > ( ( ) => client . WithHttpAgent ( "testapp" , version , "https://myapp.com" ) ) ;
836+ }
837+ }
838+
839+ [ Theory ]
840+ [ InlineData ( "" ) ]
841+ public async Task HttpAgentHeadersUrlNull_Fails ( string url )
842+ {
843+ using ( var client = new HttpTesterClient ( ) )
844+ {
845+ client
846+ . CreateHttpRequest ( new Uri ( "http://swagger-demo.qatoolkit.io/" ) , true )
847+ . WithQueryParams ( new Dictionary < string , string > ( ) { { "api-version" , "1" } } )
848+ . WithMethod ( HttpMethod . Get )
849+ . WithPath ( "/api/bicycles/1" ) ;
850+
851+ Assert . Throws < ArgumentNullException > ( ( ) => client . WithHttpAgent ( "testapp" , "1.0" , url ) ) ;
852+ }
853+ }
790854 }
791855}
0 commit comments