From b86a54b1be257c7f0885731eb8833a697700af1a Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sun, 12 Feb 2023 15:37:31 +0100 Subject: [PATCH] :gear: :broom: Clean up smells and security hotspot, set up code coverage --- .github/workflows/build.yml | 9 ++++++++- cat_cafe/Controllers/CatsController.cs | 5 ----- cat_cafe/Controllers/CustomersController.cs | 5 ----- cat_cafe/Dto/CustomerDto.cs | 2 +- cat_cafe/Entities/Cat.cs | 2 +- cat_cafe/Program.cs | 2 -- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1242a8c..6a965f9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,13 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} shell: powershell run: | - .\.sonar\scanner\dotnet-sonarscanner begin /k:"draialexis_cat_cafe" /o:"draialexis" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" + .\.sonar\scanner\dotnet-sonarscanner begin + /k:"draialexis_cat_cafe" + /o:"draialexis" + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" + /d:sonar.host.url="https://sonarcloud.io" + /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml dotnet build cat_cafe\cat_cafe.sln + dotnet build --no-incremental + dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file diff --git a/cat_cafe/Controllers/CatsController.cs b/cat_cafe/Controllers/CatsController.cs index 734dbc5..b8881b7 100644 --- a/cat_cafe/Controllers/CatsController.cs +++ b/cat_cafe/Controllers/CatsController.cs @@ -123,10 +123,5 @@ namespace cat_cafe.Controllers return NoContent(); } - - private bool CatExists(long id) - { - return _context.Cats.Any(e => e.Id == id); - } } } diff --git a/cat_cafe/Controllers/CustomersController.cs b/cat_cafe/Controllers/CustomersController.cs index 89ff88e..b4e0f49 100644 --- a/cat_cafe/Controllers/CustomersController.cs +++ b/cat_cafe/Controllers/CustomersController.cs @@ -129,10 +129,5 @@ namespace cat_cafe.Controllers return Ok(); } - - private bool CustomerExists(long id) - { - return _context.Customers.Any(e => e.Id == id); - } } } diff --git a/cat_cafe/Dto/CustomerDto.cs b/cat_cafe/Dto/CustomerDto.cs index 7a029e7..658be04 100644 --- a/cat_cafe/Dto/CustomerDto.cs +++ b/cat_cafe/Dto/CustomerDto.cs @@ -6,7 +6,7 @@ namespace cat_cafe.Dto { public long Id { get; set; } [Required] - public string FullName { get; set; } + public string FullName { get; set; } = ""; [Required] public int Age { get; set; } = 0; } diff --git a/cat_cafe/Entities/Cat.cs b/cat_cafe/Entities/Cat.cs index 6d6ac23..089c9cd 100644 --- a/cat_cafe/Entities/Cat.cs +++ b/cat_cafe/Entities/Cat.cs @@ -10,6 +10,6 @@ namespace cat_cafe.Entities public int Age { get; set; } = 0; public long? BarId { get; set; } public Bar? Bar { get; set; } - public string Meow() { return "meow"; } + public static string Meow { get; set; } = "meow"; } } diff --git a/cat_cafe/Program.cs b/cat_cafe/Program.cs index bbb6902..38f73ff 100644 --- a/cat_cafe/Program.cs +++ b/cat_cafe/Program.cs @@ -6,8 +6,6 @@ using System.Net.WebSockets; var builder = WebApplication.CreateBuilder(args); -Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.File("log.txt").CreateLogger(); - List _sockets = new(); // Add services to the container. -- 2.36.3