Roles #21

Merged
csimonapastore merged 36 commits from roles into main 2025-03-26 23:52:19 +01:00
Showing only changes of commit 8f98ee5954 - Show all commits

View File

@@ -10,7 +10,7 @@ namespace BasicDotnetTemplate.MainProject.Tests;
public class UserService_Tests public class UserService_Tests
{ {
private static User _user = ModelsInit.CreateUser(); private static User _user = ModelsInit.CreateUser();
private static Role? _role; private static Role _role = ModelsInit.CreateRole();
[TestMethod] [TestMethod]
public void Inizialize() public void Inizialize()
@@ -200,108 +200,113 @@ public class UserService_Tests
} }
} }
// [TestMethod] [TestMethod]
// public async Task CheckIfEmailIsValid_EmailAlreadyExists() public async Task CheckIfEmailIsValid_EmailAlreadyExists()
// { {
// try try
// { {
// if (_userService != null) var userService = TestUtils.CreateUserService();
// { if (userService != null)
// var valid = await _userService.CheckIfEmailIsValid(_expectedUser?.Email ?? String.Empty); {
// Assert.IsFalse(valid); var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty);
// } Assert.IsFalse(valid);
// else }
// { else
// Assert.Fail($"UserService is null"); {
// } Assert.Fail($"UserService is null");
// } }
// catch (Exception ex) }
// { catch (Exception ex)
// Console.WriteLine(ex.InnerException); {
// Assert.Fail($"An exception was thrown: {ex}"); Console.WriteLine(ex.InnerException);
// } Assert.Fail($"An exception was thrown: {ex}");
// } }
}
// [TestMethod] [TestMethod]
// public async Task GetUserByIdAsync() public async Task GetUserByIdAsync()
// { {
// try try
// { {
// if (_userService != null) var userService = TestUtils.CreateUserService();
// { if (userService != null)
// var user = await _userService.GetUserByIdAsync(_user?.Id ?? 0); {
// Assert.IsNotNull(user); var user = await userService.GetUserByIdAsync(_user.Id);
// Assert.IsTrue(user.Id == _user?.Id); Assert.IsNotNull(user);
// } Assert.IsTrue(user.Id == _user?.Id);
// else }
// { else
// Assert.Fail($"UserService is null"); {
// } Assert.Fail($"UserService is null");
// } }
// catch (Exception ex) }
// { catch (Exception ex)
// Console.WriteLine(ex.InnerException); {
// Assert.Fail($"An exception was thrown: {ex}"); Console.WriteLine(ex.InnerException);
// } Assert.Fail($"An exception was thrown: {ex}");
// } }
}
// [TestMethod] [TestMethod]
// public async Task GetUserByGuidAsync() public async Task GetUserByGuidAsync()
// { {
// try try
// { {
// if (_userService != null) var userService = TestUtils.CreateUserService();
// { if (userService != null)
// var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty); {
// Assert.IsNotNull(user); var user = await userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
// Assert.IsTrue(user.Guid == _user?.Guid); Assert.IsNotNull(user);
// } Assert.IsTrue(user.Guid == _user?.Guid);
// else }
// { else
// Assert.Fail($"UserService is null"); {
// } Assert.Fail($"UserService is null");
// } }
// catch (Exception ex) }
// { catch (Exception ex)
// Console.WriteLine(ex.InnerException); {
// Assert.Fail($"An exception was thrown: {ex}"); Console.WriteLine(ex.InnerException);
// } Assert.Fail($"An exception was thrown: {ex}");
// } }
}
// [TestMethod] [TestMethod]
// public async Task DeleteUser() public async Task DeleteUser()
// { {
// try try
// { {
// if (_userService != null) var userService = TestUtils.CreateUserService();
// { if (userService != null)
// var user = await _userService.GetUserByGuidAsync(_user?.Guid ?? String.Empty); {
// Assert.IsNotNull(user); var user = await userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
// var deleted = await _userService.DeleteUserAsync(user); Assert.IsNotNull(user);
// Assert.IsTrue(deleted); var deleted = await userService.DeleteUserAsync(user);
// } Assert.IsTrue(deleted);
// else }
// { else
// Assert.Fail($"UserService is null"); {
// } Assert.Fail($"UserService is null");
// } }
// catch (Exception ex) }
// { catch (Exception ex)
// Console.WriteLine(ex.InnerException); {
// Assert.Fail($"An exception was thrown: {ex}"); Console.WriteLine(ex.InnerException);
// } Assert.Fail($"An exception was thrown: {ex}");
// } }
}
// [TestCleanup] [TestCleanup]
// public static async Task CleanupAsync() public static async Task CleanupAsync()
// { {
// var role = await _roleService?.GetRoleByGuidAsync(_role?.Guid ?? String.Empty); var roleService = TestUtils.CreateRoleService();
// Assert.IsNotNull(role); var role = await roleService.GetRoleByGuidAsync(_role.Guid ?? String.Empty);
// var deleted = await _roleService?.DeleteRoleAsync(role); Assert.IsNotNull(role);
// Assert.IsTrue(deleted); var deleted = await roleService.DeleteRoleAsync(role);
// } Assert.IsTrue(deleted);
}
} }