< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Auditing.AuditLogWriter
Assembly: ArturRios.Heimdall.Command
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Auditing/AuditLogWriter.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 34
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
WriteAsync()100%44100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Auditing/AuditLogWriter.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.Interfaces;
 2using ArturRios.Heimdall.Domain.Entities;
 3using ArturRios.Heimdall.Shared.Security;
 4
 5namespace ArturRios.Heimdall.Command.Auditing;
 6
 9837public class AuditLogWriter(IAsyncRepository<AuditLog, long> repository, IActorAccessor actorAccessor)
 8    : IAuditLogWriter
 9{
 10    /// <summary>Longest failure reason stored; matches AUDIT_LOG.failure_reason's column.</summary>
 11    private const int MaxFailureReasonLength = 500;
 12
 13    public async Task WriteAsync(string action, Guid? targetId, bool succeeded, string? failureReason)
 14    {
 98515        var entry = new AuditLog
 98516        {
 98517            PublicId = Guid.NewGuid(),
 98518            ActorPersonId = actorAccessor.ActorPersonId,
 98519            ActorRole = actorAccessor.ActorRole,
 98520            Action = action,
 98521            TargetId = targetId,
 98522            Succeeded = succeeded,
 98523            // Truncated rather than allowed to fail the insert: a reason too long for the column
 98524            // would otherwise turn a recorded refusal into no record at all, which is the one
 98525            // outcome the trail must not have.
 98526            FailureReason = failureReason is { Length: > MaxFailureReasonLength }
 98527                ? failureReason[..MaxFailureReasonLength]
 98528                : failureReason,
 98529            CreatedAt = DateTime.UtcNow
 98530        };
 31
 98532        await repository.CreateAsync(entry);
 98533    }
 34}