< Summary

Information
Class: AsiBackbone.Storage.InMemory.Audit.InMemoryAuditResidueLifecycleStore
Assembly: AsiBackbone.Storage.InMemory
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Storage.InMemory/Audit/InMemoryAuditResidueLifecycleStore.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
AppendAsync(...)100%22100%
FindByEventIdAsync(...)100%11100%
FindByCorrelationIdAsync(...)100%11100%
FindByAuditResidueIdAsync(...)100%11100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Storage.InMemory/Audit/InMemoryAuditResidueLifecycleStore.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using AsiBackbone.Core.Audit;
 3
 4namespace AsiBackbone.Storage.InMemory.Audit;
 5
 6/// <summary>
 7/// In-memory audit residue lifecycle store for tests, samples, and development hosts.
 8/// </summary>
 9/// <remarks>
 10/// This store is not durable across process restarts. Production hosts should use a durable provider such as EF Core or
 11/// </remarks>
 12public sealed class InMemoryAuditResidueLifecycleStore : IAsiBackboneAuditResidueLifecycleStore
 13{
 3414    private readonly ConcurrentDictionary<string, AuditResidueLifecycleEvent> events = new(StringComparer.Ordinal);
 15
 16    /// <inheritdoc />
 17    public ValueTask<AuditResidueLifecycleEvent> AppendAsync(
 18        AuditResidueLifecycleEvent lifecycleEvent,
 19        CancellationToken cancellationToken = default)
 20    {
 2821        ArgumentNullException.ThrowIfNull(lifecycleEvent);
 2622        cancellationToken.ThrowIfCancellationRequested();
 23
 2424        return !events.TryAdd(lifecycleEvent.EventId, lifecycleEvent)
 2425            ? throw new InvalidOperationException($"Lifecycle event '{lifecycleEvent.EventId}' already exists.")
 2426            : ValueTask.FromResult(lifecycleEvent);
 27    }
 28
 29    /// <inheritdoc />
 30    public ValueTask<AuditResidueLifecycleEvent?> FindByEventIdAsync(
 31        string eventId,
 32        CancellationToken cancellationToken = default)
 33    {
 2634        ArgumentException.ThrowIfNullOrWhiteSpace(eventId);
 2435        cancellationToken.ThrowIfCancellationRequested();
 36
 2237        _ = events.TryGetValue(eventId.Trim(), out AuditResidueLifecycleEvent? lifecycleEvent);
 38
 2239        return ValueTask.FromResult(lifecycleEvent);
 40    }
 41
 42    /// <inheritdoc />
 43    public ValueTask<IReadOnlyList<AuditResidueLifecycleEvent>> FindByCorrelationIdAsync(
 44        string correlationId,
 45        CancellationToken cancellationToken = default)
 46    {
 847        ArgumentException.ThrowIfNullOrWhiteSpace(correlationId);
 648        cancellationToken.ThrowIfCancellationRequested();
 49
 450        string normalizedCorrelationId = correlationId.Trim();
 51
 452        IReadOnlyList<AuditResidueLifecycleEvent> matches = [.. events.Values
 1253            .Where(lifecycleEvent => string.Equals(lifecycleEvent.CorrelationId, normalizedCorrelationId, StringComparis
 454            .OrderBy(lifecycleEvent => lifecycleEvent.OccurredUtc)
 855            .ThenBy(lifecycleEvent => lifecycleEvent.EventId)];
 56
 457        return ValueTask.FromResult(matches);
 58    }
 59
 60    /// <inheritdoc />
 61    public ValueTask<IReadOnlyList<AuditResidueLifecycleEvent>> FindByAuditResidueIdAsync(
 62        string auditResidueId,
 63        CancellationToken cancellationToken = default)
 64    {
 865        ArgumentException.ThrowIfNullOrWhiteSpace(auditResidueId);
 666        cancellationToken.ThrowIfCancellationRequested();
 67
 468        string normalizedAuditResidueId = auditResidueId.Trim();
 69
 470        IReadOnlyList<AuditResidueLifecycleEvent> matches = [.. events.Values
 1271            .Where(lifecycleEvent => string.Equals(lifecycleEvent.AuditResidueId, normalizedAuditResidueId, StringCompar
 472            .OrderBy(lifecycleEvent => lifecycleEvent.OccurredUtc)
 873            .ThenBy(lifecycleEvent => lifecycleEvent.EventId)];
 74
 475        return ValueTask.FromResult(matches);
 76    }
 77}