Adding tests

This commit is contained in:
2025-03-26 23:43:44 +01:00
parent 9f595779ee
commit c9390479bb
5 changed files with 132 additions and 39 deletions

View File

@@ -19,6 +19,7 @@ public interface IRoleService
public class RoleService : BaseService, IRoleService
{
private readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public RoleService(
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
@@ -92,14 +93,22 @@ public class RoleService : BaseService, IRoleService
{
Role? role = null;
using (var transaction = _sqlServerContext.Database.BeginTransactionAsync())
using var transaction = await _sqlServerContext.Database.BeginTransactionAsync();
try
{
var tempRole = this.CreateRoleData(data);
await _sqlServerContext.Roles.AddAsync(tempRole);
await _sqlServerContext.SaveChangesAsync();
await (await transaction).CommitAsync();
await transaction.CommitAsync();
role = tempRole;
}
catch (Exception exception)
{
await transaction.RollbackAsync();
Logger.Error(exception, $"[RoleService][CreateRoleAsync]");
throw;
}
return role;
}