< Summary

Information
Class: TeleFlow.Framework.States.StateKey
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/States/StateKey.cs
Line coverage
78%
Covered lines: 29
Uncovered lines: 8
Coverable lines: 37
Total lines: 104
Line coverage: 78.3%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
.ctor(...)100%210%
.ctor(...)100%11100%
get_Namespace()100%11100%
set_Namespace(...)100%11100%
get_Scope()100%11100%
set_Scope(...)100%11100%
get_Subject()100%11100%
set_Subject(...)100%11100%
get_Partition()100%11100%
set_Partition(...)100%11100%
get_Destiny()100%11100%
set_Destiny(...)100%11100%
Create(...)100%11100%
Create(...)100%210%
ValidateRequired(...)100%22100%
ValidateOptional(...)100%44100%

File(s)

/_/src/TeleFlow.Framework.Core/States/StateKey.cs

#LineLine coverage
 1namespace TeleFlow.Framework.States;
 2
 3/// <summary>
 4/// Identifies the owner and isolation boundary of state records used by state stores, state data,
 5/// wizard history, and future storage-backed coordination primitives.
 6/// </summary>
 7public readonly record struct StateKey(
 8    string Namespace,
 9    string Scope,
 10    string Subject,
 11    string? Partition,
 12    string Destiny)
 13{
 11814    private readonly string _namespace = ValidateRequired(Namespace, nameof(Namespace));
 11615    private readonly string _scope = ValidateRequired(Scope, nameof(Scope));
 11416    private readonly string _subject = ValidateRequired(Subject, nameof(Subject));
 11217    private readonly string? _partition = ValidateOptional(Partition, nameof(Partition));
 11118    private readonly string _destiny = ValidateRequired(Destiny, nameof(Destiny));
 19
 20    public StateKey(string scope, string subject)
 021        : this(
 022            StateKeyDefaults.DefaultNamespace,
 023            scope,
 024            subject,
 025            null,
 026            StateKeyDefaults.DefaultDestiny)
 27    {
 028    }
 29
 30    public StateKey(string scope, string subject, string? partition)
 10131        : this(
 10132            StateKeyDefaults.DefaultNamespace,
 10133            scope,
 10134            subject,
 10135            partition,
 10136            StateKeyDefaults.DefaultDestiny)
 37    {
 10138    }
 39
 40    public string Namespace
 41    {
 742        get => _namespace;
 143        init => _namespace = ValidateRequired(value, nameof(Namespace));
 44    }
 45
 46    public string Scope
 47    {
 848        get => _scope;
 149        init => _scope = ValidateRequired(value, nameof(Scope));
 50    }
 51
 52    public string Subject
 53    {
 854        get => _subject;
 155        init => _subject = ValidateRequired(value, nameof(Subject));
 56    }
 57
 58    public string? Partition
 59    {
 860        get => _partition;
 161        init => _partition = ValidateOptional(value, nameof(Partition));
 62    }
 63
 64    public string Destiny
 65    {
 766        get => _destiny;
 167        init => _destiny = ValidateRequired(value, nameof(Destiny));
 68    }
 69
 70    public static StateKey Create(string scope, string subject, string? partition = null)
 71    {
 10172        return new StateKey(scope, subject, partition);
 73    }
 74
 75    public static StateKey Create(
 76        string keyNamespace,
 77        string scope,
 78        string subject,
 79        string? partition,
 80        string destiny)
 81    {
 082        return new StateKey(keyNamespace, scope, subject, partition, destiny);
 83    }
 84
 85    private static string ValidateRequired(string? value, string parameterName)
 86    {
 46387        if (string.IsNullOrWhiteSpace(value))
 88        {
 1289            throw new ArgumentException($"{parameterName} must be provided.", parameterName);
 90        }
 91
 45192        return value;
 93    }
 94
 95    private static string? ValidateOptional(string? value, string parameterName)
 96    {
 11397        if (value is not null && string.IsNullOrWhiteSpace(value))
 98        {
 299            throw new ArgumentException($"{parameterName} must be null or non-empty.", parameterName);
 100        }
 101
 111102        return value;
 103    }
 104}