@@ -195,6 +195,37 @@ public void GenerateCurl_Without_Content_For_PostMethod()
195195 @"curl -X POST http://localhost:1213/api/test -H 'Authorization: Bearer 56bfa7a0-0541-4d71-9efc-8b28219ac31a' -d ''" ) ) ;
196196 }
197197
198+ [ Theory ]
199+ public void GenerateCurl_Along_With_Warning_When_Exist_Slash_At_The_Beginning_Of_The_RequestUri_For_PostMethod ( )
200+ {
201+ // Arrange
202+ string requestBody = @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}" ;
203+
204+ var requestUri = "/api/test" ;
205+ var httpRequestMessage = new HttpRequestMessage ( HttpMethod . Post , requestUri ) ;
206+ httpRequestMessage . Content = new StringContent ( requestBody , Encoding . UTF8 , MediaTypeNames . Application . Json ) ;
207+ httpRequestMessage . Headers . Add ( "Authorization" , "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61" ) ;
208+
209+ using var httpClient = new HttpClient ( ) ;
210+ httpClient . BaseAddress = new Uri ( "http://localhost:1213" ) ;
211+
212+ // Act
213+ string script = Generator . GenerateCurl (
214+ httpClient ,
215+ httpRequestMessage ,
216+ requestUri ,
217+ true ) ;
218+
219+ // Assert
220+ Assert . That ( script , Is . Not . Null ) ;
221+ Assert . That ( script , Is . Not . Empty ) ;
222+ Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
223+ Assert . That ( script ? . Trim ( ) ,
224+ Is . EqualTo (
225+ @"# Warning: you must remove the Slash at the first of the requestUri.
226+ curl -X POST http://localhost:1213/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ) ;
227+ }
228+
198229 #endregion
199230
200231 #region :: GenerateCurl For Get Method ::
@@ -254,7 +285,36 @@ public void GenerateCurl_With_QueryString_For_GetMethod()
254285 Assert . That ( script , Is . Not . Empty ) ;
255286 Assert . That ( script , Does . StartWith ( "curl" ) ) ;
256287 Assert . That ( script ? . Trim ( ) ,
257- Is . EqualTo ( @"curl http://localhost:1213/api/test?id=12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
288+ Is . EqualTo (
289+ @"curl http://localhost:1213/api/test?id=12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
290+ }
291+
292+ [ Theory ]
293+ public void GenerateCurl_Along_With_Warning_When_Exist_Slash_At_The_Beginning_Of_The_RequestUri_For_GetMethod ( )
294+ {
295+ // Arrange
296+ var requestUri = "/api/test" ;
297+ var httpRequestMessage = new HttpRequestMessage ( HttpMethod . Get , requestUri ) ;
298+ httpRequestMessage . Content = new StringContent ( string . Empty , Encoding . UTF8 , MediaTypeNames . Application . Json ) ;
299+ httpRequestMessage . Headers . Add ( "Authorization" , "Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9" ) ;
300+
301+ using var httpClient = new HttpClient ( ) ;
302+ httpClient . BaseAddress = new Uri ( "http://localhost:1213" ) ;
303+
304+ // Act
305+ string script = Generator . GenerateCurl (
306+ httpClient ,
307+ httpRequestMessage ,
308+ requestUri ,
309+ true ) ;
310+
311+ // Assert
312+ Assert . That ( script , Is . Not . Null ) ;
313+ Assert . That ( script , Is . Not . Empty ) ;
314+ Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
315+ Assert . That ( script ? . Trim ( ) ,
316+ Is . EqualTo ( @"# Warning: you must remove the Slash at the first of the requestUri.
317+ curl http://localhost:1213/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
258318 }
259319
260320 #endregion
0 commit comments