Roles #21

Merged
csimonapastore merged 36 commits from roles into main 2025-03-26 23:52:19 +01:00
2 changed files with 39 additions and 12 deletions
Showing only changes of commit fdf97c7c42 - Show all commits

View File

@@ -187,7 +187,7 @@ public class RoleService_Tests
} }
[TestMethod] [TestMethod]
public async Task DeleteRole() public async Task DeleteRoleAsync()
{ {
try try
{ {

View File

@@ -9,29 +9,20 @@ namespace BasicDotnetTemplate.MainProject.Tests;
[TestClass] [TestClass]
public class UserService_Tests public class UserService_Tests
{ {
private static User? _expectedUser;
private static User? _user; private static User? _user;
private static Role? _role; private static Role? _role;
private static UserService? _userService;
private static RoleService? _roleService;
[TestInitialize]
public void Setup()
{
_expectedUser = ModelsInit.CreateUser();
_userService = TestUtils.CreateUserService();
_roleService = TestUtils.CreateRoleService();
}
[TestMethod] [TestMethod]
public void Inizialize() public void Inizialize()
{ {
try try
{ {
var _userService = TestUtils.CreateUserService();
if (_userService != null) if (_userService != null)
{ {
Assert.IsInstanceOfType(_userService, typeof(UserService)); Assert.IsInstanceOfType(_userService, typeof(UserService));
} }
else else
{ {
@@ -50,6 +41,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
var testString = "test"; var testString = "test";
if (_userService != null) if (_userService != null)
{ {
@@ -74,6 +69,9 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
var testEmail = "test@email.it"; var testEmail = "test@email.it";
var testPassword = "password"; var testPassword = "password";
@@ -100,6 +98,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty); var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty);
@@ -122,6 +124,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
CreateUserRequestData data = new CreateUserRequestData() CreateUserRequestData data = new CreateUserRequestData()
{ {
FirstName = _expectedUser?.FirstName ?? String.Empty, FirstName = _expectedUser?.FirstName ?? String.Empty,
@@ -165,6 +171,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty, _user?.Guid ?? String.Empty); var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty, _user?.Guid ?? String.Empty);
@@ -187,6 +197,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty); var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty);
@@ -209,6 +223,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var user = await _userService.GetUserByIdAsync(_user?.Id ?? 0); var user = await _userService.GetUserByIdAsync(_user?.Id ?? 0);
@@ -232,6 +250,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty); var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty);
@@ -255,6 +277,10 @@ public class UserService_Tests
{ {
try try
{ {
var _expectedUser = ModelsInit.CreateUser();
var _userService = TestUtils.CreateUserService();
var _roleService = TestUtils.CreateRoleService();
if (_userService != null) if (_userService != null)
{ {
var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty); var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty);
@@ -279,6 +305,7 @@ public class UserService_Tests
[TestCleanup] [TestCleanup]
public static async Task CleanupAsync() public static async Task CleanupAsync()
{ {
var _roleService = TestUtils.CreateRoleService();
var role = await _roleService?.GetRoleByGuidAsync(_role?.Guid ?? String.Empty); var role = await _roleService?.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
Assert.IsNotNull(role); Assert.IsNotNull(role);
var deleted = await _roleService?.DeleteRoleAsync(role); var deleted = await _roleService?.DeleteRoleAsync(role);