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
8 changes: 3 additions & 5 deletions .github/workflows/template-build-test-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-target-framework: ["net8.0", "net9.0"]
dotnet-target-framework: ["net10.0"]
include:
- dotnet-install-framework: 8.0.x
dotnet-target-framework: net8.0
- dotnet-install-framework: 10.0.x
dotnet-target-framework: net10.0

- dotnet-install-framework: 9.0.x
dotnet-target-framework: net9.0
env:
source-directory: ${{ inputs.source-directory }}
source-project: ${{ inputs.source-project }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/template-build-test-solution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest

env:
dotnet-install-framework: 9.0.x
dotnet-install-framework: 10.0.x

defaults:
run:
Expand Down
26 changes: 9 additions & 17 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
</PropertyGroup>

<ItemGroup Label="Microsoft NuGet Packages (All Frameworks)">
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.6" />
</ItemGroup>

<ItemGroup Label="Microsoft NuGet Packages (Source)" Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.17" />
</ItemGroup>

<ItemGroup Label="Microsoft NuGet Packages (Source)" Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.0" />
</ItemGroup>

<ItemGroup Label="Microsoft NuGet Packages (Test)">
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="xunit.v3" Version="3.1.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>

<ItemGroup Label="External Testing Packages">
<PackageVersion Include="Bogus" Version="35.6.3" />
<PackageVersion Include="FluentAssertions" Version="[7.0.0]" />
<PackageVersion Include="Moq" Version="[4.18.4]" />
<PackageVersion Include="Bogus" Version="35.6.5" />
<PackageVersion Include="Moq" Version="[4.20.72]" />
<PackageVersion Include="BlazorFocused.Testing.Logging" Version="1.0.0" />
</ItemGroup>

Expand Down
13 changes: 6 additions & 7 deletions samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
</PropertyGroup>

<ItemGroup Label="Microsoft NuGet Packages (Source)">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
</ItemGroup>

<ItemGroup Label="Microsoft NuGet Packages (Test)">
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.6" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="xunit.v3" Version="3.1.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
</ItemGroup>

<ItemGroup Label="External Testing Packages">
<PackageVersion Include="Bogus" Version="35.6.3" />
<PackageVersion Include="FluentAssertions" Version="[7.0.0]" />
<PackageVersion Include="Moq" Version="[4.18.4]" />
<PackageVersion Include="Bogus" Version="35.6.5" />
<PackageVersion Include="Moq" Version="[4.20.72]" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand All @@ -10,7 +10,7 @@
<PackageReference Include="Bogus" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Text.Json;
using System.Web;
using BlazorFocused.Exceptions.Middleware;
using Xunit.Abstractions;

namespace MiddlewareSample.Api.Test;

Expand All @@ -38,7 +37,7 @@ public async Task ShouldReturnProperStatusCodes()

string url = $"/ThrowCustomClientException?statusCode={(int)expectedStatusCode}";

HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url);
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url, TestContext.Current.CancellationToken);

testOutputHelper.WriteLine("Expected Status Code: {0}", httpResponseMessage.StatusCode);

Expand All @@ -52,7 +51,7 @@ public async Task ShouldReturnAmbiguousForRandomException()
{
string url = "/ThrowRandomException";

HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url);
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url, TestContext.Current.CancellationToken);

ProblemDetails problemDetails = await GetProblemDetailsAsync(httpResponseMessage);

Expand All @@ -73,7 +72,7 @@ public async Task ShouldReturnRuntimeExceptionStatusCodeException()

string url = $"/ThrowCustomClientException?statusCode={(int)expectedStatusCode}&message={expectedMessage}";

HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url);
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url, TestContext.Current.CancellationToken);

ProblemDetails problemDetails = await GetProblemDetailsAsync(httpResponseMessage);

Expand All @@ -95,7 +94,7 @@ public async Task ShouldReturnClientSpecificExceptionMessage()

string url = $"/ThrowCustomClientException?statusCode={(int)expectedStatusCode}&message={internalExceptionMessage}&clientMessage={expectedClientMessage}";

HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url);
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url, TestContext.Current.CancellationToken);

ProblemDetails problemDetails = await GetProblemDetailsAsync(httpResponseMessage);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
6 changes: 2 additions & 4 deletions samples/MiddlewareSample/MiddlewareSample.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
app.MapGet("/ThrowRandomException", () =>
{
throw new RandomException();
})
.WithOpenApi();
});

app.MapGet("/ThrowCustomClientException", (
[FromQuery] HttpStatusCode? statusCode,
Expand All @@ -65,8 +64,7 @@
};

throw exception;
})
.WithOpenApi();
});

app.Run();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Label="NuGet Metadata">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
// Licensed under the MIT License
// -------------------------------------------------------

using BlazorFocused.Exceptions.Middleware.ApplicationBuilder;
using BlazorFocused.Exceptions.Middleware.ExceptionBuilder;
using Bogus;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using BlazorFocused.Exceptions.Middleware.ApplicationBuilder;
using BlazorFocused.Exceptions.Middleware.ExceptionBuilder;

namespace BlazorFocused.Exceptions.Middleware.Test.ApplicationBuilder;

Expand All @@ -37,7 +36,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationKeyDuringError()

requestDelegateMock.Setup(request =>
request.Invoke(httpContext))
.ThrowsAsync(thrownException);
.ThrowsAsync(thrownException);

Exception actualException =
await Record.ExceptionAsync(() =>
Expand All @@ -50,7 +49,7 @@ await Record.ExceptionAsync(() =>
ProblemDetails actualErrorResponse = await GetErrorResponseFromBody<ProblemDetails>(memoryStream);

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Key and default Guid Value
Assert.True(httpContext.Response.Headers.ContainsKey(expectedCorrelationHeader));
Expand Down Expand Up @@ -89,7 +88,7 @@ await Record.ExceptionAsync(() =>
NullLogger<ApplicationBuilderMiddleware>.Instance));

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Key and default Guid Value
Assert.True(httpContext.Response.Headers.ContainsKey(expectedCorrelationHeader));
Expand All @@ -110,7 +109,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationValueDuringError()

var exceptionsMiddlewareOptions = new ExceptionsMiddlewareOptions
{
ConfigureCorrelationValue = (context) => context.TraceIdentifier
ConfigureCorrelationValue = context => context.TraceIdentifier
};

// IOptionsMonitor should not be called
Expand All @@ -119,7 +118,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationValueDuringError()

requestDelegateMock.Setup(request =>
request.Invoke(httpContext))
.ThrowsAsync(thrownException);
.ThrowsAsync(thrownException);

Exception actualException =
await Record.ExceptionAsync(() =>
Expand All @@ -132,10 +131,11 @@ await Record.ExceptionAsync(() =>
ProblemDetails actualErrorResponse = await GetErrorResponseFromBody<ProblemDetails>(memoryStream);

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Correlation Value
Assert.Equal(expectedCorrelationValue, httpContext.Response.Headers[exceptionsMiddlewareOptions.CorrelationKey]);
Assert.Equal(expectedCorrelationValue,
httpContext.Response.Headers[exceptionsMiddlewareOptions.CorrelationKey]);

Assert.Equal(exceptionsMiddlewareOptions.DefaultErrorMessage, actualErrorResponse.Detail);
Assert.Equal(expectedInstance, actualErrorResponse.Instance);
Expand All @@ -156,7 +156,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationValueWithoutError()

var exceptionsMiddlewareOptions = new ExceptionsMiddlewareOptions
{
ConfigureCorrelationValue = (context) => context.TraceIdentifier
ConfigureCorrelationValue = context => context.TraceIdentifier
};

// IOptionsMonitor should not be called
Expand All @@ -172,10 +172,11 @@ await Record.ExceptionAsync(() =>
NullLogger<ApplicationBuilderMiddleware>.Instance));

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Correlation Value
Assert.Equal(expectedCorrelationValue, httpContext.Response.Headers[exceptionsMiddlewareOptions.CorrelationKey]);
Assert.Equal(expectedCorrelationValue,
httpContext.Response.Headers[exceptionsMiddlewareOptions.CorrelationKey]);
Assert.Equal(200, httpContext.Response.StatusCode);
}

Expand All @@ -194,7 +195,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationKeyAndValueDuringError
var exceptionsMiddlewareOptions = new ExceptionsMiddlewareOptions
{
CorrelationKey = expectedCorrelationHeader,
ConfigureCorrelationValue = (context) => context.TraceIdentifier
ConfigureCorrelationValue = context => context.TraceIdentifier
};

// IOptionsMonitor should not be called
Expand All @@ -203,7 +204,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationKeyAndValueDuringError

requestDelegateMock.Setup(request =>
request.Invoke(httpContext))
.ThrowsAsync(thrownException);
.ThrowsAsync(thrownException);

Exception actualException =
await Record.ExceptionAsync(() =>
Expand All @@ -216,7 +217,7 @@ await Record.ExceptionAsync(() =>
ProblemDetails actualErrorResponse = await GetErrorResponseFromBody<ProblemDetails>(memoryStream);

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Correlation Value
Assert.Equal(expectedCorrelationValue, httpContext.Response.Headers[expectedCorrelationHeader]);
Expand All @@ -242,7 +243,7 @@ public async Task Invoke_ShouldReturnConfiguredCorrelationKeyAndValueWithoutErro
var exceptionsMiddlewareOptions = new ExceptionsMiddlewareOptions
{
CorrelationKey = expectedCorrelationHeader,
ConfigureCorrelationValue = (context) => context.TraceIdentifier
ConfigureCorrelationValue = context => context.TraceIdentifier
};

// IOptionsMonitor should not be called
Expand All @@ -258,7 +259,7 @@ await Record.ExceptionAsync(() =>
NullLogger<ApplicationBuilderMiddleware>.Instance));

// Should be null since error is caught
actualException.Should().BeNull();
Assert.Null(actualException);

// Check Correlation Value
Assert.Equal(expectedCorrelationValue, httpContext.Response.Headers[expectedCorrelationHeader]);
Expand Down
Loading