Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Setup .NET
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'

Expand All @@ -27,7 +27,7 @@ jobs:
run: dotnet build ./*/Infra.Http.Api.slnx --no-restore -c Release

- name: Test Infra.Http.Api
run: dotnet test ./*/Infra.Http.Api.slnx --no-restore -c Release
run: dotnet test ./*/Infra.Http.Api.slnx --no-build --no-restore -c Release

- name: Pack Infra.Http.Api
run: dotnet pack ./*/Infra.Http.Api.slnx --no-build -o ~/nuget -c Release
Expand Down
6 changes: 3 additions & 3 deletions src/Api.Contract/Api.Contract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<NoWarn>$(NoWarn);IDE0130;CA1859</NoWarn>
<RootNamespace>GarageGroup.Infra</RootNamespace>
<AssemblyName>GarageGroup.Infra.Http.Api.Contract</AssemblyName>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PrimeFuncPack.Core.Failure" Version="2.2.0" />
<PackageReference Include="PrimeFuncPack.Core.FlatArray" Version="1.5.1" />
<PackageReference Include="PrimeFuncPack.Core.FlatArray" Version="1.6.0" />
<PackageReference Include="PrimeFuncPack.Core.Result" Version="2.0.2" />
<PackageReference Include="PrimeFuncPack.Primitives.Strings" Version="3.0.0" />
<PackageReference Include="System.Memory.Data" Version="10.0.6" />
<PackageReference Include="System.Memory.Data" Version="10.0.8" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Api.Test/Api.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="8.0.1">
<PackageReference Include="coverlet.collector" Version="10.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
20 changes: 19 additions & 1 deletion src/Api.Test/Test.HttpApi/HttpApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,22 @@ private static HttpResponseMessage CreateResponse(

return response;
}
}

private static bool ContainsHeader(FlatArray<KeyValuePair<string, string>> headers, string key, string value)
{
foreach (var header in headers)
{
if (string.Equals(header.Key, key, StringComparison.InvariantCultureIgnoreCase) is false)
{
continue;
}

if (string.Equals(header.Value, value, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}

return false;
}
}
22 changes: 10 additions & 12 deletions src/Api.Test/Test.HttpApi/Test.Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ partial class HttpApiTest
[Theory]
[MemberData(nameof(SuccessCaseTestData))]
public static async Task SendAsync_ResponseIsSuccess_ExpectMappedSuccess(
HttpSuccessType successType,
int statusCode,
string? reasonPhrase,
bool hasHeaders,
bool hasBody)
HttpSuccessType successType, int statusCode, string? reasonPhrase, bool hasHeaders, bool hasBody)
{
var source = CreateApi(
sendAsync: (_, _) =>
Expand Down Expand Up @@ -44,9 +40,8 @@ public static async Task SendAsync_ResponseIsSuccess_ExpectMappedSuccess(

if (hasHeaders)
{
Assert.Equal(1, success.Headers.Length);
Assert.True(string.Equals(success.Headers[0].Key, "x-request-id", StringComparison.InvariantCultureIgnoreCase));
Assert.Equal("abc", success.Headers[0].Value);
Assert.True(ContainsHeader(success.Headers, "x-request-id", "abc"));
Assert.True(ContainsHeader(success.Headers, "Content-Type", "application/json; charset=utf-8"));
}
else
{
Expand Down Expand Up @@ -97,16 +92,19 @@ public static async Task SendAsync_ResponseIsFailure_ExpectMappedFailure(

Assert.Equal((HttpFailureCode)statusCode, failure.StatusCode);
Assert.Equal(reasonPhrase, failure.ReasonPhrase);
Assert.Equal(1, failure.Headers.Length);
Assert.True(string.Equals(failure.Headers[0].Key, "x-request-id", StringComparison.InvariantCultureIgnoreCase));
Assert.Equal("abc", failure.Headers[0].Value);
Assert.True(ContainsHeader(failure.Headers, "x-request-id", "abc"));

if (body is null)
{
Assert.Equal(default, failure.Body);
return;
}

if (string.IsNullOrWhiteSpace(mediaType) is false)
{
Assert.True(ContainsHeader(failure.Headers, "Content-Type", $"{mediaType}; charset={charSet}"));
}

Assert.Equal(mediaType, failure.Body.Type.MediaType);
Assert.Equal(charSet, failure.Body.Type.CharSet);
Assert.Equal(body, failure.Body.Content?.ToString());
Expand Down Expand Up @@ -206,4 +204,4 @@ public static async Task SendAsync_InputBodyIsEmpty_ExpectRequestWithoutContent(

Assert.False(hasContent);
}
}
}
6 changes: 3 additions & 3 deletions src/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<NoWarn>$(NoWarn);IDE0130;CA1859</NoWarn>
<RootNamespace>GarageGroup.Infra</RootNamespace>
<AssemblyName>GarageGroup.Infra.Http.Api</AssemblyName>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,8 +23,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.6" />
<PackageReference Include="PrimeFuncPack.Dependency" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.8" />
<PackageReference Include="PrimeFuncPack.Dependency" Version="2.2.0" />
</ItemGroup>

</Project>
31 changes: 22 additions & 9 deletions src/Api/Api/HttpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,29 @@ private static void SetBody(HttpRequestMessage httpRequest, HttpBody body)
}
}

private static IEnumerable<KeyValuePair<string, string>> GetHeaders(HttpResponseMessage httpResponse)
{
foreach (var header in httpResponse.Headers)
{
foreach (var value in header.Value)
private static IEnumerable<KeyValuePair<string, string>> GetHeaders(HttpResponseMessage httpResponse)
{
foreach (var header in httpResponse.Headers)
{
foreach (var value in header.Value)
{
yield return new(header.Key, value);
}
}
}
yield return new(header.Key, value);
}
}

if (httpResponse.Content is null)
{
yield break;
}

foreach (var header in httpResponse.Content.Headers)
{
foreach (var value in header.Value)
{
yield return new(header.Key, value);
}
}
}

private static async Task<HttpBody> ReadBodyAsync(HttpContent httpContent, CancellationToken cancellationToken)
{
Expand Down