22using System . Net . Http . Json ;
33using System . Net . Mime ;
44using System . Text ;
5+ using FluentAssertions ;
56using HttpClientToCurl ;
67using Microsoft . AspNetCore . WebUtilities ;
78using NUnit . Framework ;
@@ -30,11 +31,11 @@ public void Success_GenerateCurlInString_For_PostMethod()
3031 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
3132
3233 // Assert
33- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
34- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
35- Assert . That ( curlResult ? . Trim ( ) ,
36- Is . EqualTo (
37- @"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}'" ) ) ;
34+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
35+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
36+ curlResult . Trim ( ) . Should ( )
37+ . BeEquivalentTo (
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}'" ) ;
3839 }
3940
4041 [ Theory ]
@@ -54,11 +55,11 @@ public void GenerateCurl_When_Set_RequestUri_Inside_HttpRequestMessage_For_PostM
5455 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
5556
5657 // Assert
57- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
58- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
59- Assert . That ( curlResult ? . Trim ( ) ,
60- Is . EqualTo (
61- @"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}'" ) ) ;
58+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
59+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
60+ curlResult . Trim ( ) . Should ( )
61+ . BeEquivalentTo (
62+ @"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}'" ) ;
6263 }
6364
6465 [ Theory ]
@@ -78,11 +79,11 @@ public void Success_GenerateCurlInString_When_RequestUri_Is_Null_For_PostMethod(
7879 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
7980
8081 // Assert
81- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
82- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
83- Assert . That ( curlResult ? . Trim ( ) ,
84- Is . EqualTo (
85- @"curl -X POST http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ) ;
82+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
83+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
84+ curlResult . Trim ( ) . Should ( )
85+ . BeEquivalentTo (
86+ @"curl -X POST http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ;
8687 }
8788
8889 [ Theory ]
@@ -101,11 +102,11 @@ public void Success_GenerateCurlInString_When_RequestBody_Is_Null_For_PostMethod
101102 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
102103
103104 // Assert
104- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
105- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
106- Assert . That ( curlResult ? . Trim ( ) ,
107- Is . EqualTo (
108- @"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 ''" ) ) ;
105+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
106+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
107+ curlResult . Trim ( ) . Should ( )
108+ . BeEquivalentTo (
109+ @"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 ''" ) ;
109110 }
110111
111112 [ Theory ]
@@ -123,11 +124,9 @@ public void Success_GenerateCurlInString_When_HttpContent_Is_Null_For_PostMethod
123124 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
124125
125126 // Assert
126- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
127- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
128- Assert . That ( curlResult ? . Trim ( ) ,
129- Is . EqualTo (
130- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -d ''" ) ) ;
127+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
128+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
129+ curlResult . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -d ''" ) ;
131130 }
132131
133132 [ Theory ]
@@ -155,11 +154,11 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_For_PostMeth
155154 HttpMethod . Post , requestUri , httpRequestHeaders , jsonContent ) ;
156155
157156 // Assert
158- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
159- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
160- Assert . That ( curlResult ? . Trim ( ) ,
161- Is . EqualTo (
162- @"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}'" ) ) ;
157+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
158+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
159+ curlResult . Trim ( ) . Should ( )
160+ . BeEquivalentTo (
161+ @"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}'" ) ;
163162 }
164163
165164 [ Theory ]
@@ -178,11 +177,9 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_Body_Is_
178177 HttpMethod . Post , requestUri , httpRequestHeaders ) ;
179178
180179 // Assert
181- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
182- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
183- Assert . That ( curlResult ? . Trim ( ) ,
184- Is . EqualTo (
185- @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -d ''" ) ) ;
180+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
181+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
182+ curlResult . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -d ''" ) ;
186183 }
187184
188185 [ Theory ]
@@ -209,11 +206,11 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_RequestU
209206 httpMethod : HttpMethod . Post , requestHeaders : httpRequestHeaders , requestBody : jsonContent ) ;
210207
211208 // Assert
212- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
213- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
214- Assert . That ( curlResult ? . Trim ( ) ,
215- Is . EqualTo (
216- @"curl -X POST http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ) ;
209+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
210+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
211+ curlResult . Trim ( ) . Should ( )
212+ . BeEquivalentTo (
213+ @"curl -X POST http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ;
217214 }
218215
219216 [ Theory ]
@@ -239,11 +236,11 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_HttpRequ
239236 httpMethod : HttpMethod . Post , requestUri : requestUri , requestBody : jsonContent ) ;
240237
241238 // Assert
242- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
243- Assert . That ( curlResult , Does . StartWith ( "curl -X POST" ) ) ;
244- Assert . That ( curlResult ? . Trim ( ) ,
245- Is . EqualTo (
246- @"curl -X POST http://localhost:1213/v1/api/test -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ) ;
239+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
240+ curlResult . Should ( ) . StartWith ( "curl -X POST" ) ;
241+ curlResult . Trim ( ) . Should ( )
242+ . BeEquivalentTo (
243+ @"curl -X POST http://localhost:1213/v1/api/test -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""sara"",""requestId"":10001001,""amount"":20000}'" ) ;
247244 }
248245
249246 #endregion
@@ -266,11 +263,11 @@ public void Success_GenerateCurlInString_For_GetMethod()
266263 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
267264
268265 // Assert
269- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
270- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
271- Assert . That ( curlResult ? . Trim ( ) ,
272- Is . EqualTo (
273- @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
266+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
267+ curlResult . Should ( ) . StartWith ( "curl" ) ;
268+ curlResult . Trim ( ) . Should ( )
269+ . BeEquivalentTo (
270+ @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
274271 }
275272
276273 [ Theory ]
@@ -293,11 +290,11 @@ public void Success_GenerateCurlInString_With_QueryString_For_GetMethod()
293290 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
294291
295292 // Assert
296- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
297- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
298- Assert . That ( curlResult ? . Trim ( ) ,
299- Is . EqualTo (
300- @"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'" ) ) ;
293+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
294+ curlResult . Should ( ) . StartWith ( "curl" ) ;
295+ curlResult . Trim ( ) . Should ( )
296+ . BeEquivalentTo (
297+ @"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'" ) ;
301298 }
302299
303300 [ Theory ]
@@ -315,10 +312,10 @@ public void Success_GenerateCurlInString_When_RequestUri_Is_Null_For_GetMethod()
315312 string curlResult = httpClient . GenerateCurlInString ( httpRequestMessage ) ;
316313
317314 // Assert
318- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
319- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
320- Assert . That ( curlResult ? . Trim ( ) ,
321- Is . EqualTo ( @"curl http://localhost:1213/v1 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ) ;
315+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
316+ curlResult . Should ( ) . StartWith ( "curl" ) ;
317+ curlResult . Trim ( ) . Should ( )
318+ . BeEquivalentTo ( @"curl http://localhost:1213/v1 -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'" ) ;
322319 }
323320
324321 [ Theory ]
@@ -337,11 +334,9 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_For_GetMetho
337334 HttpMethod . Get , requestUri , httpRequestHeaders ) ;
338335
339336 // Assert
340- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
341- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
342- Assert . That ( curlResult ? . Trim ( ) ,
343- Is . EqualTo (
344- @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61'" ) ) ;
337+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
338+ curlResult . Should ( ) . StartWith ( "curl" ) ;
339+ curlResult . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61'" ) ;
345340 }
346341
347342 [ Theory ]
@@ -359,11 +354,9 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_RequestU
359354 httpMethod : HttpMethod . Get , requestHeaders : httpRequestHeaders ) ;
360355
361356 // Assert
362- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
363- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
364- Assert . That ( curlResult ? . Trim ( ) ,
365- Is . EqualTo (
366- @"curl http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61'" ) ) ;
357+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
358+ curlResult . Should ( ) . StartWith ( "curl" ) ;
359+ curlResult . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl http://localhost:1213/v1 -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61'" ) ;
367360 }
368361
369362 [ Theory ]
@@ -380,11 +373,9 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_HttpRequ
380373 HttpMethod . Get , requestUri ) ;
381374
382375 // Assert
383- Assert . That ( ! string . IsNullOrWhiteSpace ( curlResult ? . Trim ( ) ) , Is . True ) ;
384- Assert . That ( curlResult , Does . StartWith ( "curl" ) ) ;
385- Assert . That ( curlResult ? . Trim ( ) ,
386- Is . EqualTo (
387- @"curl http://localhost:1213/v1/api/test" ) ) ;
376+ curlResult . Should ( ) . NotBeNullOrEmpty ( ) ;
377+ curlResult . Should ( ) . StartWith ( "curl" ) ;
378+ curlResult . Trim ( ) . Should ( ) . BeEquivalentTo ( @"curl http://localhost:1213/v1/api/test" ) ;
388379 }
389380
390381 #endregion
0 commit comments