Fixing SonarCloud integration + fixing CodeSmells
This commit is contained in:
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -44,5 +44,6 @@ 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 build
|
||||
dotnet build --no-incremental
|
||||
dotnet test --collect "Code Coverage"
|
||||
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
**/obj
|
||||
**/bin
|
||||
**/appsettings.*.json
|
||||
**/TestResults
|
||||
@@ -12,7 +12,7 @@ namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
public class Program_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Program_Configuration_IsValid()
|
||||
public void Program_Configuration_IsValid()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
|
||||
@@ -36,12 +36,21 @@ public class Program_Tests
|
||||
|
||||
if (execute != null)
|
||||
{
|
||||
object initializeObj = execute.Invoke(null, new object[] { });
|
||||
MethodInfo initialize = (MethodInfo)initializeObj;
|
||||
object? initializeObj = execute != null ? execute.Invoke(null, Array.Empty<object>()) : throw new ArgumentNullException("LaunchConfiguration not found");
|
||||
MethodInfo? initialize = initializeObj != null ? (MethodInfo)initializeObj : throw new ArgumentNullException("Unable to convert object because execute.Invoke is null");
|
||||
if (initialize != null)
|
||||
{
|
||||
initialize.Invoke(null, new object[] { new string[] { } });
|
||||
Assert.IsTrue(true);
|
||||
var success = false;
|
||||
try
|
||||
{
|
||||
initialize.Invoke(null, new object[] { Array.Empty<string>() });
|
||||
success = true;
|
||||
}
|
||||
catch (Exception innerException)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown during initialize.Invoke: {innerException.Message}");
|
||||
}
|
||||
Assert.IsTrue(success);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,7 +3,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
[Controller]
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
public abstract class BaseController : ControllerBase
|
||||
{
|
||||
protected readonly IConfiguration _configuration;
|
||||
@@ -56,3 +57,4 @@ public abstract class BaseController : ControllerBase
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
[Route("")]
|
||||
public class RootController : BaseController
|
||||
{
|
||||
public RootController(
|
||||
@@ -12,8 +13,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("")]
|
||||
[HttpGet("")]
|
||||
public IActionResult GetVersion()
|
||||
{
|
||||
return Success(String.Empty, "Success");
|
||||
|
||||
@@ -3,6 +3,7 @@ using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
public class VersionController : BaseController
|
||||
{
|
||||
public VersionController(
|
||||
@@ -12,8 +13,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("version")]
|
||||
[HttpGet("get")]
|
||||
public IActionResult GetVersion()
|
||||
{
|
||||
return Success(String.Empty, _appSettings?.Settings?.Version);
|
||||
|
||||
@@ -35,15 +35,11 @@ internal static class Program
|
||||
{
|
||||
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
internal static WebApplication app;
|
||||
|
||||
public static void Initialize(string[] args)
|
||||
public static WebApplication Initialize(string[] args)
|
||||
{
|
||||
Logger.Info("[Program][Main] Start building");
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
Logger.Info("[Program][Main] Creating configuration");
|
||||
|
||||
var _configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(System.AppDomain.CurrentDomain.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
@@ -113,7 +109,7 @@ internal static class Program
|
||||
options.SwaggerDoc("v1", openApiInfo);
|
||||
});
|
||||
|
||||
app = builder.Build();
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
// REGISTER MIDDLEWARE HERE
|
||||
app.UseRouting();
|
||||
@@ -136,19 +132,15 @@ internal static class Program
|
||||
});
|
||||
}
|
||||
|
||||
Logger.Info("[Program][Main] Launching app");
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ReflectionProgram.LaunchConfiguration();
|
||||
Initialize(args);
|
||||
|
||||
WebApplication app = Initialize(args);
|
||||
app.Run();
|
||||
|
||||
Logger.Info("[Program][Main] Shutting down logger");
|
||||
|
||||
NLog.LogManager.Shutdown(); // Flush and close down internal threads and timers
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user