< Summary

Information
Class: RoleRadar.Domain.Notes.NoteRevision
Assembly: RoleRadar.Domain
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Notes/NoteRevision.cs
Line coverage
88%
Covered lines: 48
Uncovered lines: 6
Coverable lines: 54
Total lines: 111
Line coverage: 88.8%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.1%
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_NoteId()100%11100%
get_RevisionNumber()100%11100%
get_Reason()100%11100%
get_PriorBody()100%11100%
get_PriorBodyHash()100%11100%
get_PriorVersionToken()100%11100%
get_CreatedAtUtc()100%11100%
.ctor(...)100%11100%
Create(...)58.33%151273.91%
Rehydrate(...)100%11100%
EnsureUtc(...)50%22100%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Notes/NoteRevision.cs

#LineLine coverage
 1using RoleRadar.Domain.Common;
 2
 3namespace RoleRadar.Domain.Notes;
 4
 5public sealed class NoteRevision
 6{
 7    public const string ReasonReplaceSection = "replace-section";
 8    public const string ReasonImportOverwrite = "import-overwrite";
 9
 4410    public Guid Id { get; }
 11
 2012    public string OwnerId { get; }
 13
 2014    public Guid NoteId { get; }
 15
 3216    public int RevisionNumber { get; }
 17
 2218    public string Reason { get; }
 19
 3420    public string PriorBody { get; }
 21
 2022    public string PriorBodyHash { get; }
 23
 2024    public Guid PriorVersionToken { get; }
 25
 2026    public DateTime CreatedAtUtc { get; }
 27
 3628    private NoteRevision(
 3629        Guid id,
 3630        string ownerId,
 3631        Guid noteId,
 3632        int revisionNumber,
 3633        string reason,
 3634        string priorBody,
 3635        string priorBodyHash,
 3636        Guid priorVersionToken,
 3637        DateTime createdAtUtc)
 38    {
 3639        Id = id;
 3640        OwnerId = ownerId;
 3641        NoteId = noteId;
 3642        RevisionNumber = revisionNumber;
 3643        Reason = reason;
 3644        PriorBody = priorBody;
 3645        PriorBodyHash = priorBodyHash;
 3646        PriorVersionToken = priorVersionToken;
 3647        CreatedAtUtc = EnsureUtc(createdAtUtc);
 3648    }
 49
 50    public static NoteRevision Create(
 51        string ownerId,
 52        Guid noteId,
 53        int revisionNumber,
 54        string reason,
 55        string priorBody,
 56        Guid priorVersionToken,
 57        DateTime createdAtUtc)
 58    {
 2259        var validOwner = new OwnerId(ownerId).Value;
 2260        if (noteId == Guid.Empty)
 61        {
 062            throw new ArgumentException("Note identifier cannot be empty.", nameof(noteId));
 63        }
 64
 2265        if (revisionNumber < 1)
 66        {
 067            throw new ArgumentOutOfRangeException(nameof(revisionNumber), "Revision number must be >= 1.");
 68        }
 69
 2270        if (reason is not (ReasonReplaceSection or ReasonImportOverwrite))
 71        {
 072            throw new ArgumentException(
 073                $"Revision reason must be '{ReasonReplaceSection}' or '{ReasonImportOverwrite}'.",
 074                nameof(reason));
 75        }
 76
 2277        ArgumentNullException.ThrowIfNull(priorBody);
 2278        if (priorVersionToken == Guid.Empty)
 79        {
 080            throw new ArgumentException("Prior version token cannot be empty.", nameof(priorVersionToken));
 81        }
 82
 2283        var priorBodyHash = Sha256Hasher.ComputeLowerHex(priorBody);
 84
 2285        return new NoteRevision(
 2286            Guid.CreateVersion7(),
 2287            validOwner,
 2288            noteId,
 2289            revisionNumber,
 2290            reason,
 2291            priorBody,
 2292            priorBodyHash,
 2293            priorVersionToken,
 2294            EnsureUtc(createdAtUtc));
 95    }
 96
 97    public static NoteRevision Rehydrate(
 98        Guid id,
 99        string ownerId,
 100        Guid noteId,
 101        int revisionNumber,
 102        string reason,
 103        string priorBody,
 104        string priorBodyHash,
 105        Guid priorVersionToken,
 106        DateTime createdAtUtc) =>
 14107        new(id, ownerId, noteId, revisionNumber, reason, priorBody, priorBodyHash, priorVersionToken, createdAtUtc);
 108
 109    private static DateTime EnsureUtc(DateTime value) =>
 58110        value.Kind == DateTimeKind.Utc ? value : DateTime.SpecifyKind(value, DateTimeKind.Utc);
 111}