Skip to content

Commit 450a5bc

Browse files
Resolve conflicts
2 parents f3b10ec + 7d18a69 commit 450a5bc

File tree

23 files changed

+1065
-84
lines changed

23 files changed

+1065
-84
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup .NET
1717
uses: actions/setup-dotnet@v2
1818
with:
19-
dotnet-version: 8.0.x
19+
dotnet-version: 9.0.x
2020
- name: Restore dependencies
2121
run: dotnet restore
2222
working-directory: ./

.lutignore

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
## The .lutignore file is used by Live Unit Testing to ignore Visual Studio temporary files, build results,
2+
## and files generated by popular Visual Studio add-ons when creating a private copy of the source tree that
3+
## Live Unit Testing uses for its build.
4+
##
5+
## This file has same format as git's .gitignore file (https://git-scm.com/docs/gitignore). In fact, in the
6+
## case where a .lutignore file is not found, but a .gitignore file is found, Live Unit Testing will use the
7+
## .gitignore file directly for the above purpose.
8+
9+
# User-specific files
10+
*.suo
11+
*.user
12+
*.userprefs
13+
*.sln.docstates
14+
.vs/
15+
.vscode/
16+
.packages/
17+
.dotnet/
18+
.tools/
19+
.idea/
20+
21+
# Build results
22+
[Dd]ebug/
23+
[Rr]elease/
24+
[Bb]inaries/
25+
[Bb]in/
26+
[Oo]bj/
27+
x64/
28+
TestResults/
29+
30+
# Debug artifacts
31+
launchSettings.json
32+
33+
# Click-Once directory
34+
publish/
35+
36+
# Publish Web Output
37+
*.Publish.xml
38+
39+
# NuGet
40+
packages/
41+
[Nn]u[Gg]et.exe
42+
*-packages.config
43+
*.nuget.props
44+
*.nuget.targets
45+
project.lock.json
46+
msbuild.binlog
47+
*.project.lock.json
48+
49+
# Miscellaneous
50+
*_i.c
51+
*_p.c
52+
*.ilk
53+
*.meta
54+
*.obj
55+
*.pch
56+
*.pdb
57+
*.pgc
58+
*.pgd
59+
*.sbr
60+
*.tlb
61+
*.tli
62+
*.tlh
63+
*.tmp
64+
*.tmp_proj
65+
*.log
66+
*.wrn
67+
*.vspscc
68+
*.vssscc
69+
.builds
70+
*.pidb
71+
*.scc
72+
sql/
73+
*.Cache
74+
ClientBin/
75+
[Ss]tyle[Cc]op.*
76+
~$*
77+
*~
78+
*.dbmdl
79+
*.[Pp]ublish.xml
80+
*.pfx
81+
*.publishsettings
82+
83+
# Cache and temp files
84+
ipch/
85+
*.aps
86+
*.ncb
87+
*.opensdf
88+
*.sdf
89+
*.cachefile
90+
*.VC.opendb
91+
*.VC.db
92+
AppPackages/
93+
_ReSharper*/
94+
*.[Rr]e[Ss]harper
95+
*.DotSettings
96+
$RECYCLE.BIN/
97+
.DS_Store
98+
*wpftmp.*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<LUTConfig Version="1.0">
2+
<Repository />
3+
<ParallelBuilds>true</ParallelBuilds>
4+
<ParallelTestRuns>true</ParallelTestRuns>
5+
<TestCaseTimeout>180000</TestCaseTimeout>
6+
</LUTConfig>

HttpClientToCurlGenerator.sln

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 17.7.34221.43
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientToCurl", "src\HttpClientToCurl\HttpClientToCurl.csproj", "{18B3309D-B84C-453D-8EF7-16CA9E58F5DC}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientToCurlGeneratorTest", "tests\HttpClientToCurlGeneratorTest\HttpClientToCurlGeneratorTest.csproj", "{BF3321A5-A590-44DD-BA5D-44978D9B6125}"
9-
EndProject
108
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{A8574DB9-8411-4F81-A82E-F97AD00EF8AF}"
119
EndProject
1210
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientToCurl.Sample.InConsole", "examples\HttpClientToCurl.Sample.InConsole\HttpClientToCurl.Sample.InConsole.csproj", "{323022D2-AAA7-443B-895C-77F5B1634D68}"
@@ -25,10 +23,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solutionItems", "solutionIt
2523
pre-push = pre-push
2624
EndProjectSection
2725
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpRequestMessageToCurlGeneratorTest", "HttpRequestMessageToCurlTest\HttpRequestMessageToCurlGeneratorTest.csproj", "{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531}"
29-
EndProject
3026
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientToCurl.Sample.InGlobal", "examples\HttpClientToCurl.Sample.InGlobal\HttpClientToCurl.Sample.InGlobal.csproj", "{5A8427BC-0821-E973-7221-263D13156248}"
3127
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientToCurlTest", "tests\HttpClientToCurlTest\HttpClientToCurlTest.csproj", "{8CC76F1F-5845-D81E-5E9A-113F913A444B}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpRequestMessageToCurlTest", "tests\HttpRequestMessageToCurlTest\HttpRequestMessageToCurlTest.csproj", "{69E31075-F14E-1DE2-1D6E-D934A5C0480F}"
31+
EndProject
3232
Global
3333
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3434
Debug|Any CPU = Debug|Any CPU
@@ -39,10 +39,6 @@ Global
3939
{18B3309D-B84C-453D-8EF7-16CA9E58F5DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
4040
{18B3309D-B84C-453D-8EF7-16CA9E58F5DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
4141
{18B3309D-B84C-453D-8EF7-16CA9E58F5DC}.Release|Any CPU.Build.0 = Release|Any CPU
42-
{BF3321A5-A590-44DD-BA5D-44978D9B6125}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43-
{BF3321A5-A590-44DD-BA5D-44978D9B6125}.Debug|Any CPU.Build.0 = Debug|Any CPU
44-
{BF3321A5-A590-44DD-BA5D-44978D9B6125}.Release|Any CPU.ActiveCfg = Release|Any CPU
45-
{BF3321A5-A590-44DD-BA5D-44978D9B6125}.Release|Any CPU.Build.0 = Release|Any CPU
4642
{323022D2-AAA7-443B-895C-77F5B1634D68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4743
{323022D2-AAA7-443B-895C-77F5B1634D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
4844
{323022D2-AAA7-443B-895C-77F5B1634D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -55,26 +51,30 @@ Global
5551
{403B236B-D7D8-43FB-B47E-DCCAF8BA96C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
5652
{403B236B-D7D8-43FB-B47E-DCCAF8BA96C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
5753
{403B236B-D7D8-43FB-B47E-DCCAF8BA96C4}.Release|Any CPU.Build.0 = Release|Any CPU
58-
{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59-
{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531}.Debug|Any CPU.Build.0 = Debug|Any CPU
60-
{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531}.Release|Any CPU.ActiveCfg = Release|Any CPU
61-
{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531}.Release|Any CPU.Build.0 = Release|Any CPU
6254
{5A8427BC-0821-E973-7221-263D13156248}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6355
{5A8427BC-0821-E973-7221-263D13156248}.Debug|Any CPU.Build.0 = Debug|Any CPU
6456
{5A8427BC-0821-E973-7221-263D13156248}.Release|Any CPU.ActiveCfg = Release|Any CPU
6557
{5A8427BC-0821-E973-7221-263D13156248}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{8CC76F1F-5845-D81E-5E9A-113F913A444B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{8CC76F1F-5845-D81E-5E9A-113F913A444B}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{8CC76F1F-5845-D81E-5E9A-113F913A444B}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{8CC76F1F-5845-D81E-5E9A-113F913A444B}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{69E31075-F14E-1DE2-1D6E-D934A5C0480F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{69E31075-F14E-1DE2-1D6E-D934A5C0480F}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{69E31075-F14E-1DE2-1D6E-D934A5C0480F}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{69E31075-F14E-1DE2-1D6E-D934A5C0480F}.Release|Any CPU.Build.0 = Release|Any CPU
6666
EndGlobalSection
6767
GlobalSection(SolutionProperties) = preSolution
6868
HideSolutionNode = FALSE
6969
EndGlobalSection
7070
GlobalSection(NestedProjects) = preSolution
7171
{18B3309D-B84C-453D-8EF7-16CA9E58F5DC} = {D3967ABF-F7C6-4432-9B67-A3F804CBC3E7}
72-
{BF3321A5-A590-44DD-BA5D-44978D9B6125} = {E36BF269-7F5D-4DE7-99B0-14567F9CD6B3}
7372
{323022D2-AAA7-443B-895C-77F5B1634D68} = {A8574DB9-8411-4F81-A82E-F97AD00EF8AF}
7473
{F7B35144-A00C-45BE-BC41-36C1B21FCD18} = {A8574DB9-8411-4F81-A82E-F97AD00EF8AF}
7574
{403B236B-D7D8-43FB-B47E-DCCAF8BA96C4} = {A8574DB9-8411-4F81-A82E-F97AD00EF8AF}
76-
{007CA9E0-CDF0-4375-8E8C-A24C9A7BF531} = {E36BF269-7F5D-4DE7-99B0-14567F9CD6B3}
7775
{5A8427BC-0821-E973-7221-263D13156248} = {A8574DB9-8411-4F81-A82E-F97AD00EF8AF}
76+
{8CC76F1F-5845-D81E-5E9A-113F913A444B} = {E36BF269-7F5D-4DE7-99B0-14567F9CD6B3}
77+
{69E31075-F14E-1DE2-1D6E-D934A5C0480F} = {E36BF269-7F5D-4DE7-99B0-14567F9CD6B3}
7878
EndGlobalSection
7979
GlobalSection(ExtensibilityGlobals) = postSolution
8080
SolutionGuid = {E5E0FFF6-54C3-4BA1-91F3-EF3513A18D5D}

examples/HttpClientToCurl.Sample.InConsole/ApiCaller.cs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@ namespace HttpClientToCurl.Sample.InConsole;
55

66
public static class ApiCaller
77
{
8+
// Create an instance of HttpClient
9+
private static readonly HttpClient Client = new();
10+
private const string ApiUrl = "https://jsonplaceholder.typicode.com/posts";
11+
812
public static async Task MakeApiCall()
913
{
10-
string apiUrl = "https://jsonplaceholder.typicode.com/posts";
11-
12-
// Create an instance of HttpClient
13-
HttpClient client = new();
14-
1514
try
1615
{
1716
// Create a sample JSON payload
18-
string jsonPayload =
19-
"{\"title\":\"New Post\",\"body\":\"This is the body of the new post\",\"userId\":1}";
17+
string requestBody = /*lang=json,strict*/ @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
2018

2119
// Create HttpRequestMessage with the POST verb
22-
HttpRequestMessage request = new(HttpMethod.Post, apiUrl);
20+
HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, ApiUrl);
2321

2422
// Set up the request headers
25-
request.Headers.Add("Authorization", "Bearer YourAccessToken"); // Add any necessary headers
23+
httpRequestMessage.Headers.Add("Authorization", "Bearer YourAccessToken"); // Add any necessary headers
2624

2725
// Set the request content with the JSON payload
28-
request.Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
26+
httpRequestMessage.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
2927

30-
// Log the curl command for debugging or testing.
31-
// This generates a curl command that can be imported into Postman.
32-
// Use it to check and compare against all the requirements.
28+
/* Generate a curl command and print it in the console for debugging or testing.
29+
This command can be imported into Postman for checking and comparing against all the requirements. */
3330

34-
client.GenerateCurlInConsole(request);
31+
// *** First Scenario ***
32+
GenerateCurlByHttpClient(httpRequestMessage);
33+
// *** Second Scenario ***
34+
GenerateCurlByHttpRequestMessage(httpRequestMessage);
3535

3636
// Send the request
37-
HttpResponseMessage response = await client.SendAsync(request);
37+
HttpResponseMessage response = await Client.SendAsync(httpRequestMessage);
3838

3939
// Check if the request was successful (status code 200-299)
4040
if (response.IsSuccessStatusCode)
@@ -53,4 +53,42 @@ public static async Task MakeApiCall()
5353
Console.WriteLine($"Exception: {ex.Message}");
5454
}
5555
}
56+
57+
#region << Private Methods >>
58+
59+
private static void GenerateCurlByHttpClient(HttpRequestMessage httpRequestMessage)
60+
{
61+
Console.WriteLine("* Generate Curl By HttpClient:");
62+
63+
// config is optional
64+
Client.GenerateCurlInConsole(httpRequestMessage, config =>
65+
{
66+
// Customize console configuration if needed
67+
config.TurnOn = true; // Enable generating curl command to the console
68+
config.NeedAddDefaultHeaders = true; // Specify if default headers should be included
69+
config.EnableCodeBeautification = true;
70+
config.EnableCompression = false;
71+
});
72+
73+
Console.WriteLine();
74+
}
75+
76+
private static void GenerateCurlByHttpRequestMessage(HttpRequestMessage httpRequestMessage)
77+
{
78+
Console.WriteLine("* Generate Curl By HttpRequestMessage:");
79+
80+
// config is optional
81+
httpRequestMessage.GenerateCurlInConsole(new Uri(ApiUrl), config =>
82+
{
83+
// Customize console configuration if needed
84+
config.TurnOn = true; // Enable generating curl command to the console
85+
config.NeedAddDefaultHeaders = true; // Specify if default headers should be included
86+
config.EnableCodeBeautification = true;
87+
config.EnableCompression = false;
88+
});
89+
90+
Console.WriteLine();
91+
}
92+
93+
#endregion << Private Methods >>
5694
}

examples/HttpClientToCurl.Sample.InConsole/HttpClientToCurl.Sample.InConsole.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

examples/HttpClientToCurl.Sample.InFile/ApiCaller.cs

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,36 @@ namespace HttpClientToCurl.Sample.InFile;
55

66
public static class ApiCaller
77
{
8+
// Create an instance of HttpClient
9+
private static readonly HttpClient Client = new();
10+
private const string ApiUrl = "https://jsonplaceholder.typicode.com/posts";
11+
812
public static async Task MakeApiCall()
913
{
10-
string apiUrl = "https://jsonplaceholder.typicode.com/posts";
11-
12-
// Create an instance of HttpClient
13-
HttpClient client = new();
14-
1514
try
1615
{
1716
// Create a sample JSON payload
18-
string jsonPayload =
19-
"{\"title\":\"New Post\",\"body\":\"This is the body of the new post\",\"userId\":1}";
17+
string requestBody = /*lang=json,strict*/ @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
2018

2119
// Create HttpRequestMessage with the POST verb
22-
HttpRequestMessage request = new(HttpMethod.Post, apiUrl);
20+
HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, ApiUrl);
2321

2422
// Set up the request headers
25-
request.Headers.Add("Authorization", "Bearer YourAccessToken"); // Add any necessary headers
23+
httpRequestMessage.Headers.Add("Authorization", "Bearer YourAccessToken"); // Add any necessary headers
2624

2725
// Set the request content with the JSON payload
28-
request.Content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
26+
httpRequestMessage.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
2927

30-
// Generate a curl command and write it to a file for debugging or testing.
31-
// This command can be imported into Postman for checking and comparing against all the requirements.
32-
// config is optional
33-
client.GenerateCurlInFile(request, config =>
34-
{
35-
// Customize file configuration if needed
36-
config.TurnOn = true; // Enable generating curl command to file
37-
config.Filename = "curl_commands.txt"; // Specify the file name
38-
config.Path = "C:\\Path\\To\\Directory"; // Specify the directory path
39-
config.NeedAddDefaultHeaders = true; // Specify if default headers should be included
40-
});
28+
/* Generate a curl command and write it to a file for debugging or testing.
29+
This command can be imported into Postman for checking and comparing against all the requirements. */
30+
31+
// *** First Scenario ***
32+
GenerateCurlByHttpClient(httpRequestMessage);
33+
// *** Second Scenario ***
34+
GenerateCurlByHttpRequestMessage(httpRequestMessage);
4135

4236
// Send the request
43-
HttpResponseMessage response = await client.SendAsync(request);
37+
HttpResponseMessage response = await Client.SendAsync(httpRequestMessage);
4438

4539
// Check if the request was successful (status code 200-299)
4640
if (response.IsSuccessStatusCode)
@@ -59,4 +53,44 @@ public static async Task MakeApiCall()
5953
Console.WriteLine($"Exception: {ex.Message}");
6054
}
6155
}
56+
57+
#region << Private Methods >>
58+
59+
private static void GenerateCurlByHttpClient(HttpRequestMessage httpRequestMessage)
60+
{
61+
Console.WriteLine("* Generate Curl By HttpClient:");
62+
63+
// config is optional
64+
Client.GenerateCurlInFile(httpRequestMessage, config =>
65+
{
66+
// Customize file configuration if needed
67+
config.TurnOn = true; // Enable generating curl command to file
68+
config.NeedAddDefaultHeaders = true; // Specify if default headers should be included
69+
config.Filename = "curl_commands"; // Specify the file name
70+
config.Path = @"C:\Path\To\Directory"; // Specify the directory path !!
71+
});
72+
73+
Console.WriteLine("Done.");
74+
Console.WriteLine();
75+
}
76+
77+
private static void GenerateCurlByHttpRequestMessage(HttpRequestMessage httpRequestMessage)
78+
{
79+
Console.WriteLine("* Generate Curl By HttpRequestMessage:");
80+
81+
// config is optional
82+
httpRequestMessage.GenerateCurlInFile(new Uri(ApiUrl), config =>
83+
{
84+
// Customize file configuration if needed
85+
config.TurnOn = true; // Enable generating curl command to file
86+
config.NeedAddDefaultHeaders = true; // Specify if default headers should be included
87+
config.Filename = "curl_commands"; // Specify the file name
88+
config.Path = @"C:\Path\To\Directory"; // Specify the directory path !!
89+
});
90+
91+
Console.WriteLine("Done.");
92+
Console.WriteLine();
93+
}
94+
95+
#endregion << Private Methods >>
6296
}

0 commit comments

Comments
 (0)