|
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; |
4 | 5 |
|
5 | | -namespace HttpClientToCurl.Builder; |
| 6 | +namespace HttpClientToCurlGeneratorTest.UnitTest.MediaTypes.Json; |
6 | 7 |
|
7 | | -public static class Generator |
| 8 | +public class FailedCurlGeneratorTests |
8 | 9 | { |
9 | | - public static string GenerateCurl(HttpClient httpClient, HttpRequestMessage httpRequestMessage, BaseConfig config) |
| 10 | + [Fact] |
| 11 | + public void GenerateCurl_When_HttpMethod_Is_Invalid() |
10 | 12 | { |
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}"; |
14 | 15 |
|
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) |
19 | 18 | { |
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) |
26 | 20 | }; |
| 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)); |
27 | 31 | } |
28 | 32 | } |
0 commit comments