< Summary

Information
Class: Intentum.Core.Behavior.BehaviorSpaceBuilder
Assembly: Intentum.Core
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Core/Behavior/BehaviorSpaceBuilder.cs
Line coverage
76%
Covered lines: 38
Uncovered lines: 12
Coverable lines: 50
Total lines: 104
Line coverage: 76%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
WithActor(...)100%11100%
Action(...)100%22100%
Action(...)50%2288.88%
Action(...)50%2290%
Action(...)0%220%
Observe(...)100%11100%
Build()100%11100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Core/Behavior/BehaviorSpaceBuilder.cs

#LineLine coverage
 1namespace Intentum.Core.Behavior;
 2
 3/// <summary>
 4/// Fluent builder for creating BehaviorSpace instances with a more readable API.
 5/// </summary>
 6public sealed class BehaviorSpaceBuilder
 7{
 8    private const string WithActorRequiredMessage = "Must call WithActor before Action";
 9
 7910    private readonly BehaviorSpace _space = new();
 11    private string? _currentActor;
 12
 13    /// <summary>
 14    /// Sets the current actor for subsequent actions.
 15    /// </summary>
 16    public BehaviorSpaceBuilder WithActor(string actor)
 7817    {
 7818        _currentActor = actor;
 7819        return this;
 7820    }
 21
 22    /// <summary>
 23    /// Adds an action for the current actor.
 24    /// </summary>
 25    public BehaviorSpaceBuilder Action(string action)
 12126    {
 12127        if (_currentActor == null)
 128            throw new InvalidOperationException(WithActorRequiredMessage);
 29
 12030        _space.Observe(new BehaviorEvent(
 12031            _currentActor,
 12032            action,
 12033            DateTimeOffset.UtcNow));
 34
 12035        return this;
 12036    }
 37
 38    /// <summary>
 39    /// Adds an action for the current actor with a specific timestamp.
 40    /// </summary>
 41    public BehaviorSpaceBuilder Action(string action, DateTimeOffset occurredAt)
 142    {
 143        if (_currentActor == null)
 044            throw new InvalidOperationException(WithActorRequiredMessage);
 45
 146        _space.Observe(new BehaviorEvent(
 147            _currentActor,
 148            action,
 149            occurredAt));
 50
 151        return this;
 152    }
 53
 54    /// <summary>
 55    /// Adds an action for the current actor with metadata.
 56    /// </summary>
 57    public BehaviorSpaceBuilder Action(string action, IReadOnlyDictionary<string, object>? metadata)
 258    {
 259        if (_currentActor == null)
 060            throw new InvalidOperationException(WithActorRequiredMessage);
 61
 262        _space.Observe(new BehaviorEvent(
 263            _currentActor,
 264            action,
 265            DateTimeOffset.UtcNow,
 266            metadata));
 67
 268        return this;
 269    }
 70
 71    /// <summary>
 72    /// Adds an action for the current actor with timestamp and metadata.
 73    /// </summary>
 74    public BehaviorSpaceBuilder Action(string action, DateTimeOffset occurredAt, IReadOnlyDictionary<string, object>? me
 075    {
 076        if (_currentActor == null)
 077            throw new InvalidOperationException(WithActorRequiredMessage);
 78
 079        _space.Observe(new BehaviorEvent(
 080            _currentActor,
 081            action,
 082            occurredAt,
 083            metadata));
 84
 085        return this;
 086    }
 87
 88    /// <summary>
 89    /// Adds a complete behavior event directly.
 90    /// </summary>
 91    public BehaviorSpaceBuilder Observe(BehaviorEvent behaviorEvent)
 192    {
 193        _space.Observe(behaviorEvent);
 194        return this;
 195    }
 96
 97    /// <summary>
 98    /// Builds and returns the BehaviorSpace instance.
 99    /// </summary>
 100    public BehaviorSpace Build()
 78101    {
 78102        return _space;
 78103    }
 104}