Roles #21
@@ -64,6 +64,7 @@ public class RoleService_Tests
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var _roleService = TestUtils.CreateRoleService();
|
||||||
CreateRoleRequestData data = new CreateRoleRequestData()
|
CreateRoleRequestData data = new CreateRoleRequestData()
|
||||||
{
|
{
|
||||||
Name = _expectedRole?.Name ?? String.Empty,
|
Name = _expectedRole?.Name ?? String.Empty,
|
||||||
@@ -144,6 +145,7 @@ public class RoleService_Tests
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var _roleService = TestUtils.CreateRoleService();
|
||||||
if (_roleService != null)
|
if (_roleService != null)
|
||||||
{
|
{
|
||||||
var role = await _roleService.GetRoleByIdAsync(_role?.Id ?? 0);
|
var role = await _roleService.GetRoleByIdAsync(_role?.Id ?? 0);
|
||||||
@@ -167,6 +169,7 @@ public class RoleService_Tests
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var _roleService = TestUtils.CreateRoleService();
|
||||||
if (_roleService != null)
|
if (_roleService != null)
|
||||||
{
|
{
|
||||||
var role = await _roleService.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
|
var role = await _roleService.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
|
||||||
@@ -190,6 +193,7 @@ public class RoleService_Tests
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var _roleService = TestUtils.CreateRoleService();
|
||||||
if (_roleService != null)
|
if (_roleService != null)
|
||||||
{
|
{
|
||||||
var role = await _roleService.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
|
var role = await _roleService.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ namespace BasicDotnetTemplate.MainProject.Tests;
|
|||||||
[TestClass]
|
[TestClass]
|
||||||
public class UserService_Tests
|
public class UserService_Tests
|
||||||
{
|
{
|
||||||
private static User _user = ModelsInit.CreateUser();
|
|
||||||
private static Role _role = ModelsInit.CreateRole();
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Inizialize()
|
public void Inizialize()
|
||||||
{
|
{
|
||||||
@@ -34,35 +31,6 @@ public class UserService_Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [TestInitialize]
|
|
||||||
// public void Setup()
|
|
||||||
// {
|
|
||||||
// _expectedUser = ModelsInit.CreateUser();
|
|
||||||
// _expectedRole = ModelsInit.CreateRole();
|
|
||||||
// _roleService = TestUtils.CreateRoleService();
|
|
||||||
// _userService = TestUtils.CreateUserService();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [TestMethod]
|
|
||||||
// public void Inizialize()
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// if (_userService != null)
|
|
||||||
// {
|
|
||||||
// Assert.IsInstanceOfType(_userService, typeof(UserService));
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// Assert.Fail($"UserService is null");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine(ex.InnerException);
|
|
||||||
// Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task GetUserByUsernameAndPassword_Null()
|
public async Task GetUserByUsernameAndPassword_Null()
|
||||||
@@ -88,41 +56,16 @@ public class UserService_Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // TODO
|
|
||||||
// // [TestMethod]
|
|
||||||
// public async Task GetUserByUsernameAndPassword_Success()
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// var testEmail = "test@email.it";
|
|
||||||
// var testPassword = "password";
|
|
||||||
// if (_userService != null)
|
|
||||||
// {
|
|
||||||
// var user = await _userService.GetUserByUsernameAndPassword(testEmail, testPassword);
|
|
||||||
// Assert.IsTrue(user != null);
|
|
||||||
// Assert.IsTrue(user.Email == testEmail);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// Assert.Fail($"UserService is null");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine(ex.InnerException);
|
|
||||||
// Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task CheckIfEmailIsValid_EmailNotExists()
|
public async Task CheckIfEmailIsValid_EmailNotExists()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userService = TestUtils.CreateUserService();
|
var userService = TestUtils.CreateUserService();
|
||||||
|
var user = ModelsInit.CreateUser();
|
||||||
if (userService != null)
|
if (userService != null)
|
||||||
{
|
{
|
||||||
var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty);
|
var valid = await userService.CheckIfEmailIsValid(user.Email);
|
||||||
Assert.IsTrue(valid);
|
Assert.IsTrue(valid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -143,6 +86,7 @@ public class UserService_Tests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userService = TestUtils.CreateUserService();
|
var userService = TestUtils.CreateUserService();
|
||||||
|
var roleService = TestUtils.CreateRoleService();
|
||||||
var expectedUser = ModelsInit.CreateUser();
|
var expectedUser = ModelsInit.CreateUser();
|
||||||
|
|
||||||
CreateUserRequestData data = new CreateUserRequestData()
|
CreateUserRequestData data = new CreateUserRequestData()
|
||||||
@@ -166,129 +110,36 @@ public class UserService_Tests
|
|||||||
Assert.IsTrue(expectedUser.LastName == user.LastName);
|
Assert.IsTrue(expectedUser.LastName == user.LastName);
|
||||||
Assert.IsTrue(expectedUser.Email == user.Email);
|
Assert.IsTrue(expectedUser.Email == user.Email);
|
||||||
Assert.IsTrue(expectedUser.Role?.Name == user.Role?.Name);
|
Assert.IsTrue(expectedUser.Role?.Name == user.Role?.Name);
|
||||||
_user = user;
|
|
||||||
_role = user.Role;
|
|
||||||
|
|
||||||
}
|
User realUser = user!;
|
||||||
catch (Exception ex)
|
Role realRole = user!.Role!;
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
// CheckIfEmailIsValid_CurrentUser
|
||||||
public async Task CheckIfEmailIsValid_EmailCurrentUser()
|
var valid = await userService.CheckIfEmailIsValid(realUser.Email, realUser.Guid);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty, _user.Guid ?? String.Empty);
|
|
||||||
Assert.IsTrue(valid);
|
Assert.IsTrue(valid);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.Fail($"UserService is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
// CheckIfEmailIsValid_EmailAlreadyExists
|
||||||
public async Task CheckIfEmailIsValid_EmailAlreadyExists()
|
valid = await userService.CheckIfEmailIsValid(realUser.Email);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty);
|
|
||||||
Assert.IsFalse(valid);
|
Assert.IsFalse(valid);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.Fail($"UserService is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
//GetUserByIdAsync
|
||||||
public async Task GetUserByIdAsync()
|
var getUserById = await userService.GetUserByIdAsync(realUser.Id);
|
||||||
{
|
Assert.IsNotNull(getUserById);
|
||||||
try
|
Assert.IsTrue(getUserById.Id == realUser?.Id);
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var user = await userService.GetUserByIdAsync(_user.Id);
|
|
||||||
Assert.IsNotNull(user);
|
|
||||||
Assert.IsTrue(user.Id == _user?.Id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.Fail($"UserService is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
//GetUserByGuidAsync
|
||||||
public async Task GetUserByGuidAsync()
|
var getUserByGuid = await userService.GetUserByGuidAsync(realUser.Guid);
|
||||||
{
|
Assert.IsNotNull(getUserByGuid);
|
||||||
try
|
Assert.IsTrue(getUserByGuid.Guid == realUser?.Guid);
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var user = await userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
|
|
||||||
Assert.IsNotNull(user);
|
|
||||||
Assert.IsTrue(user.Guid == _user?.Guid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.Fail($"UserService is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
//DeleteUserAsync
|
||||||
public async Task DeleteUser()
|
var deleted = await userService.DeleteUserAsync(realUser);
|
||||||
{
|
Assert.IsTrue(deleted);
|
||||||
try
|
|
||||||
{
|
//DeleteRoleAsync
|
||||||
var userService = TestUtils.CreateUserService();
|
deleted = await roleService.DeleteRoleAsync(realRole);
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var user = await userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
|
|
||||||
Assert.IsNotNull(user);
|
|
||||||
var deleted = await userService.DeleteUserAsync(user);
|
|
||||||
Assert.IsTrue(deleted);
|
Assert.IsTrue(deleted);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.Fail($"UserService is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.InnerException);
|
Console.WriteLine(ex.InnerException);
|
||||||
@@ -296,18 +147,6 @@ public class UserService_Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public static async Task CleanupAsync()
|
|
||||||
{
|
|
||||||
var roleService = TestUtils.CreateRoleService();
|
|
||||||
var role = await roleService.GetRoleByGuidAsync(_role.Guid ?? String.Empty);
|
|
||||||
Assert.IsNotNull(role);
|
|
||||||
var deleted = await roleService.DeleteRoleAsync(role);
|
|
||||||
Assert.IsTrue(deleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user