< Summary

Information
Class: RoleRadar.Domain.Tracking.ApplicationEvent
Assembly: RoleRadar.Domain
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/ApplicationEvent.cs
Line coverage
97%
Covered lines: 46
Uncovered lines: 1
Coverable lines: 47
Total lines: 97
Line coverage: 97.8%
Branch coverage
87%
Covered branches: 14
Total branches: 16
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_OwnerId()100%11100%
get_ApplicationId()100%11100%
get_EventDate()100%11100%
get_EventType()100%11100%
get_EventSource()100%11100%
get_Notes()100%11100%
get_CreatedAt()100%11100%
Create(...)87.5%161696.42%
Rehydrate(...)100%11100%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/ApplicationEvent.cs

#LineLine coverage
 1using System.Globalization;
 2
 3namespace RoleRadar.Domain.Tracking;
 4
 5public sealed class ApplicationEvent
 6{
 7    public const int MaxEventSourceLength = 100;
 8    public const int MaxNotesLength = 500;
 9
 522410    public Guid Id { get; init; }
 1274211    public string OwnerId { get; init; } = string.Empty;
 1005212    public Guid ApplicationId { get; init; }
 804413    public string EventDate { get; private set; } = string.Empty;
 537614    public ApplicationEventType EventType { get; private set; }
 537815    public string? EventSource { get; private set; }
 542816    public string? Notes { get; private set; }
 516417    public DateTimeOffset CreatedAt { get; init; }
 18
 19    public static ApplicationEvent Create(
 20        string ownerId,
 21        Guid applicationId,
 22        string eventDate,
 23        ApplicationEventType eventType,
 24        string? eventSource = null,
 25        string? notes = null,
 26        Guid? id = null,
 27        DateTimeOffset? now = null)
 28    {
 260229        ArgumentException.ThrowIfNullOrWhiteSpace(ownerId);
 260230        if (applicationId == Guid.Empty)
 31        {
 032            throw new ArgumentException("Application ID cannot be empty.", nameof(applicationId));
 33        }
 34
 260235        ArgumentException.ThrowIfNullOrWhiteSpace(eventDate);
 260036        if (!DateOnly.TryParseExact(eventDate.Trim(), "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, o
 37        {
 438            throw new ArgumentException($"Event date must be in YYYY-MM-DD format: '{eventDate}'.", nameof(eventDate));
 39        }
 40
 259641        string? validatedEventSource = null;
 259642        if (eventSource is not null)
 43        {
 24244            if (eventSource.Length > MaxEventSourceLength)
 45            {
 246                throw new ArgumentException($"Event source cannot exceed {MaxEventSourceLength} characters.", nameof(eve
 47            }
 24048            validatedEventSource = eventSource.Trim();
 49        }
 50
 259451        string? validatedNotes = null;
 259452        if (notes is not null)
 53        {
 22854            if (notes.Length > MaxNotesLength)
 55            {
 256                throw new ArgumentException($"Notes cannot exceed {MaxNotesLength} characters.", nameof(notes));
 57            }
 22658            validatedNotes = notes.Trim();
 59        }
 60
 259261        var ts = now ?? DateTimeOffset.UtcNow;
 259262        return new ApplicationEvent
 259263        {
 259264            Id = id ?? Guid.CreateVersion7(),
 259265            OwnerId = ownerId.Trim(),
 259266            ApplicationId = applicationId,
 259267            EventDate = eventDate.Trim(),
 259268            EventType = eventType,
 259269            EventSource = validatedEventSource,
 259270            Notes = validatedNotes,
 259271            CreatedAt = ts
 259272        };
 73    }
 74
 75    public static ApplicationEvent Rehydrate(
 76        Guid id,
 77        string ownerId,
 78        Guid applicationId,
 79        string eventDate,
 80        ApplicationEventType eventType,
 81        string? eventSource,
 82        string? notes,
 83        DateTimeOffset createdAt)
 84    {
 13085        return new ApplicationEvent
 13086        {
 13087            Id = id,
 13088            OwnerId = ownerId,
 13089            ApplicationId = applicationId,
 13090            EventDate = eventDate,
 13091            EventType = eventType,
 13092            EventSource = eventSource,
 13093            Notes = notes,
 13094            CreatedAt = createdAt
 13095        };
 96    }
 97}