From 39b7f4f3b3fc73b4ed0f7039f6a0aeaae8e604ed Mon Sep 17 00:00:00 2001 From: csimonapastore Date: Sat, 4 May 2024 19:29:44 +0200 Subject: [PATCH] Fixing SonarCloud integration + fixing CodeSmells - 2 --- .github/workflows/build.yml | 3 ++- MainProject/Controllers/BaseController.cs | 4 ++-- MainProject/MainProject.csproj | 4 ++++ MainProject/Models/Api/Response/BaseResponse.cs | 3 ++- MainProject/Program.cs | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e876868..b03fd70 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,6 +44,7 @@ jobs: shell: powershell run: | .\.sonar\scanner\dotnet-sonarscanner begin /k:"csimonapastore_BasicDotnetTemplate" /o:"csimonapastore-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" + dotnet restore dotnet build --no-incremental - dotnet test --collect "Code Coverage" + dotnet test ./MainProject.Tests/MainProject.Tests.csproj --collect "XPlat Code Coverage" --results-directory TestResults/ --logger "trx;LogFileName=unit_test_sonar.trx" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" diff --git a/MainProject/Controllers/BaseController.cs b/MainProject/Controllers/BaseController.cs index e95890b..2fa623a 100644 --- a/MainProject/Controllers/BaseController.cs +++ b/MainProject/Controllers/BaseController.cs @@ -10,7 +10,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers protected readonly IConfiguration _configuration; protected readonly AppSettings _appSettings; - public BaseController( + protected BaseController( IConfiguration configuration ) { @@ -20,7 +20,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } #nullable enable - private BaseResponse CreateResponse(HttpStatusCode status, string message, object? data = null) + private static BaseResponse CreateResponse(HttpStatusCode status, string message, object? data = null) { return new BaseResponse() { diff --git a/MainProject/MainProject.csproj b/MainProject/MainProject.csproj index 74e83bf..b180db7 100644 --- a/MainProject/MainProject.csproj +++ b/MainProject/MainProject.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/MainProject/Models/Api/Response/BaseResponse.cs b/MainProject/Models/Api/Response/BaseResponse.cs index 619d2ad..040427b 100644 --- a/MainProject/Models/Api/Response/BaseResponse.cs +++ b/MainProject/Models/Api/Response/BaseResponse.cs @@ -3,8 +3,9 @@ namespace BasicDotnetTemplate.MainProject.Models.Api.Response; public class BaseResponse { public int Status { get; set; } - public string Message { get; set; } #nullable enable + public string? Message { get; set; } + public object? Data { get; set; } #nullable disable } \ No newline at end of file diff --git a/MainProject/Program.cs b/MainProject/Program.cs index 07224d2..d102c13 100644 --- a/MainProject/Program.cs +++ b/MainProject/Program.cs @@ -8,7 +8,7 @@ using System.Reflection; namespace BasicDotnetTemplate.MainProject; -public class ReflectionProgram +public static class ReflectionProgram { public static MethodInfo LaunchConfiguration() { @@ -25,7 +25,7 @@ public class ReflectionProgram initialize = m; } } - return initialize; + return initialize!; } }