1- using System . Net . Mime ;
2- using System . Text ;
1+ using FluentAssertions ;
32using HttpClientToCurl ;
43using Microsoft . AspNetCore . WebUtilities ;
54using NUnit . Framework ;
5+ using System . Net . Mime ;
6+ using System . Text ;
67
78namespace HttpClientToCurlGeneratorTest . UnitTest . MediaTypes . Json ;
89
910public class SuccessCurlGeneratorTests
1011{
11- #region :: GenerateCurl For Post Method ::
12+
1213
1314 [ Theory ]
1415 public void GenerateCurl_For_PostMethod ( )
@@ -31,11 +32,9 @@ public void GenerateCurl_For_PostMethod()
3132 true ) ;
3233
3334 // Assert
34- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
35- Assert . That ( script , Does . StartWith ( "curl -X POST" ) ) ;
36- Assert . That ( script ? . Trim ( ) ,
37- Is . EqualTo (
38- @"curl -X POST http://localhost:1213/v1/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}'" ) ) ;
35+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
36+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
37+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/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}'" ) ;
3938 }
4039
4140 [ Theory ]
@@ -60,11 +59,9 @@ public void GenerateCurl_With_ContentLength_For_PostMethod()
6059 true ) ;
6160
6261 // Assert
63- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
64- Assert . That ( script , Does . StartWith ( "curl -X POST" ) ) ;
65- Assert . That ( script ? . Trim ( ) ,
66- Is . EqualTo (
67- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer f69406a4-6b62-4734-a8dc-158f0fc308ab' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ) ;
62+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
63+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
64+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer f69406a4-6b62-4734-a8dc-158f0fc308ab' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ;
6865 }
6966
7067 [ Theory ]
@@ -92,11 +89,10 @@ public void GenerateCurl_With_QueryString_For_PostMethod()
9289 true ) ;
9390
9491 // Assert
95- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
96- Assert . That ( script , Does . StartWith ( "curl -X POST" ) ) ;
97- Assert . That ( script ? . Trim ( ) ,
98- Is . EqualTo (
99- @"curl -X POST http://localhost:1213/v1/api/test?id=12 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""amin"",""requestId"":10001000,""amount"":10000}'" ) ) ;
92+
93+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
94+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
95+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test?id=12 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""amin"",""requestId"":10001000,""amount"":10000}'" ) ;
10096 }
10197
10298 [ Theory ]
@@ -125,10 +121,9 @@ public void GenerateCurl_UrlEncoded_For_PostMethod()
125121 true ) ;
126122
127123 // Assert
128- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
129- Assert . That ( script ? . Trim ( ) ,
130- Is . EqualTo (
131- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/x-www-form-urlencoded' -d 'session=703438f3-16ad-4ba5-b923-8f72cd0f2db9' -d 'payload={""name"":""justin"",""requestId"":10001026,""amount"":26000}'" ) ) ;
124+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
125+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
126+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/x-www-form-urlencoded' -d 'session=703438f3-16ad-4ba5-b923-8f72cd0f2db9' -d 'payload={""name"":""justin"",""requestId"":10001026,""amount"":26000}'" ) ;
132127 }
133128
134129 [ Theory ]
@@ -150,11 +145,9 @@ public void GenerateCurl_Without_RequestBody_For_PostMethod()
150145 true ) ;
151146
152147 // Assert
153- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
154- Assert . That ( script , Does . StartWith ( "curl -X POST" ) ) ;
155- Assert . That ( script ? . Trim ( ) ,
156- Is . EqualTo (
157- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer c332e9a1-1e0e-44c2-b819-b0e7e8ff7d45' -H 'Content-Type: application/json; charset=utf-8' -d ''" ) ) ;
148+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
149+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
150+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer c332e9a1-1e0e-44c2-b819-b0e7e8ff7d45' -H 'Content-Type: application/json; charset=utf-8' -d ''" ) ;
158151 }
159152
160153 [ Theory ]
@@ -176,11 +169,9 @@ public void GenerateCurl_Without_Content_For_PostMethod()
176169 true ) ;
177170
178171 // Assert
179- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
180- Assert . That ( script , Does . StartWith ( "curl -X POST" ) ) ;
181- Assert . That ( script ? . Trim ( ) ,
182- Is . EqualTo (
183- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 56bfa7a0-0541-4d71-9efc-8b28219ac31a' -d ''" ) ) ;
172+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
173+ script . Should ( ) . StartWith ( "curl -X POST" ) ;
174+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 56bfa7a0-0541-4d71-9efc-8b28219ac31a' -d ''" ) ;
184175 }
185176
186177 [ Theory ]
@@ -204,12 +195,10 @@ public void GenerateCurl_Along_With_Warning_When_Has_Additional_Slash_For_PostMe
204195 true ) ;
205196
206197 // Assert
207- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
208- Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
209- Assert . That ( script ? . Trim ( ) ,
210- Is . EqualTo (
211- @"# Warning: you must remove the Slash at the end of base url or at the first of the requestUri.
212- curl -X POST http://localhost:1213/v1/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}'" ) ) ;
198+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
199+ script . Should ( ) . StartWith ( "# Warning" ) ;
200+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"# Warning: you must remove the Slash at the end of base url or at the first of the requestUri.
201+ curl -X POST http://localhost:1213/v1/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}'" ) ;
213202 }
214203
215204 [ Theory ]
@@ -233,18 +222,12 @@ public void GenerateCurl_Along_With_Warning_When_Has_Fewer_Slash_For_PostMethod(
233222 true ) ;
234223
235224 // Assert
236- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
237- Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
238- Assert . That ( script ? . Trim ( ) ,
239- Is . EqualTo (
240- @"# Warning: you must add the Slash at the end of base url or at the first of the requestUri.
241- curl -X POST http://localhost:1213/v1/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}'" ) ) ;
225+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
226+ script . Should ( ) . StartWith ( "# Warning" ) ;
227+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"# Warning: you must add the Slash at the end of base url or at the first of the requestUri.
228+ curl -X POST http://localhost:1213/v1/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}'" ) ;
242229 }
243230
244- #endregion
245-
246- #region :: GenerateCurl For Get Method ::
247-
248231 [ Theory ]
249232 public void GenerateCurl_For_GetMethod ( )
250233 {
@@ -264,11 +247,9 @@ public void GenerateCurl_For_GetMethod()
264247 true ) ;
265248
266249 // Assert
267- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
268- Assert . That ( script , Does . StartWith ( "curl" ) ) ;
269- Assert . That ( script ? . Trim ( ) ,
270- Is . EqualTo (
271- @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
250+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
251+ script . Should ( ) . StartWith ( "curl" ) ;
252+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
272253 }
273254
274255 [ Theory ]
@@ -294,11 +275,9 @@ public void GenerateCurl_With_QueryString_For_GetMethod()
294275 true ) ;
295276
296277 // Assert
297- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
298- Assert . That ( script , Does . StartWith ( "curl" ) ) ;
299- Assert . That ( script ? . Trim ( ) ,
300- Is . EqualTo (
301- @"curl http://localhost:1213/v1/api/test?id=12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
278+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
279+ script . Should ( ) . StartWith ( "curl" ) ;
280+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl http://localhost:1213/v1/api/test?id=12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
302281 }
303282
304283 [ Theory ]
@@ -320,11 +299,10 @@ public void GenerateCurl_Along_With_Warning_When_Has_Additional_Slash_For_GetMet
320299 true ) ;
321300
322301 // Assert
323- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
324- Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
325- Assert . That ( script ? . Trim ( ) ,
326- Is . EqualTo ( @"# Warning: you must remove the Slash at the end of base url or at the first of the requestUri.
327- curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
302+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
303+ script . Should ( ) . StartWith ( "# Warning" ) ;
304+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"# Warning: you must remove the Slash at the end of base url or at the first of the requestUri.
305+ curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
328306 }
329307
330308 [ Theory ]
@@ -346,17 +324,12 @@ public void GenerateCurl_Along_With_Warning_When_Has_Fewer_Slash_For_GetMethod()
346324 true ) ;
347325
348326 // Assert
349- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
350- Assert . That ( script , Does . StartWith ( "# Warning" ) ) ;
351- Assert . That ( script ? . Trim ( ) ,
352- Is . EqualTo ( @"# Warning: you must add the Slash at the end of base url or at the first of the requestUri.
353- curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
327+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
328+ script . Should ( ) . StartWith ( "# Warning" ) ;
329+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"# Warning: you must add the Slash at the end of base url or at the first of the requestUri.
330+ curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
354331 }
355332
356- #endregion
357-
358- #region :: GenerateCurl For Put Method ::
359-
360333 [ Theory ]
361334 public void GenerateCurl_For_PutMethod ( )
362335 {
@@ -378,17 +351,11 @@ public void GenerateCurl_For_PutMethod()
378351 true ) ;
379352
380353 // Assert
381- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
382- Assert . That ( script , Does . StartWith ( "curl -X PUT" ) ) ;
383- Assert . That ( script ? . Trim ( ) ,
384- Is . EqualTo (
385- @"curl -X PUT http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""reza"",""requestId"":10001002,""amount"":30000}'" ) ) ;
354+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
355+ script . Should ( ) . StartWith ( "curl -X PUT" ) ;
356+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X PUT http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""reza"",""requestId"":10001002,""amount"":30000}'" ) ;
386357 }
387358
388- #endregion
389-
390- #region :: GenerateCurl For Patch Method ::
391-
392359 [ Theory ]
393360 public void GenerateCurl_For_PatchMethod ( )
394361 {
@@ -410,17 +377,11 @@ public void GenerateCurl_For_PatchMethod()
410377 true ) ;
411378
412379 // Assert
413- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
414- Assert . That ( script , Does . StartWith ( "curl -X PATCH" ) ) ;
415- Assert . That ( script ? . Trim ( ) ,
416- Is . EqualTo (
417- @"curl -X PATCH http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""hamed"",""requestId"":10001003,""amount"":40000}'" ) ) ;
380+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
381+ script . Should ( ) . StartWith ( "curl -X PATCH" ) ;
382+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X PATCH http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""hamed"",""requestId"":10001003,""amount"":40000}'" ) ;
418383 }
419384
420- #endregion
421-
422- #region :: GenerateCurl For DeleteMethod ::
423-
424385 [ Theory ]
425386 public void GenerateCurl_For_DeleteMethod ( )
426387 {
@@ -441,12 +402,9 @@ public void GenerateCurl_For_DeleteMethod()
441402 true ) ;
442403
443404 // Assert
444- Assert . That ( ! string . IsNullOrWhiteSpace ( script ? . Trim ( ) ) , Is . True ) ;
445- Assert . That ( script , Does . StartWith ( "curl -X DELETE" ) ) ;
446- Assert . That ( script ? . Trim ( ) ,
447- Is . EqualTo (
448- @"curl -X DELETE http://localhost:1213/v1/api/test/12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
405+ script . Should ( ) . NotBeNullOrEmpty ( ) ;
406+ script . Should ( ) . StartWith ( "curl -X DELETE" ) ;
407+ script . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X DELETE http://localhost:1213/v1/api/test/12 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
449408 }
450409
451- #endregion
452- }
410+ }
0 commit comments