Skip to content

Commit 9a6a092

Browse files
aminamin
authored andcommitted
ctrl+alt+l
1 parent 1cfe5b4 commit 9a6a092

File tree

6 files changed

+54
-27
lines changed

6 files changed

+54
-27
lines changed

src/HttpClientToCurl/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static void GenerateCurlInFile(this HttpClient httpClient, HttpRequestMes
147147
public static void GenerateCurlInFile(
148148
this HttpClient httpClient,
149149
HttpMethod httpMethod,
150-
string requestUri="",
150+
string requestUri = "",
151151
HttpRequestHeaders requestHeaders = null,
152152
HttpContent requestBody = null,
153153
Action<FileConfig> config = null)

src/HttpClientToCurl/Utility/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static void AppendBodyItem(this StringBuilder stringBuilder, object bod
1313
.Append(body)
1414
.Append('\'')
1515
.Append(' ');
16-
16+
1717
internal static void AddFormUrlEncodedContentBody(this StringBuilder stringBuilder, string body)
1818
{
1919
string decodedBody = HttpUtility.UrlDecode(body);
@@ -46,7 +46,7 @@ internal static ConsoleColor SetColor(this HttpMethod httpMethod)
4646

4747
return color;
4848
}
49-
49+
5050
internal static string NormalizedPath(this string path)
5151
{
5252
string inputPath = path?.Trim();

src/HttpClientToCurl/Utility/Helpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ internal static HttpRequestMessage FillHttpRequestMessage(HttpMethod httpMethod,
6363

6464
return httpRequestMessage;
6565
}
66-
66+
6767
internal static bool CheckAddressIsAbsoluteUri(Uri baseAddress)
6868
{
6969
bool isValidAbsoluteAddress = true;
70-
70+
7171
if (baseAddress is null)
7272
isValidAbsoluteAddress = false;
7373
else if (!baseAddress.IsAbsoluteUri)

src/HttpClientToCurlGeneratorTest/FunctionalTest/SuccessScenariosTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Success_GenerateCurlInString_For_PostMethod()
3838
.BeEquivalentTo(
3939
@"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}'");
4040
}
41-
41+
4242
[Theory]
4343
public void Success_GenerateCurlInString_With_RequestUri_TypeOf_Uri_For_PostMethod()
4444
{
@@ -117,7 +117,7 @@ public void Success_GenerateCurlInString_When_RequestBody_Is_Null_For_PostMethod
117117
{
118118
// Arrange
119119
var requestUri = "api/test";
120-
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post,requestUri);
120+
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
121121
httpRequestMessage.Content = new StringContent(string.Empty, Encoding.UTF8, MediaTypeNames.Application.Json);
122122
httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61");
123123

@@ -186,7 +186,7 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_For_PostMeth
186186
.BeEquivalentTo(
187187
@"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}'");
188188
}
189-
189+
190190
[Theory]
191191
public void Success_GenerateCurlInString_Without_HttpRequestMessage_With_RequestUri_Typeof_Uri_For_PostMethod()
192192
{
@@ -261,7 +261,7 @@ public void Success_GenerateCurlInString_Without_HttpRequestMessage_And_RequestU
261261

262262
// Act
263263
string curlResult = httpClient.GenerateCurlInString(
264-
httpMethod: HttpMethod.Post, requestHeaders: httpRequestHeaders, requestBody: jsonContent,requestUri:string.Empty);
264+
httpMethod: HttpMethod.Post, requestHeaders: httpRequestHeaders, requestBody: jsonContent, requestUri: string.Empty);
265265

266266
// Assert
267267
curlResult.Should().NotBeNullOrEmpty();

src/HttpClientToCurlGeneratorTest/UnitTest/MediaTypes/Json/SuccessCurlGeneratorTests.cs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public void GenerateCurl_For_PostMethod()
3232
// Assert
3333
script.Should().NotBeNullOrEmpty();
3434
script.Should().StartWith("curl -X POST");
35-
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}'");
35+
script.Trim().Should()
36+
.BeEquivalentTo(
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}'");
3638
}
3739

3840
[Theory]
@@ -59,7 +61,9 @@ public void GenerateCurl_With_ContentLength_For_PostMethod()
5961
// Assert
6062
script.Should().NotBeNullOrEmpty();
6163
script.Should().StartWith("curl -X POST");
62-
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}'");
64+
script.Trim().Should()
65+
.BeEquivalentTo(
66+
@"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}'");
6367
}
6468

6569
[Theory]
@@ -90,7 +94,9 @@ public void GenerateCurl_With_QueryString_For_PostMethod()
9094

9195
script.Should().NotBeNullOrEmpty();
9296
script.Should().StartWith("curl -X POST");
93-
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}'");
97+
script.Trim().Should()
98+
.BeEquivalentTo(
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}'");
94100
}
95101

96102
[Theory]
@@ -121,7 +127,9 @@ public void GenerateCurl_UrlEncoded_For_PostMethod()
121127
// Assert
122128
script.Should().NotBeNullOrEmpty();
123129
script.Should().StartWith("curl -X POST");
124-
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}'");
130+
script.Trim().Should()
131+
.BeEquivalentTo(
132+
@"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}'");
125133
}
126134

127135
[Theory]
@@ -145,7 +153,9 @@ public void GenerateCurl_Without_RequestBody_For_PostMethod()
145153
// Assert
146154
script.Should().NotBeNullOrEmpty();
147155
script.Should().StartWith("curl -X POST");
148-
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 ''");
156+
script.Trim().Should()
157+
.BeEquivalentTo(
158+
@"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 ''");
149159
}
150160

151161
[Theory]
@@ -171,7 +181,7 @@ public void GenerateCurl_Without_Content_For_PostMethod()
171181
script.Should().StartWith("curl -X POST");
172182
script.Trim().Should().BeEquivalentTo(@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 56bfa7a0-0541-4d71-9efc-8b28219ac31a' -d ''");
173183
}
174-
184+
175185
[Theory]
176186
public void GenerateCurl_When_Invalid_JsonBody_PostMethod()
177187
{
@@ -195,7 +205,9 @@ public void GenerateCurl_When_Invalid_JsonBody_PostMethod()
195205
// Assert
196206
script.Should().NotBeNullOrEmpty();
197207
script.Should().StartWith("curl -X POST");
198-
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"":""steven"",""requestId"":10001005,""amount"":60000'");
208+
script.Trim().Should()
209+
.BeEquivalentTo(
210+
@"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"":""steven"",""requestId"":10001005,""amount"":60000'");
199211
}
200212

201213
[Theory]
@@ -221,9 +233,11 @@ public void GenerateCurl_When_BaseAddress_Is_Null_PostMethod()
221233
// Assert
222234
script.Should().NotBeNullOrEmpty();
223235
script.Should().StartWith("curl -X POST");
224-
script.Trim().Should().BeEquivalentTo(@"curl -X POST -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""nancy"",""requestId"":10001006,""amount"":70000}'");
236+
script.Trim().Should()
237+
.BeEquivalentTo(
238+
@"curl -X POST -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: application/json; charset=utf-8' -d '{""name"":""nancy"",""requestId"":10001006,""amount"":70000}'");
225239
}
226-
240+
227241
[Theory]
228242
public void GenerateCurl_For_GetMethod()
229243
{
@@ -245,7 +259,9 @@ public void GenerateCurl_For_GetMethod()
245259
// Assert
246260
script.Should().NotBeNullOrEmpty();
247261
script.Should().StartWith("curl");
248-
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'");
262+
script.Trim().Should()
263+
.BeEquivalentTo(
264+
@"curl http://localhost:1213/v1/api/test -H 'Authorization: Bearer 703438f3-16ad-4ba5-b923-8f72cd0f2db9' -H 'Content-Type: application/json; charset=utf-8'");
249265
}
250266

251267
[Theory]
@@ -273,8 +289,11 @@ public void GenerateCurl_With_QueryString_For_GetMethod()
273289
// Assert
274290
script.Should().NotBeNullOrEmpty();
275291
script.Should().StartWith("curl");
276-
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'");
292+
script.Trim().Should()
293+
.BeEquivalentTo(
294+
@"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'");
277295
}
296+
278297
[Theory]
279298
public void GenerateCurl_For_PutMethod()
280299
{
@@ -298,7 +317,9 @@ public void GenerateCurl_For_PutMethod()
298317
// Assert
299318
script.Should().NotBeNullOrEmpty();
300319
script.Should().StartWith("curl -X PUT");
301-
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}'");
320+
script.Trim().Should()
321+
.BeEquivalentTo(
322+
@"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}'");
302323
}
303324

304325
[Theory]
@@ -324,7 +345,9 @@ public void GenerateCurl_For_PatchMethod()
324345
// Assert
325346
script.Should().NotBeNullOrEmpty();
326347
script.Should().StartWith("curl -X PATCH");
327-
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}'");
348+
script.Trim().Should()
349+
.BeEquivalentTo(
350+
@"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}'");
328351
}
329352

330353
[Theory]
@@ -349,6 +372,8 @@ public void GenerateCurl_For_DeleteMethod()
349372
// Assert
350373
script.Should().NotBeNullOrEmpty();
351374
script.Should().StartWith("curl -X DELETE");
352-
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'");
375+
script.Trim().Should()
376+
.BeEquivalentTo(
377+
@"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'");
353378
}
354-
}
379+
}

src/HttpClientToCurlGeneratorTest/UnitTest/MediaTypes/Xml/SuccessCurlGeneratorTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ public void Get_Curl_Script_For_PostMethod()
3737
// Assert
3838
script.Should().NotBeNullOrEmpty();
3939
script.Should().StartWith("curl -X POST");
40-
script.Trim().Should().BeEquivalentTo(@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<?xml version = ""1.0"" encoding = ""UTF-8""?>
40+
script.Trim().Should().BeEquivalentTo(
41+
@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<?xml version = ""1.0"" encoding = ""UTF-8""?>
4142
<Order>
4243
<Id>12</Id>
4344
<name>Jason</name>
4445
<requestId>10001024</requestId>
4546
<amount>240000</amount>
4647
</Order>'");
4748
}
48-
49+
4950
[Theory]
5051
public void Get_Error_Message_When_Input_XML_Is_Invalid_For_PostMethod()
5152
{
@@ -76,7 +77,8 @@ public void Get_Error_Message_When_Input_XML_Is_Invalid_For_PostMethod()
7677
script.Should().NotBeNull();
7778
script.Should().NotBeEmpty();
7879
script.Should().StartWith("curl -X POST");
79-
script.Trim().Should().BeEquivalentTo(@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<xml version = ""1.0"" encoding = ""UTF-8""?>
80+
script.Trim().Should().BeEquivalentTo(
81+
@"curl -X POST http://localhost:1213/v1/api/test -H 'Authorization: Bearer 4797c126-3f8a-454a-aff1-96c0220dae61' -H 'Content-Type: text/xml; charset=utf-8' -d '<xml version = ""1.0"" encoding = ""UTF-8""?>
8082
<Order>
8183
<Id>12</Id>
8284
<name>Jason</name>

0 commit comments

Comments
 (0)