Skip to content

Commit 30aa8d3

Browse files
authored
Update FailedCurlGeneratorTests.cs
1 parent f35be87 commit 30aa8d3

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
using HttpClientToCurl.Builder.Concrete;
2-
using HttpClientToCurl.Builder.Interface;
3-
using HttpClientToCurl.Config;
1+
using System.Net.Mime;
2+
using System.Text;
3+
using HttpClientToCurl.Builder;
4+
using Xunit;
45

5-
namespace HttpClientToCurl.Builder;
6+
namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Json;
67

7-
public static class Generator
8+
public class FailedCurlGeneratorTests
89
{
9-
public static string GenerateCurl(HttpClient httpClient, HttpRequestMessage httpRequestMessage, BaseConfig config)
10+
[Fact]
11+
public void GenerateCurl_When_HttpMethod_Is_Invalid()
1012
{
11-
var builder = GetBuilder(httpRequestMessage.Method);
12-
return builder.CreateCurl(httpClient, httpRequestMessage, config);
13-
}
13+
// Arrange
14+
string requestBody = /*lang=json,strict*/ @"{""name"":""russel"",""requestId"":10001004,""amount"":50000}";
1415

15-
private static IBuilder GetBuilder(HttpMethod method)
16-
{
17-
string methodName = method.Method;
18-
return methodName switch
16+
var requestUri = "api/test";
17+
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Trace, requestUri)
1918
{
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."),
19+
Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json)
2620
};
21+
httpRequestMessage.Headers.Add("Authorization", "Bearer 4797c126-3f8a-454a-aff1-96c0220dae61");
22+
23+
using var httpClient = new HttpClient();
24+
httpClient.BaseAddress = new Uri("http://localhost:1213/v1/");
25+
26+
// Act - Assert
27+
Assert.Throws<Exception>(() => Generator.GenerateCurl(
28+
httpClient,
29+
httpRequestMessage,
30+
null));
2731
}
2832
}

0 commit comments

Comments
 (0)