@@ -72,7 +72,7 @@ public void Given_Info_When_AddMetadata_Invoked_Then_It_Should_Return_Result(str
7272 [ DataRow ( "https" , "localhost" , 47071 , null ) ]
7373 [ DataRow ( "https" , "localhost" , 47071 , "" ) ]
7474 [ DataRow ( "https" , "localhost" , 47071 , "api" ) ]
75- public void Given_NoOptions_When_AddMetadata_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix )
75+ public void Given_NoOptions_When_AddServer_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix )
7676 {
7777 var helper = new Mock < IDocumentHelper > ( ) ;
7878 var doc = new Document ( helper . Object ) ;
@@ -104,7 +104,7 @@ public void Given_NoOptions_When_AddMetadata_Invoked_Then_It_Should_Return_Resul
104104 [ DataRow ( "https" , "localhost" , 47071 , null ) ]
105105 [ DataRow ( "https" , "localhost" , 47071 , "" ) ]
106106 [ DataRow ( "https" , "localhost" , 47071 , "api" ) ]
107- public void Given_EmptyOptions_When_AddMetadata_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix )
107+ public void Given_EmptyOptions_When_AddServer_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix )
108108 {
109109 var helper = new Mock < IDocumentHelper > ( ) ;
110110 var doc = new Document ( helper . Object ) ;
@@ -139,7 +139,7 @@ public void Given_EmptyOptions_When_AddMetadata_Invoked_Then_It_Should_Return_Re
139139 [ DataRow ( "https" , "localhost" , 47071 , null , "helloworld" ) ]
140140 [ DataRow ( "https" , "localhost" , 47071 , "" , "helloworld" ) ]
141141 [ DataRow ( "https" , "localhost" , 47071 , "api" , "helloworld" ) ]
142- public void Given_ExtraServers_And_Include_When_AddMetadata_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix , string server )
142+ public void Given_ExtraServers_And_Include_When_AddServer_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix , string server )
143143 {
144144 var helper = new Mock < IDocumentHelper > ( ) ;
145145 var doc = new Document ( helper . Object ) ;
@@ -177,7 +177,7 @@ public void Given_ExtraServers_And_Include_When_AddMetadata_Invoked_Then_It_Shou
177177 [ DataRow ( "https" , "localhost" , 47071 , null , "helloworld" ) ]
178178 [ DataRow ( "https" , "localhost" , 47071 , "" , "helloworld" ) ]
179179 [ DataRow ( "https" , "localhost" , 47071 , "api" , "helloworld" ) ]
180- public void Given_ExtraServers_And_Exclude_When_AddMetadata_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix , string server )
180+ public void Given_ExtraServers_And_Exclude_When_AddServer_Invoked_Then_It_Should_Return_Result ( string scheme , string host , int port , string routePrefix , string server )
181181 {
182182 var helper = new Mock < IDocumentHelper > ( ) ;
183183 var doc = new Document ( helper . Object ) ;
@@ -201,6 +201,109 @@ public void Given_ExtraServers_And_Exclude_When_AddMetadata_Invoked_Then_It_Shou
201201 result . OpenApiDocument . Servers . First ( ) . Url . Should ( ) . Be ( server ) ;
202202 }
203203
204+ [ DataTestMethod ]
205+ [ DataRow ( "http" , "localhost" , "api" , "http://localhost/api" ) ]
206+ [ DataRow ( "https" , "localhost" , "api" , "https://localhost/api" ) ]
207+ [ DataRow ( "http" , "localhost:7071" , "api" , "http://localhost:7071/api" ) ]
208+ [ DataRow ( "https" , "localhost:47071" , "api" , "https://localhost:47071/api" ) ]
209+ [ DataRow ( "http" , "localhost" , "" , "http://localhost" ) ]
210+ [ DataRow ( "https" , "localhost" , "" , "https://localhost" ) ]
211+ [ DataRow ( "http" , "localhost:7071" , "" , "http://localhost:7071" ) ]
212+ [ DataRow ( "https" , "localhost:47071" , "" , "https://localhost:47071" ) ]
213+ [ DataRow ( "http" , "localhost" , null , "http://localhost" ) ]
214+ [ DataRow ( "https" , "localhost" , null , "https://localhost" ) ]
215+ [ DataRow ( "http" , "localhost:7071" , null , "http://localhost:7071" ) ]
216+ [ DataRow ( "https" , "localhost:47071" , null , "https://localhost:47071" ) ]
217+ public void Given_NullOptions_When_AddServer_Invoked_Then_It_Should_Return_BaseUrl ( string scheme , string host , string routePrefix , string expected )
218+ {
219+ var helper = new Mock < IDocumentHelper > ( ) ;
220+ var doc = new Document ( helper . Object ) ;
221+
222+ var req = new Mock < IHttpRequestDataObject > ( ) ;
223+ req . SetupGet ( p => p . Scheme ) . Returns ( scheme ) ;
224+
225+ var hostString = new HostString ( host ) ;
226+ req . SetupGet ( p => p . Host ) . Returns ( hostString ) ;
227+
228+ var result = doc . InitialiseDocument ( )
229+ . AddServer ( req . Object , routePrefix , null ) ;
230+
231+ result . OpenApiDocument . Servers . Should ( ) . HaveCount ( 1 ) ;
232+ result . OpenApiDocument . Servers . First ( ) . Url . Should ( ) . Be ( expected ) ;
233+ }
234+
235+ [ DataTestMethod ]
236+ [ DataRow ( "http" , "localhost" , "api" , true , true , "https://localhost/api" ) ]
237+ [ DataRow ( "https" , "localhost" , "api" , true , true , "https://localhost/api" ) ]
238+ [ DataRow ( "http" , "localhost:7071" , "api" , true , true , "https://localhost:7071/api" ) ]
239+ [ DataRow ( "https" , "localhost:47071" , "api" , true , true , "https://localhost:47071/api" ) ]
240+ [ DataRow ( "http" , "localhost" , "" , true , true , "https://localhost" ) ]
241+ [ DataRow ( "https" , "localhost" , "" , true , true , "https://localhost" ) ]
242+ [ DataRow ( "http" , "localhost:7071" , "" , true , true , "https://localhost:7071" ) ]
243+ [ DataRow ( "https" , "localhost:47071" , "" , true , true , "https://localhost:47071" ) ]
244+ [ DataRow ( "http" , "localhost" , null , true , true , "https://localhost" ) ]
245+ [ DataRow ( "https" , "localhost" , null , true , true , "https://localhost" ) ]
246+ [ DataRow ( "http" , "localhost:7071" , null , true , true , "https://localhost:7071" ) ]
247+ [ DataRow ( "https" , "localhost:47071" , null , true , true , "https://localhost:47071" ) ]
248+ [ DataRow ( "http" , "localhost" , "api" , true , false , "https://localhost/api" ) ]
249+ [ DataRow ( "https" , "localhost" , "api" , true , false , "https://localhost/api" ) ]
250+ [ DataRow ( "http" , "localhost:7071" , "api" , true , false , "https://localhost:7071/api" ) ]
251+ [ DataRow ( "https" , "localhost:47071" , "api" , true , false , "https://localhost:47071/api" ) ]
252+ [ DataRow ( "http" , "localhost" , "" , true , false , "https://localhost" ) ]
253+ [ DataRow ( "https" , "localhost" , "" , true , false , "https://localhost" ) ]
254+ [ DataRow ( "http" , "localhost:7071" , "" , true , false , "https://localhost:7071" ) ]
255+ [ DataRow ( "https" , "localhost:47071" , "" , true , false , "https://localhost:47071" ) ]
256+ [ DataRow ( "http" , "localhost" , null , true , false , "https://localhost" ) ]
257+ [ DataRow ( "https" , "localhost" , null , true , false , "https://localhost" ) ]
258+ [ DataRow ( "http" , "localhost:7071" , null , true , false , "https://localhost:7071" ) ]
259+ [ DataRow ( "https" , "localhost:47071" , null , true , false , "https://localhost:47071" ) ]
260+ [ DataRow ( "http" , "localhost" , "api" , false , true , "http://localhost/api" ) ]
261+ [ DataRow ( "https" , "localhost" , "api" , false , true , "http://localhost/api" ) ]
262+ [ DataRow ( "http" , "localhost:7071" , "api" , false , true , "http://localhost:7071/api" ) ]
263+ [ DataRow ( "https" , "localhost:47071" , "api" , false , true , "http://localhost:47071/api" ) ]
264+ [ DataRow ( "http" , "localhost" , "" , false , true , "http://localhost" ) ]
265+ [ DataRow ( "https" , "localhost" , "" , false , true , "http://localhost" ) ]
266+ [ DataRow ( "http" , "localhost:7071" , "" , false , true , "http://localhost:7071" ) ]
267+ [ DataRow ( "https" , "localhost:47071" , "" , false , true , "http://localhost:47071" ) ]
268+ [ DataRow ( "http" , "localhost" , null , false , true , "http://localhost" ) ]
269+ [ DataRow ( "https" , "localhost" , null , false , true , "http://localhost" ) ]
270+ [ DataRow ( "http" , "localhost:7071" , null , false , true , "http://localhost:7071" ) ]
271+ [ DataRow ( "https" , "localhost:47071" , null , false , true , "http://localhost:47071" ) ]
272+ [ DataRow ( "http" , "localhost" , "api" , false , false , "http://localhost/api" ) ]
273+ [ DataRow ( "https" , "localhost" , "api" , false , false , "https://localhost/api" ) ]
274+ [ DataRow ( "http" , "localhost:7071" , "api" , false , false , "http://localhost:7071/api" ) ]
275+ [ DataRow ( "https" , "localhost:47071" , "api" , false , false , "https://localhost:47071/api" ) ]
276+ [ DataRow ( "http" , "localhost" , "" , false , false , "http://localhost" ) ]
277+ [ DataRow ( "https" , "localhost" , "" , false , false , "https://localhost" ) ]
278+ [ DataRow ( "http" , "localhost:7071" , "" , false , false , "http://localhost:7071" ) ]
279+ [ DataRow ( "https" , "localhost:47071" , "" , false , false , "https://localhost:47071" ) ]
280+ [ DataRow ( "http" , "localhost" , null , false , false , "http://localhost" ) ]
281+ [ DataRow ( "https" , "localhost" , null , false , false , "https://localhost" ) ]
282+ [ DataRow ( "http" , "localhost:7071" , null , false , false , "http://localhost:7071" ) ]
283+ [ DataRow ( "https" , "localhost:47071" , null , false , false , "https://localhost:47071" ) ]
284+ public void Given_Options_When_AddServer_Invoked_Then_It_Should_Return_BaseUrl ( string scheme , string host , string routePrefix , bool forceHttps , bool forceHttp , string expected )
285+ {
286+ var helper = new Mock < IDocumentHelper > ( ) ;
287+ var doc = new Document ( helper . Object ) ;
288+
289+ var req = new Mock < IHttpRequestDataObject > ( ) ;
290+ req . SetupGet ( p => p . Scheme ) . Returns ( scheme ) ;
291+
292+ var hostString = new HostString ( host ) ;
293+ req . SetupGet ( p => p . Host ) . Returns ( hostString ) ;
294+
295+ var options = new Mock < IOpenApiConfigurationOptions > ( ) ;
296+ options . SetupGet ( p => p . ForceHttps ) . Returns ( forceHttps ) ;
297+ options . SetupGet ( p => p . ForceHttp ) . Returns ( forceHttp ) ;
298+ options . SetupGet ( p => p . Servers ) . Returns ( new List < OpenApiServer > ( ) ) ;
299+
300+ var result = doc . InitialiseDocument ( )
301+ . AddServer ( req . Object , routePrefix , options . Object ) ;
302+
303+ result . OpenApiDocument . Servers . Should ( ) . HaveCount ( 1 ) ;
304+ result . OpenApiDocument . Servers . First ( ) . Url . Should ( ) . Be ( expected ) ;
305+ }
306+
204307 [ TestMethod ]
205308 public void Given_Null_When_AddNamingStrategy_Invoked_Then_It_Should_Throw_Exception ( )
206309 {
0 commit comments