< Summary

Information
Class: ProjectTemplate.Infrastructure.Data.AuditEntry
Assembly: ProjectTemplate.Infrastructure
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/AuditEntry.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 92
Line coverage: 100%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_HasTemporaryProperties()100%11100%
ToAuditRecord()50%88100%
SerializeAuditValues(...)100%22100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/AuditEntry.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using System.Reflection;
 3using System.Text.Json;
 4using Microsoft.EntityFrameworkCore.ChangeTracking;
 5using ProjectTemplate.Infrastructure.Data.Entities;
 6
 7namespace ProjectTemplate.Infrastructure.Data;
 8
 319internal sealed class AuditEntry(EntityEntry entry)
 10{
 11    internal EntityEntry Entry { get; } = entry;
 12    [DataType(DataType.Text)]
 13    internal string TableName { get; set; } = string.Empty;
 14    [DataType(DataType.Text)]
 15    internal string State { get; set; } = string.Empty;
 16    [DataType(DataType.Text)]
 17    internal string Application { get; set; } = string.Empty;
 18    [DataType(DataType.Text)]
 19    internal string ModifiedBy { get; set; } = string.Empty;
 20    [DataType(DataType.Text)]
 21    internal string ActorId { get; set; } = string.Empty;
 22    [DataType(DataType.Text)]
 23    internal string ActorType { get; set; } = string.Empty;
 24    [DataType(DataType.Text)]
 25    internal string MutationBatchId { get; set; } = string.Empty;
 26    [DataType(DataType.Text)]
 27    internal string? OperationExecutionId { get; set; }
 28    [DataType(DataType.Text)]
 29    internal string? ExecutionAttemptId { get; set; }
 30    [DataType(DataType.Text)]
 31    internal string? CorrelationId { get; set; }
 32    [DataType(DataType.Text)]
 33    internal string? TraceId { get; set; }
 34    [DataType(DataType.Text)]
 35    internal string? SpanId { get; set; }
 36    [DataType(DataType.Text)]
 37    internal string? DecisionAuditRecordId { get; set; }
 38    [DataType(DataType.Text)]
 39    internal string? TenantHash { get; set; }
 40    [DataType(DataType.Text)]
 41    internal string? OrganizationHash { get; set; }
 42    [DataType(DataType.DateTime)]
 43    internal DateTime ModifiedOnUtc { get; set; }
 44    internal Dictionary<string, object> KeyValues { get; } = [];
 45    internal Dictionary<string, object> OriginalValues { get; } = [];
 46    internal Dictionary<string, object> CurrentValues { get; } = [];
 47    internal List<PropertyEntry> TemporaryProperties { get; } = [];
 48
 6049    internal bool HasTemporaryProperties => TemporaryProperties.Count != 0;
 50
 51    internal AuditRecord ToAuditRecord()
 52    {
 3153        string applicationAssembly =
 3154            Assembly.GetEntryAssembly()?.GetName().Name
 3155            ?? GetType().Assembly.GetName().Name
 3156            ?? "Unknown Assembly";
 57
 3158        AuditRecord auditRecord = new()
 3159        {
 3160            SchemaVersion = "1.0",
 3161            Entity = TableName,
 3162            State = State,
 3163            Application = string.IsNullOrWhiteSpace(Application)
 3164                ? applicationAssembly
 3165                : Application,
 3166            ModifiedBy = ModifiedBy,
 3167            ActorId = ActorId,
 3168            ActorType = ActorType,
 3169            MutationBatchId = MutationBatchId,
 3170            OperationExecutionId = OperationExecutionId,
 3171            ExecutionAttemptId = ExecutionAttemptId,
 3172            CorrelationId = CorrelationId,
 3173            TraceId = TraceId,
 3174            SpanId = SpanId,
 3175            DecisionAuditRecordId = DecisionAuditRecordId,
 3176            TenantHash = TenantHash,
 3177            OrganizationHash = OrganizationHash,
 3178            ModifiedOnUtc = ModifiedOnUtc,
 3179            KeyValues = SerializeAuditValues(KeyValues),
 3180            OriginalValues = SerializeAuditValues(OriginalValues),
 3181            CurrentValues = SerializeAuditValues(CurrentValues)
 3182        };
 3183        return auditRecord;
 84    }
 85
 86    private static string SerializeAuditValues(Dictionary<string, object> values)
 87    {
 9388        return values.Count == 0
 9389            ? string.Empty
 9390            : JsonSerializer.Serialize(values);
 91    }
 92}