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
29 changes: 29 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Run tests
run: dotnet test --no-build --configuration Release --verbosity normal
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
Releases/
!releases/
x64/
x86/
[Ww][Ii][Nn]32/
Expand All @@ -33,6 +34,7 @@ ScaffoldingReadMe.txt

# NuGet Packages
*.nupkg
!releases/*.nupkg
# NuGet Symbol Packages
*.snupkg

Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<LangVersion>13</LangVersion>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14</LangVersion>

</PropertyGroup>

</Project>
</Project>
15 changes: 13 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.11" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<!-- Coverlet -->
<PackageVersion Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<!-- Microsoft -->
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<!-- Shouldly -->
<PackageVersion Include="Shouldly" Version="4.3.0" />
<!-- xUnit -->
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
</Project>
10 changes: 8 additions & 2 deletions RestExceptions.slnx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Solution>
<Folder Name="/examples/">
<Project Path="examples\RestExceptions.Demo\RestExceptions.Demo.csproj" Type="C#" />
<Project Path="examples\RestExceptions.Demo\RestExceptions.Demo.csproj" />
</Folder>
<Folder Name="/solution/">
<File Path=".editorconfig" />
Expand All @@ -13,7 +13,13 @@
<File Path=".github/CODEOWNERS" />
<File Path="README.md" />
</Folder>
<Folder Name="/solution/git/workflows/">
<File Path=".github/workflows/CI.yml" />
</Folder>
<Folder Name="/src/">
<Project Path="src\RestExceptions\RestExceptions.csproj" Type="C#" />
<Project Path="src\RestExceptions\RestExceptions.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/RestExceptions.IntegrationTests/RestExceptions.IntegrationTests.csproj" />
</Folder>
</Solution>
3 changes: 3 additions & 0 deletions examples/RestExceptions.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@
app.UseHttpsRedirection();

app.Run();

// Needed so WebApplicationFactory<T> in tests can find the entry point
public partial class Program;
Binary file added releases/RestExceptions.10.0.0.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.11.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.7.1.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.7.2.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.7.3.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.7.4.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.7.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.8.nupkg
Binary file not shown.
Binary file added releases/RestExceptions.9.0.9.nupkg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class BadRequestRestException(
{
public static string DefaultMessage => "Malformed request syntax.";

public override string Title => "Bad request";
public override string Title => "Bad Request";
public override HttpStatusCode StatusCode => HttpStatusCode.BadRequest;
}
9 changes: 2 additions & 7 deletions src/RestExceptions/RestExceptions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<PackageId>RestExceptions</PackageId>
<Title>RestExceptions</Title>
<Version>9.0.11</Version>
<Version>10.0.0</Version>

<Authors>Stratis-Dermanoutsos</Authors>
<Company>Stratis-OSS</Company>
Expand All @@ -16,17 +16,12 @@
<Description>Extensible Web API middleware that maps all exceptions to standardized RFC7807-compliant HTTP responses.</Description>
<PackageTags>open-source http oss rest errors csharp dotnet exceptions problem-details rfc7807</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>* Updated dependencies to latest versions.
<PackageReleaseNotes>* Upgraded to .NET 10 and C# 14.
</PackageReleaseNotes>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup>
<!-- Required to have the AddProblemDetails extension -->
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
14 changes: 14 additions & 0 deletions tests/RestExceptions.IntegrationTests/ApiFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc.Testing;

namespace RestExceptions.IntegrationTests;

public class ApiFactory : WebApplicationFactory<Program>
{
public HttpClient CreateHttpsClient()
{
return CreateClient(new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri("https://localhost")
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing"/>
<PackageReference Include="Shouldly"/>
<PackageReference Include="xunit"/>
<PackageReference Include="xunit.runner.visualstudio"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\examples\RestExceptions.Demo\RestExceptions.Demo.csproj" />
<ProjectReference Include="..\..\src\RestExceptions\RestExceptions.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Net.Http.Json;
using Microsoft.AspNetCore.Mvc;

// ReSharper disable once CheckNamespace
namespace RestExceptions.IntegrationTests.Services;

public abstract class ApiTests(ApiFactory factory)
{
protected readonly HttpClient Client = factory.CreateHttpsClient();

protected async Task<ProblemDetails?> GetProblemDetailsAsync(string path, int statusCode)
{
var resp = await Client.GetAsync(Path.Join(path, statusCode.ToString()));

var result = await resp.Content.ReadFromJsonAsync<ProblemDetails>();
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Shouldly;

namespace RestExceptions.IntegrationTests.Services;

public class RestExceptionsTests(ApiFactory factory) : ApiTests(factory), IClassFixture<ApiFactory>
{
[Theory]
[InlineData(0, "Internal Server Error")]
[InlineData(400, "Bad Request")]
[InlineData(401, "Unauthorized")]
[InlineData(402, "Payment Required")]
[InlineData(403, "Forbidden")]
[InlineData(404, "Not Found")]
[InlineData(405, "Method Not Allowed")]
[InlineData(406, "Not Acceptable")]
[InlineData(407, "Proxy Authentication Required")]
[InlineData(408, "Request Timeout")]
[InlineData(409, "Conflict")]
[InlineData(410, "Gone")]
[InlineData(411, "Length Required")]
[InlineData(412, "Precondition Failed")]
[InlineData(413, "Content Too Large")]
[InlineData(414, "URI Too Long")]
[InlineData(415, "Unsupported Media Type")]
[InlineData(416, "Range Not Satisfiable")]
[InlineData(417, "Expectation Failed")]
[InlineData(421, "Misdirected Request")]
[InlineData(422, "Unprocessable Content")]
[InlineData(423, "Locked")]
[InlineData(424, "Failed Dependency")]
[InlineData(426, "Upgrade Required")]
[InlineData(428, "Precondition Required")]
[InlineData(429, "Too Many Requests")]
[InlineData(431, "Request Header Fields Too Large")]
[InlineData(451, "Unavailable For Legal Reasons")]
[InlineData(500, "Internal Server Error")]
[InlineData(501, "Not Implemented")]
[InlineData(502, "Bad Gateway")]
[InlineData(503, "Service Unavailable")]
[InlineData(504, "Gateway Timeout")]
[InlineData(505, "HTTP Version Not Supported")]
[InlineData(506, "Variant Also Negotiates")]
[InlineData(507, "Insufficient Storage")]
[InlineData(508, "Loop Detected")]
[InlineData(510, "Not Extended")]
[InlineData(511, "Network Authentication Required")]
public async Task Status_Code_To_Http_Error_Title(int statusCode, string expected)
{
// Act
var problemDetails = await GetProblemDetailsAsync("error", statusCode);
var result = problemDetails?.Title ?? string.Empty;

// Assert
result.ShouldBe(expected);
}
}