Skip to content

Commit f35be87

Browse files
authored
Update FailedCurlGeneratorTests.cs
1 parent 7fda28a commit f35be87

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed
Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
1-
// using FluentAssertions;
2-
// using System.Net.Mime;
3-
// using System.Text;
4-
// using HttpClientToCurl.Builder;
5-
// using Xunit;
6-
//
7-
// namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Json;
8-
//
9-
// public class FailedCurlGeneratorTests
10-
// {
11-
// [Fact]
12-
// public void GenerateCurl_When_HttpMethod_Is_Invalid()
13-
// {
14-
// // Arrange
15-
// string requestBody = /*lang=json,strict*/ @"{""name"":""russel"",""requestId"":10001004,""amount"":50000}";
16-
//
17-
// var requestUri = "api/test";
18-
// var httpRequestMessage = new HttpRequestMessage(HttpMethod.Trace, requestUri) { Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json) };
19-
// httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61");
20-
//
21-
// using var httpClient = new HttpClient();
22-
// httpClient.BaseAddress = new Uri("http://localhost:1213/v1/");
23-
//
24-
// // Act
25-
// string script = Generator.GenerateCurl(
26-
// httpClient,
27-
// httpRequestMessage,
28-
// null);
29-
//
30-
// // Assert
31-
// script.Should().NotBeNullOrEmpty();
32-
// script.Should().StartWith("GenerateCurlError => not supported");
33-
// script.Trim().Should().BeEquivalentTo($"GenerateCurlError => not supported {httpRequestMessage.Method.Method} by HttpClientToCurl!");
34-
// }
35-
// }
1+
using HttpClientToCurl.Builder.Concrete;
2+
using HttpClientToCurl.Builder.Interface;
3+
using HttpClientToCurl.Config;
4+
5+
namespace HttpClientToCurl.Builder;
6+
7+
public static class Generator
8+
{
9+
public static string GenerateCurl(HttpClient httpClient, HttpRequestMessage httpRequestMessage, BaseConfig config)
10+
{
11+
var builder = GetBuilder(httpRequestMessage.Method);
12+
return builder.CreateCurl(httpClient, httpRequestMessage, config);
13+
}
14+
15+
private static IBuilder GetBuilder(HttpMethod method)
16+
{
17+
string methodName = method.Method;
18+
return methodName switch
19+
{
20+
"GET" => new HttpGetBuilder(),
21+
"POST" => new HttpPostBuilder(),
22+
"PUT" => new HttpPutBuilder(),
23+
"PATCH" => new HttpPatchBuilder(),
24+
"DELETE" => new HttpDeleteBuilder(),
25+
_ => throw new Exception($"HTTP method {method} is not supported."),
26+
};
27+
}
28+
}

0 commit comments

Comments
 (0)