Fixing coverage
This commit is contained in:
@@ -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,36 +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()
|
||||||
{
|
{
|
||||||
@@ -114,37 +81,18 @@ public class UserService_Tests
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task CheckIfEmailIsValid_EmailNotExists()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var valid = await userService.CheckIfEmailIsValid(_user.Email ?? String.Empty);
|
|
||||||
Assert.IsTrue(valid);
|
|
||||||
}
|
|
||||||
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 CreateUserAsync_Success()
|
public async Task CreateUserAsync_Success()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userService = TestUtils.CreateUserService();
|
var userService = TestUtils.CreateUserService();
|
||||||
|
var roleService = TestUtils.CreateRoleService();
|
||||||
var expectedUser = ModelsInit.CreateUser();
|
var expectedUser = ModelsInit.CreateUser();
|
||||||
|
|
||||||
|
var valid = await userService.CheckIfEmailIsValid(expectedUser.Email ?? String.Empty);
|
||||||
|
Assert.IsTrue(valid);
|
||||||
|
|
||||||
CreateUserRequestData data = new CreateUserRequestData()
|
CreateUserRequestData data = new CreateUserRequestData()
|
||||||
{
|
{
|
||||||
FirstName = expectedUser.FirstName ?? String.Empty,
|
FirstName = expectedUser.FirstName ?? String.Empty,
|
||||||
@@ -166,128 +114,34 @@ 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;
|
|
||||||
|
|
||||||
}
|
var user_role = await roleService.GetRoleByGuidAsync(user.Role?.Guid ?? String.Empty);
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
Assert.Fail($"An exception was thrown: {ex}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task CheckIfEmailIsValid_EmailCurrentUser()
|
valid = await userService.CheckIfEmailIsValid(user.Email, user.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]
|
valid = await userService.CheckIfEmailIsValid(user.Email, Guid.NewGuid().ToString());
|
||||||
public async Task CheckIfEmailIsValid_EmailAlreadyExists()
|
|
||||||
{
|
|
||||||
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]
|
|
||||||
public async Task GetUserByIdAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
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]
|
var user_by_id = await userService.GetUserByIdAsync(user.Id);
|
||||||
public async Task GetUserByGuidAsync()
|
Assert.IsNotNull(user_by_id);
|
||||||
{
|
Assert.IsTrue(user.Id == user_by_id.Id);
|
||||||
try
|
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
var user_by_guid = await userService.GetUserByGuidAsync(user.Guid);
|
||||||
if (userService != null)
|
Assert.IsNotNull(user_by_guid);
|
||||||
{
|
Assert.IsTrue(user.Guid == user_by_guid.Guid);
|
||||||
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]
|
|
||||||
public async Task DeleteUser()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var userService = TestUtils.CreateUserService();
|
|
||||||
if (userService != null)
|
|
||||||
{
|
|
||||||
var user = await userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
|
|
||||||
Assert.IsNotNull(user);
|
|
||||||
var deleted = await userService.DeleteUserAsync(user);
|
var deleted = await userService.DeleteUserAsync(user);
|
||||||
Assert.IsTrue(deleted);
|
Assert.IsTrue(deleted);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
Assert.IsNotNull(user_role);
|
||||||
Assert.Fail($"UserService is null");
|
deleted = await roleService.DeleteRoleAsync(user_role);
|
||||||
}
|
Assert.IsTrue(deleted);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -296,18 +150,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