< Summary

Information
Class: AsiBackbone.Core.Actors.AsiBackboneActorContext
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Actors/AsiBackboneActorContext.cs
Line coverage
100%
Covered lines: 45
Uncovered lines: 0
Coverable lines: 45
Total lines: 130
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
get_ActorId()100%11100%
get_ActorType()100%11100%
get_DisplayName()100%11100%
get_IsKnown()100%11100%
get_IsAuthenticated()100%11100%
get_Unknown()100%11100%
.cctor()100%11100%
get_System()100%11100%
Human(...)100%11100%
Service(...)100%11100%
Agent(...)100%11100%
NormalizeActorId(...)100%11100%
NormalizeDisplayName(...)100%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Actors/AsiBackboneActorContext.cs

#LineLine coverage
 1namespace AsiBackbone.Core.Actors;
 2
 3/// <summary>
 4/// Provides a default framework-neutral actor context implementation.
 5/// </summary>
 6public sealed record AsiBackboneActorContext : IAsiBackboneActorContext
 7{
 8    /// <summary>
 9    /// The stable identifier used for unknown actors.
 10    /// </summary>
 11    public const string UnknownActorId = "unknown";
 12
 13    /// <summary>
 14    /// The stable identifier used for system actors.
 15    /// </summary>
 16    public const string SystemActorId = "system";
 17
 18318    private AsiBackboneActorContext(
 18319        string actorId,
 18320        AsiBackboneActorType actorType,
 18321        string? displayName,
 18322        bool isKnown,
 18323        bool isAuthenticated)
 24    {
 18325        ActorId = NormalizeActorId(actorId);
 18026        ActorType = actorType;
 18027        DisplayName = NormalizeDisplayName(displayName);
 18028        IsKnown = isKnown;
 18029        IsAuthenticated = isAuthenticated;
 18030    }
 31
 32    /// <inheritdoc />
 25733    public string ActorId { get; }
 34
 35    /// <inheritdoc />
 25736    public AsiBackboneActorType ActorType { get; }
 37
 38    /// <inheritdoc />
 24739    public string? DisplayName { get; }
 40
 41    /// <inheritdoc />
 2842    public bool IsKnown { get; }
 43
 44    /// <inheritdoc />
 3445    public bool IsAuthenticated { get; }
 46
 47    /// <summary>
 48    /// Gets a shared actor context for unknown or unauthenticated operations.
 49    /// </summary>
 1450    public static AsiBackboneActorContext Unknown { get; } =
 451        new(UnknownActorId, AsiBackboneActorType.Unknown, null, isKnown: false, isAuthenticated: false);
 52
 53    /// <summary>
 54    /// Gets a shared actor context for trusted system operations.
 55    /// </summary>
 6456    public static AsiBackboneActorContext System { get; } =
 457        new(SystemActorId, AsiBackboneActorType.System, "System", isKnown: true, isAuthenticated: true);
 58
 59    /// <summary>
 60    /// Creates an actor context for a human participant.
 61    /// </summary>
 62    /// <param name="actorId">The stable actor identifier.</param>
 63    /// <param name="displayName">The optional display name.</param>
 64    /// <param name="isAuthenticated">Whether the host has authenticated the actor.</param>
 65    /// <returns>A human actor context.</returns>
 66    public static AsiBackboneActorContext Human(
 67        string actorId,
 68        string? displayName = null,
 69        bool isAuthenticated = true)
 70    {
 13071        return new AsiBackboneActorContext(
 13072            actorId,
 13073            AsiBackboneActorType.Human,
 13074            displayName,
 13075            isKnown: true,
 13076            isAuthenticated: isAuthenticated);
 77    }
 78
 79    /// <summary>
 80    /// Creates an actor context for a service participant.
 81    /// </summary>
 82    /// <param name="actorId">The stable service actor identifier.</param>
 83    /// <param name="displayName">The optional display name.</param>
 84    /// <returns>A service actor context.</returns>
 85    public static AsiBackboneActorContext Service(string actorId, string? displayName = null)
 86    {
 3987        return new AsiBackboneActorContext(
 3988            actorId,
 3989            AsiBackboneActorType.Service,
 3990            displayName,
 3991            isKnown: true,
 3992            isAuthenticated: true);
 93    }
 94
 95    /// <summary>
 96    /// Creates an actor context for a delegated or autonomous software agent.
 97    /// </summary>
 98    /// <param name="actorId">The stable agent actor identifier.</param>
 99    /// <param name="displayName">The optional display name.</param>
 100    /// <param name="isAuthenticated">Whether the host has authenticated the agent.</param>
 101    /// <returns>An agent actor context.</returns>
 102    public static AsiBackboneActorContext Agent(
 103        string actorId,
 104        string? displayName = null,
 105        bool isAuthenticated = true)
 106    {
 6107        return new AsiBackboneActorContext(
 6108            actorId,
 6109            AsiBackboneActorType.Agent,
 6110            displayName,
 6111            isKnown: true,
 6112            isAuthenticated: isAuthenticated);
 113    }
 114
 115    private static string NormalizeActorId(string actorId)
 116    {
 183117        ArgumentException.ThrowIfNullOrWhiteSpace(actorId);
 118
 180119        return actorId.Trim();
 120    }
 121
 122    private static string? NormalizeDisplayName(string? displayName)
 123    {
 180124        string? normalizedDisplayName = displayName?.Trim();
 125
 180126        return string.IsNullOrWhiteSpace(normalizedDisplayName)
 180127            ? null
 180128            : normalizedDisplayName;
 129    }
 130}