Skip to content

Commit 7d18a69

Browse files
Add HttpRequestMessageToCurlTest into tests folder
1 parent 85b254e commit 7d18a69

File tree

10 files changed

+1735
-0
lines changed

10 files changed

+1735
-0
lines changed

tests/HttpClientToCurlTest/FunctionalTest/SuccessScenariosTests.cs

Lines changed: 461 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16+
<PackageReference Include="xunit" Version="2.6.3" />
17+
<PackageReference Include="xunit.core" Version="2.6.3" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\src\HttpClientToCurl\HttpClientToCurl.csproj" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Net.Mime;
2+
using System.Text;
3+
using HttpClientToCurl.Builder;
4+
using Xunit;
5+
6+
namespace HttpClientToCurlTest.UnitTest.MediaTypes.Json;
7+
8+
public class FailedCurlGeneratorTests
9+
{
10+
[Fact]
11+
public void GenerateCurl_When_HttpMethod_Is_Invalid()
12+
{
13+
// Arrange
14+
string requestBody = /*lang=json,strict*/ @"{""name"":""russel"",""requestId"":10001004,""amount"":50000}";
15+
16+
var requestUri = "api/test";
17+
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Trace, requestUri)
18+
{
19+
Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json)
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<NotSupportedException>(() => Generator.GenerateCurl(
28+
httpClient,
29+
httpRequestMessage,
30+
null));
31+
}
32+
}

0 commit comments

Comments
 (0)