Skip to content

Commit

Permalink
Merge pull request #3 from redbridge-uk/net7
Browse files Browse the repository at this point in the history
Moving to net 7
  • Loading branch information
binarysenator authored Dec 6, 2022
2 parents 4d2235e + 271ac5d commit 20435bb
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup .NET 6
- name: Setup .NET 7
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
Expand Down
11 changes: 5 additions & 6 deletions Redbridge.WebApi.Tests/Redbridge.WebApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Moq" Version="4.18.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Redbridge.SDK" Version="2.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Redbridge.WebApi.Tests/TestExceptionLoggerFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Redbridge.Exceptions;
using Redbridge.WebApi.Filters;

Expand Down
1 change: 1 addition & 0 deletions Redbridge.WebApi.Tests/TestUnknownEntityException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Redbridge.Data;
Expand Down
1 change: 1 addition & 0 deletions Redbridge.WebApi.Tests/TestValidationExceptionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Redbridge.Exceptions;
using Redbridge.Threading;
using Redbridge.Web.Messaging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Web.Http;
using System.Web.Http.ExceptionHandling;
using Microsoft.Extensions.Logging;
using Redbridge.Diagnostics;
using Redbridge.WebApi.Filters;
using Redbridge.WebApi.Handlers;
Expand All @@ -14,15 +15,15 @@ public static void InstallExceptionFilters(this HttpConfiguration configuration,
if (logger == null) throw new ArgumentNullException(nameof(logger));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

logger.WriteDebug("Installing exception filters...");
logger.LogDebug("Installing exception filters...");
configuration.Filters.Add(new ValidationExceptionFilterAttribute(logger));
configuration.Filters.Add(new UnknownEntityExceptionFilterAttribute(logger));
configuration.Filters.Add(new UserNotAuthenticatedExceptionFilterAttribute());
configuration.Filters.Add(new UserNotAuthorizedExceptionFilterAttribute(logger));
configuration.Filters.Add(new LoggingExceptionFilterAttribute(logger));
configuration.MessageHandlers.Add(new NotFoundCustomMessageHandler());

logger.WriteDebug("Installing exception logger...");
logger.LogDebug("Installing exception logger...");
configuration.Services.Replace(typeof(IExceptionLogger), new UnhandledExceptionLogger(logger));
}
}
Expand Down
6 changes: 3 additions & 3 deletions Redbridge.WebApi/Filters/LoggingExceptionFilterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Net;
using System.Net.Http;
using System.Web.Http.Filters;
using Redbridge.Diagnostics;
using Microsoft.Extensions.Logging;

namespace Redbridge.WebApi.Filters
{
Expand All @@ -20,7 +20,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
{
if (actionExecutedContext.Exception != null)
{
_logger.WriteInfo($"Logging that an exception has occurred in LoggingExceptionFilter: {actionExecutedContext.Exception.Message}...");
_logger.LogInformation($"Logging that an exception has occurred in LoggingExceptionFilter: {actionExecutedContext.Exception.Message}...");
var messagePhrase = actionExecutedContext.Exception.Message ?? "Internal server error - no additional detail supplied";
messagePhrase = string.Join(",", messagePhrase.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Where(s => !string.IsNullOrWhiteSpace(s))); // Carriage returns are not permitted in reason phrases.

Expand All @@ -31,7 +31,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
};

actionExecutedContext.Response = response;
_logger.WriteException(actionExecutedContext.Exception);
_logger.LogError(actionExecutedContext.Exception.Message, actionExecutedContext.Exception);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Redbridge.WebApi/Filters/UnhandledExceptionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.ExceptionHandling;
using Redbridge.Diagnostics;
using Microsoft.Extensions.Logging;

namespace Redbridge.WebApi.Filters
{
Expand All @@ -17,10 +17,10 @@ public UnhandledExceptionLogger(ILogger logger)

public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
_logger.WriteInfo("Logging (only) unhandled exceptions...");
_logger.LogInformation("Logging (only) unhandled exceptions...");

if (context.Exception != null)
_logger.WriteException(context.Exception);
_logger.LogError(context.Exception.Message, context.Exception);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Redbridge.Data;
using Redbridge.Diagnostics;

Expand All @@ -21,7 +22,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
{
if (actionExecutedContext.Exception is UnknownEntityException unknownEntityException)
{
_logger.WriteInfo($"Unknown entity exception processing with message {unknownEntityException.Message}");
_logger.LogInformation($"Unknown entity exception processing with message {unknownEntityException.Message}");

var errorMessageError = new HttpError(unknownEntityException.Message);
// Only a single result issue.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using System.Net.Http;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Redbridge.Diagnostics;
using Redbridge.Exceptions;

Expand All @@ -17,7 +18,7 @@ public UserNotAuthorizedExceptionFilterAttribute(ILogger logger)

public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
_logger.WriteInfo("Checking exception for user not authorized exception filtering....");
_logger.LogInformation("Checking exception for user not authorized exception filtering....");

var exception = actionExecutedContext.Exception as UserNotAuthorizedException;

Expand Down
17 changes: 8 additions & 9 deletions Redbridge.WebApi/Filters/ValidationExceptionFilterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Net.Http;
using System.Text;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Redbridge.Diagnostics;
using Redbridge.Exceptions;
using Redbridge.Validation;

Expand All @@ -18,14 +18,13 @@ public class ValidationExceptionFilterAttribute : ExceptionFilterAttribute

public ValidationExceptionFilterAttribute(ILogger logger)
{
if (logger == null) throw new ArgumentNullException(nameof(logger));
_logger = logger;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
// Convert ValidationResultsException results or a ValidationException into ValidationResults
_logger.WriteInfo("Checking exception for validation exception filtering....");
_logger.LogInformation("Checking exception for validation exception filtering....");

ValidationResult[] results;
var validationResultsException = actionExecutedContext.Exception as ValidationResultsException;
Expand All @@ -34,7 +33,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext

if (validationResultsException != null)
{
_logger.WriteInfo("Validation exception filtering being applied to a multi-results exception...");
_logger.LogInformation("Validation exception filtering being applied to a multi-results exception...");
if (validationResultsException.Results?.Results != null)
results = validationResultsException.Results.Results.ToArray();
else
Expand All @@ -45,23 +44,23 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
}
else if (validationException != null)
{
_logger.WriteInfo("Validation exception filtering being applied to a single result validation exception...");
_logger.LogInformation("Validation exception filtering being applied to a single result validation exception...");
results = new[] { new ValidationResult(false, validationException.Message) };
reasonPhrase = validationException.Message;
}
else
{
_logger.WriteDebug("Validation exception filtering skipped.");
_logger.LogDebug("Validation exception filtering skipped.");
return;
}

_logger.WriteInfo("Serializing results into JSON for transmission...");
_logger.LogInformation("Serializing results into JSON for transmission...");
var rawJson = JsonConvert.SerializeObject(results, new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});

_logger.WriteDebug($"Setting JSON result on response message: {rawJson} with code 422.");
_logger.LogDebug($"Setting JSON result on response message: {rawJson} with code 422.");
actionExecutedContext.Response = new HttpResponseMessage((HttpStatusCode)422)
{
ReasonPhrase = string.Join(",", reasonPhrase.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Where(s => !string.IsNullOrWhiteSpace(s))),
Expand Down
4 changes: 2 additions & 2 deletions Redbridge.WebApi/Redbridge.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Owin" Version="4.2.2" />
<PackageReference Include="Microsoft.Owin.Host.SystemWeb" Version="4.2.2" />
<PackageReference Include="Redbridge.ApiManagement" Version="2.2.1" />
<PackageReference Include="Redbridge.SDK" Version="2.2.1" />
<PackageReference Include="Redbridge.ApiManagement" Version="7.0.0" />
<PackageReference Include="Redbridge.SDK" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 8 additions & 5 deletions Redbridge.WebApiCore.Tests/Redbridge.WebApiCore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

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

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public UserNotAuthorizedExceptionFilter(ILogger<UserNotAuthorizedExceptionFilter

public override void OnException(ExceptionContext actionExecutedContext)
{
_logger.LogInformation("Checking exception for user not authorized exception filtering....");

if (actionExecutedContext.Exception is UserNotAuthorizedException exception)
{
actionExecutedContext.ExceptionHandled = true;
Expand Down
8 changes: 4 additions & 4 deletions Redbridge.WebApiCore/Redbridge.WebApiCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand All @@ -10,9 +10,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="6.0.10" />
<PackageReference Include="Redbridge.ApiManagement" Version="2.2.1" />
<PackageReference Include="Redbridge.SDK" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="7.0.0" />
<PackageReference Include="Redbridge.ApiManagement" Version="7.0.0" />
<PackageReference Include="Redbridge.SDK" Version="7.0.0" />
</ItemGroup>

</Project>

0 comments on commit 20435bb

Please sign in to comment.