From 9225cf3351a179c94f2b075f2089bdbf4e68dea6 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Sat, 21 Sep 2024 10:26:18 -0400 Subject: [PATCH 1/7] chore: enable nullable on projects --- Content/src/CarterService.csproj | 1 + Content/tests/CarterService.Tests.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/Content/src/CarterService.csproj b/Content/src/CarterService.csproj index 68c00dd..e400ef1 100644 --- a/Content/src/CarterService.csproj +++ b/Content/src/CarterService.csproj @@ -4,6 +4,7 @@ CarterService Exe Latest + enable diff --git a/Content/tests/CarterService.Tests.csproj b/Content/tests/CarterService.Tests.csproj index 57a5a8e..c8ce0e2 100644 --- a/Content/tests/CarterService.Tests.csproj +++ b/Content/tests/CarterService.Tests.csproj @@ -4,6 +4,7 @@ net8.0 Latest false + enable From 69deae969a763a892ff3eae8d0184d8d72292461 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Mon, 23 Sep 2024 08:58:55 -0400 Subject: [PATCH 2/7] refactor: comply with nullability enableness --- Content/src/Entities/Internal/AppSettings.cs | 8 ++++---- Content/src/Entities/Internal/FailedResponse.cs | 12 ++++++------ Content/src/Entities/Internal/HealthDefinition.cs | 8 ++++---- Content/src/Entities/Internal/RouteDefinition.cs | 4 ++-- Content/src/Extensions/TypeExtensions.cs | 2 +- Content/src/appsettings.Development.json | 3 +-- Content/src/appsettings.json | 3 +-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Content/src/Entities/Internal/AppSettings.cs b/Content/src/Entities/Internal/AppSettings.cs index 9f22759..962b820 100644 --- a/Content/src/Entities/Internal/AppSettings.cs +++ b/Content/src/Entities/Internal/AppSettings.cs @@ -5,8 +5,8 @@ /// public record AppSettings { - public CacheConfig Cache { get; init; } - public RouteDefinition RouteDefinition { get; init; } - public HealthDefinition HealthDefinition { get; init; } - public string[] ServerUrls { get; init; } + public CacheConfig Cache { get; init; } = new(); + public RouteDefinition RouteDefinition { get; init; } = new(); + public HealthDefinition HealthDefinition { get; init; } = new(); + public string[] ServerUrls { get; init; } = []; } diff --git a/Content/src/Entities/Internal/FailedResponse.cs b/Content/src/Entities/Internal/FailedResponse.cs index e3ee8e7..b5b044c 100644 --- a/Content/src/Entities/Internal/FailedResponse.cs +++ b/Content/src/Entities/Internal/FailedResponse.cs @@ -8,16 +8,16 @@ public FailedResponse(Exception ex) { Message = ex.Message; #if DEBUG - StackTrace = ex.StackTrace; - Source = ex.Source; - TargetMethod = ex.TargetSite.Name; + StackTrace = ex.StackTrace ?? string.Empty; + Source = ex.Source ?? string.Empty; + TargetMethod = ex.TargetSite?.Name ?? string.Empty; #endif } public string Message { get; set; } #if DEBUG - public string StackTrace { get; set; } - public string Source { get; set; } - public string TargetMethod { get; set; } + public string StackTrace { get; set; } = string.Empty; + public string Source { get; set; } = string.Empty; + public string TargetMethod { get; set; } = string.Empty; #endif } diff --git a/Content/src/Entities/Internal/HealthDefinition.cs b/Content/src/Entities/Internal/HealthDefinition.cs index 95dc4ce..cdeb7c2 100644 --- a/Content/src/Entities/Internal/HealthDefinition.cs +++ b/Content/src/Entities/Internal/HealthDefinition.cs @@ -2,8 +2,8 @@ public record HealthDefinition { - public string Endpoint { get; init; } - public string Name { get; init; } - public string HealthyMessage { get; init; } - public string[] Tags { get; init; } + public string Endpoint { get; init; } = string.Empty; + public string Name { get; init; } = string.Empty; + public string HealthyMessage { get; init; } = string.Empty; + public string[] Tags { get; init; } = []; } diff --git a/Content/src/Entities/Internal/RouteDefinition.cs b/Content/src/Entities/Internal/RouteDefinition.cs index 1b4186d..ad18d81 100644 --- a/Content/src/Entities/Internal/RouteDefinition.cs +++ b/Content/src/Entities/Internal/RouteDefinition.cs @@ -2,6 +2,6 @@ public record RouteDefinition { - public string RouteSuffix { get; init; } - public string Version { get; init; } + public string RouteSuffix { get; init; } = string.Empty; + public string Version { get; init; } = string.Empty; } diff --git a/Content/src/Extensions/TypeExtensions.cs b/Content/src/Extensions/TypeExtensions.cs index 8f8186a..db6a678 100644 --- a/Content/src/Extensions/TypeExtensions.cs +++ b/Content/src/Extensions/TypeExtensions.cs @@ -22,7 +22,7 @@ public static class TypeExtensions internal static Type GetAnyElementType(this Type type) { if (type.IsArray) - return type.GetElementType(); + return type.GetElementType()!; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) return type.GetGenericArguments()[0]; diff --git a/Content/src/appsettings.Development.json b/Content/src/appsettings.Development.json index 37adb80..74e85da 100644 --- a/Content/src/appsettings.Development.json +++ b/Content/src/appsettings.Development.json @@ -5,8 +5,7 @@ "WriteTo": [ { "Name": "Console" } ], - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], - "AllowedHosts": "*" + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] }, "AppSettings": { "Cache": { diff --git a/Content/src/appsettings.json b/Content/src/appsettings.json index fbfddda..3eb0eec 100644 --- a/Content/src/appsettings.json +++ b/Content/src/appsettings.json @@ -5,8 +5,7 @@ "WriteTo": [ { "Name": "Console" } ], - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], - "AllowedHosts": "*" + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] }, "AppSettings": { "Cache": { From ba0eeefd8e9aecf44ec7be50efe65acdad704f06 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 11 Oct 2024 11:50:49 -0400 Subject: [PATCH 3/7] refactor: follow dotnet format suggestions --- Content/src/Entities/Internal/AppSettings.cs | 2 +- Content/src/Entities/Internal/CacheConfig.cs | 2 +- Content/src/Entities/Internal/FailedResponse.cs | 4 ++-- Content/src/Entities/Internal/HealthDefinition.cs | 2 +- Content/src/Entities/Internal/RouteDefinition.cs | 2 +- Content/src/Extensions/HttpContextExtensions.cs | 2 +- Content/src/Extensions/WebApplicationBuilderExtensions.cs | 2 +- Content/src/Modules/HelloModule.cs | 4 ++-- Content/src/Modules/MainModule.cs | 2 +- Content/src/Program.cs | 4 ++-- Content/src/Repositories/HelloRepository.cs | 2 +- Content/src/Repositories/IHelloRepository.cs | 2 +- Content/tests/Unit/HelloTests.cs | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Content/src/Entities/Internal/AppSettings.cs b/Content/src/Entities/Internal/AppSettings.cs index 962b820..7210460 100644 --- a/Content/src/Entities/Internal/AppSettings.cs +++ b/Content/src/Entities/Internal/AppSettings.cs @@ -1,4 +1,4 @@ -namespace CarterService.Entities; +namespace CarterService.Entities.Internal; /// /// This is obtained from the appsettings.json on Startup diff --git a/Content/src/Entities/Internal/CacheConfig.cs b/Content/src/Entities/Internal/CacheConfig.cs index f4271aa..3575ab3 100644 --- a/Content/src/Entities/Internal/CacheConfig.cs +++ b/Content/src/Entities/Internal/CacheConfig.cs @@ -1,4 +1,4 @@ -namespace CarterService.Entities; +namespace CarterService.Entities.Internal; public record CacheConfig { diff --git a/Content/src/Entities/Internal/FailedResponse.cs b/Content/src/Entities/Internal/FailedResponse.cs index b5b044c..f09e899 100644 --- a/Content/src/Entities/Internal/FailedResponse.cs +++ b/Content/src/Entities/Internal/FailedResponse.cs @@ -1,6 +1,6 @@ using System; -namespace CarterService.Entities; +namespace CarterService.Entities.Internal; public record FailedResponse { @@ -9,7 +9,7 @@ public FailedResponse(Exception ex) Message = ex.Message; #if DEBUG StackTrace = ex.StackTrace ?? string.Empty; - Source = ex.Source ?? string.Empty; + Source = ex.Source ?? string.Empty; TargetMethod = ex.TargetSite?.Name ?? string.Empty; #endif } diff --git a/Content/src/Entities/Internal/HealthDefinition.cs b/Content/src/Entities/Internal/HealthDefinition.cs index cdeb7c2..7999c88 100644 --- a/Content/src/Entities/Internal/HealthDefinition.cs +++ b/Content/src/Entities/Internal/HealthDefinition.cs @@ -1,4 +1,4 @@ -namespace CarterService.Entities; +namespace CarterService.Entities.Internal; public record HealthDefinition { diff --git a/Content/src/Entities/Internal/RouteDefinition.cs b/Content/src/Entities/Internal/RouteDefinition.cs index ad18d81..8cafcb4 100644 --- a/Content/src/Entities/Internal/RouteDefinition.cs +++ b/Content/src/Entities/Internal/RouteDefinition.cs @@ -1,4 +1,4 @@ -namespace CarterService.Entities; +namespace CarterService.Entities.Internal; public record RouteDefinition { diff --git a/Content/src/Extensions/HttpContextExtensions.cs b/Content/src/Extensions/HttpContextExtensions.cs index 9245ad7..71c23da 100644 --- a/Content/src/Extensions/HttpContextExtensions.cs +++ b/Content/src/Extensions/HttpContextExtensions.cs @@ -3,7 +3,7 @@ using Carter.Cache; using Carter.ModelBinding; using Carter.Response; -using CarterService.Entities; +using CarterService.Entities.Internal; using Microsoft.AspNetCore.Http; namespace CarterService.Extensions; diff --git a/Content/src/Extensions/WebApplicationBuilderExtensions.cs b/Content/src/Extensions/WebApplicationBuilderExtensions.cs index 46c1390..efa3ed3 100644 --- a/Content/src/Extensions/WebApplicationBuilderExtensions.cs +++ b/Content/src/Extensions/WebApplicationBuilderExtensions.cs @@ -1,5 +1,5 @@ using Carter.OpenApi; -using CarterService.Entities; +using CarterService.Entities.Internal; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; diff --git a/Content/src/Modules/HelloModule.cs b/Content/src/Modules/HelloModule.cs index 3d9f3a1..855e069 100644 --- a/Content/src/Modules/HelloModule.cs +++ b/Content/src/Modules/HelloModule.cs @@ -1,8 +1,8 @@ using Carter; using Carter.OpenApi; -using CarterService.Entities; +using CarterService.Entities.Internal; using CarterService.Extensions; -using CarterService.Repository; +using CarterService.Repositories; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; diff --git a/Content/src/Modules/MainModule.cs b/Content/src/Modules/MainModule.cs index 26946fa..7ad1c02 100644 --- a/Content/src/Modules/MainModule.cs +++ b/Content/src/Modules/MainModule.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; using Carter; -using CarterService.Entities; +using CarterService.Entities.Internal; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; diff --git a/Content/src/Program.cs b/Content/src/Program.cs index 15e512a..b568d8d 100644 --- a/Content/src/Program.cs +++ b/Content/src/Program.cs @@ -1,8 +1,8 @@ using Carter; using Carter.Cache; -using CarterService.Entities; +using CarterService.Entities.Internal; using CarterService.Extensions; -using CarterService.Repository; +using CarterService.Repositories; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; diff --git a/Content/src/Repositories/HelloRepository.cs b/Content/src/Repositories/HelloRepository.cs index 2205a3d..c08be96 100644 --- a/Content/src/Repositories/HelloRepository.cs +++ b/Content/src/Repositories/HelloRepository.cs @@ -1,4 +1,4 @@ -namespace CarterService.Repository; +namespace CarterService.Repositories; public class HelloRepository : IHelloRepository { diff --git a/Content/src/Repositories/IHelloRepository.cs b/Content/src/Repositories/IHelloRepository.cs index bd76ecd..4ca4f76 100644 --- a/Content/src/Repositories/IHelloRepository.cs +++ b/Content/src/Repositories/IHelloRepository.cs @@ -1,4 +1,4 @@ -namespace CarterService.Repository; +namespace CarterService.Repositories; public interface IHelloRepository { diff --git a/Content/tests/Unit/HelloTests.cs b/Content/tests/Unit/HelloTests.cs index 5f54699..a9bdb7f 100644 --- a/Content/tests/Unit/HelloTests.cs +++ b/Content/tests/Unit/HelloTests.cs @@ -2,7 +2,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; -using CarterService.Repository; +using CarterService.Repositories; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Xunit; From a4da84ff7fc479f89d678fc64dfd7a2943c5009c Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 11 Oct 2024 12:09:29 -0400 Subject: [PATCH 4/7] actions: added steps to format code and correct build for tests --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a70aefe..10b1d5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,9 +18,13 @@ jobs: with: dotnet-version: 8.0.x - name: Build Source - run: dotnet build Content/src/CarterService.csproj -v quiet --configuration Release + run: dotnet build Content/src/CarterService.csproj --configuration Release - name: Build Tests - run: dotnet build Content/src/CarterService.csproj -v quiet --configuration Release + run: dotnet build Content/src/CarterService.Tests.csproj --configuration Release + - name: Format Source + run: dotnet format Content/src/CarterService.csproj --verify-no-changes --verbosity diagnostic + - name: Format Tests + run: dotnet format Content/src/CarterService.Tests.csproj --verify-no-changes --verbosity diagnostic - name: Test run: dotnet test Content/tests/CarterService.Tests.csproj -v quiet --configuration Release env: From 22782093ad608e4776d3ba5756a0181effae8d24 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 11 Oct 2024 12:12:08 -0400 Subject: [PATCH 5/7] action: fix tests path --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10b1d5b..2fbec01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,11 +20,11 @@ jobs: - name: Build Source run: dotnet build Content/src/CarterService.csproj --configuration Release - name: Build Tests - run: dotnet build Content/src/CarterService.Tests.csproj --configuration Release + run: dotnet build Content/tests/CarterService.Tests.csproj --configuration Release - name: Format Source run: dotnet format Content/src/CarterService.csproj --verify-no-changes --verbosity diagnostic - name: Format Tests - run: dotnet format Content/src/CarterService.Tests.csproj --verify-no-changes --verbosity diagnostic + run: dotnet format Content/tests/CarterService.Tests.csproj --verify-no-changes --verbosity diagnostic - name: Test run: dotnet test Content/tests/CarterService.Tests.csproj -v quiet --configuration Release env: From 6f0df7e626b0388d855d3e829b929ba115cf72c6 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 11 Oct 2024 12:20:05 -0400 Subject: [PATCH 6/7] action: changed from verify to format --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fbec01..12557ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,11 +22,11 @@ jobs: - name: Build Tests run: dotnet build Content/tests/CarterService.Tests.csproj --configuration Release - name: Format Source - run: dotnet format Content/src/CarterService.csproj --verify-no-changes --verbosity diagnostic + run: dotnet format Content/src/CarterService.csproj --verbosity diagnostic - name: Format Tests - run: dotnet format Content/tests/CarterService.Tests.csproj --verify-no-changes --verbosity diagnostic + run: dotnet format Content/tests/CarterService.Tests.csproj --verbosity diagnostic - name: Test - run: dotnet test Content/tests/CarterService.Tests.csproj -v quiet --configuration Release + run: dotnet test Content/tests/CarterService.Tests.csproj --configuration Release env: DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 From c3fcf02b82cdde7e9d1ac1c5b4d579653ba17a73 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 11 Oct 2024 12:25:12 -0400 Subject: [PATCH 7/7] action: moved to format under .sln --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12557ef..efda799 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,14 +17,12 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: 8.0.x + - name: Format Code + run: dotnet format analyzers Content/CarterService.sln --verbosity diagnostic - name: Build Source run: dotnet build Content/src/CarterService.csproj --configuration Release - name: Build Tests run: dotnet build Content/tests/CarterService.Tests.csproj --configuration Release - - name: Format Source - run: dotnet format Content/src/CarterService.csproj --verbosity diagnostic - - name: Format Tests - run: dotnet format Content/tests/CarterService.Tests.csproj --verbosity diagnostic - name: Test run: dotnet test Content/tests/CarterService.Tests.csproj --configuration Release env: