Fixing sonarcloud issues

This commit is contained in:
2025-06-19 19:29:05 +02:00
parent 1fc8e6cc1c
commit e03db76496
62 changed files with 152 additions and 129 deletions

23
.editorconfig Normal file
View File

@@ -0,0 +1,23 @@
# top-most EditorConfig file
root = true
# Core EditorConfig properties
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.cs]
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_rule.types.symbols = types
dotnet_naming_rule.types.style = pascal_case
dotnet_naming_rule.types.severity = warning
csharp_prefer_braced_block = true:suggestion
csharp_preserve_single_line_blocks = true
csharp_style_expression_bodied_methods = when_on_single_line:suggestion

View File

@@ -66,7 +66,7 @@ public class AuthController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(AuthenticatedUser)); Assert.IsInstanceOfType(result.Data, typeof(AuthenticatedUser));
} }
else else
@@ -103,7 +103,7 @@ public class AuthController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -173,7 +173,7 @@ public class AuthController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -212,7 +212,7 @@ public class AuthController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else

View File

@@ -75,7 +75,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(RoleDto)); Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
} }
else else
@@ -110,7 +110,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -172,7 +172,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -207,7 +207,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else
@@ -260,7 +260,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(RoleDto)); Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
} }
else else
@@ -302,7 +302,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.AreEqual("Invalid name", result.Message); Assert.AreEqual("Invalid name", result.Message);
} }
else else
@@ -346,7 +346,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -396,8 +396,8 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.IsTrue(result.Message == "Not created"); Assert.AreEqual("Not created", result.Message);
} }
else else
{ {
@@ -446,7 +446,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -499,7 +499,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else
@@ -560,7 +560,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -622,7 +622,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -657,7 +657,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else
@@ -713,7 +713,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(RoleDto)); Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
} }
else else
@@ -791,7 +791,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.AreEqual("Invalid name", result.Message); Assert.AreEqual("Invalid name", result.Message);
} }
else else
@@ -837,7 +837,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.IsTrue(result.Message == "This role is not editable"); Assert.IsTrue(result.Message == "This role is not editable");
} }
else else
@@ -879,7 +879,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -927,7 +927,7 @@ public class RoleController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -981,7 +981,7 @@ public class RoleController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else

View File

@@ -85,7 +85,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(UserDto)); Assert.IsInstanceOfType(result.Data, typeof(UserDto));
} }
else else
@@ -120,7 +120,7 @@ public class UserController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -182,7 +182,7 @@ public class UserController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -217,7 +217,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else
@@ -270,7 +270,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status200OK); Assert.AreEqual(StatusCodes.Status200OK, result.Status);
Assert.IsInstanceOfType(result.Data, typeof(UserDto)); Assert.IsInstanceOfType(result.Data, typeof(UserDto));
} }
else else
@@ -316,7 +316,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.IsTrue(result.Message == "Invalid email"); Assert.IsTrue(result.Message == "Invalid email");
} }
else else
@@ -367,7 +367,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.IsTrue(result.Message == "Role not found"); Assert.IsTrue(result.Message == "Role not found");
} }
else else
@@ -412,7 +412,7 @@ public class UserController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
// else // else
@@ -467,8 +467,8 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
Assert.IsTrue(result.Message == "Not created"); Assert.AreEqual("Not created", result.Message);
} }
else else
{ {
@@ -520,7 +520,7 @@ public class UserController_Tests
// var result = (BaseResponse<object>)response.Value; // var result = (BaseResponse<object>)response.Value;
// if (result != null) // if (result != null)
// { // {
// Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest); // Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
// Console.WriteLine(JsonConvert.SerializeObject(result)); // Console.WriteLine(JsonConvert.SerializeObject(result));
// Assert.IsTrue(result.Message == "Request is not well formed"); // Assert.IsTrue(result.Message == "Request is not well formed");
// } // }
@@ -582,7 +582,7 @@ public class UserController_Tests
var result = (BaseResponse<object>)response.Value; var result = (BaseResponse<object>)response.Value;
if (result != null) if (result != null)
{ {
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError); Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
Assert.AreEqual("Something went wrong. Unexpected error", result.Message); Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
} }
else else

View File

@@ -366,7 +366,7 @@ public class UserService_Tests
var user = await _userService.UpdateUserPasswordAsync(_user!, "this-is-a-new-password"); var user = await _userService.UpdateUserPasswordAsync(_user!, "this-is-a-new-password");
Assert.IsInstanceOfType(user, typeof(User)); Assert.IsInstanceOfType(user, typeof(User));
Assert.IsNotNull(user); Assert.IsNotNull(user);
Assert.IsTrue(user.Password != oldPassword); Assert.AreNotEqual(user.Password, oldPassword);
} }
else else
{ {
@@ -424,7 +424,7 @@ public class UserService_Tests
var user = await _userService.UpdateUserRoleAsync(_user!, role); var user = await _userService.UpdateUserRoleAsync(_user!, role);
Assert.IsInstanceOfType(user, typeof(User)); Assert.IsInstanceOfType(user, typeof(User));
Assert.IsNotNull(user); Assert.IsNotNull(user);
Assert.IsTrue(user.Role?.Id != oldRole?.Id); Assert.AreNotEqual(user.Role?.Id, oldRole?.Id);
} }
else else
{ {

View File

@@ -67,9 +67,9 @@ namespace BasicDotnetTemplate.MainProject.Controllers
{ {
try try
{ {
if (await this._roleService.CheckIfNameIsValid(request.Data.Name)) if (await this._roleService.CheckIfNameIsValid(request!.Data!.Name))
{ {
var role = await this._roleService.CreateRoleAsync(request.Data); var role = await this._roleService.CreateRoleAsync(request!.Data);
if (role == null || String.IsNullOrEmpty(role.Guid)) if (role == null || String.IsNullOrEmpty(role.Guid))
{ {
@@ -121,8 +121,8 @@ namespace BasicDotnetTemplate.MainProject.Controllers
} }
if ( if (
await this._roleService.CheckIfNameIsValid(request.Data.Name) || await this._roleService.CheckIfNameIsValid(request!.Data!.Name) ||
await this._roleService.CheckIfNameIsValid(request.Data.Name, guid) await this._roleService.CheckIfNameIsValid(request!.Data!.Name, guid)
) )
{ {
role = await this._roleService.UpdateRoleAsync(request.Data, role); role = await this._roleService.UpdateRoleAsync(request.Data, role);

View File

@@ -73,13 +73,13 @@ namespace BasicDotnetTemplate.MainProject.Controllers
{ {
if (await this._userService.CheckIfEmailIsValid(request!.Data!.Email)) if (await this._userService.CheckIfEmailIsValid(request!.Data!.Email))
{ {
var role = await this._roleService.GetRoleForUser(request.Data.RoleGuid); var role = await this._roleService.GetRoleForUser(request!.Data!.RoleGuid);
if (role == null) if (role == null)
{ {
return BadRequest("Role not found"); return BadRequest("Role not found");
} }
var user = await this._userService.CreateUserAsync(request.Data, role); var user = await this._userService.CreateUserAsync(request!.Data, role);
if (user == null || String.IsNullOrEmpty(user.Guid)) if (user == null || String.IsNullOrEmpty(user.Guid))
{ {

View File

@@ -1,4 +1,4 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable

View File

@@ -1,4 +1,4 @@
using NLog; using NLog;
using BasicDotnetTemplate.MainProject.Models.Settings; using BasicDotnetTemplate.MainProject.Models.Settings;
using System.Reflection; using System.Reflection;
using BasicDotnetTemplate.MainProject.Utils; using BasicDotnetTemplate.MainProject.Utils;