< Summary

Information
Class: Elsa.Expressions.Models.MemoryRegister
Assembly: Elsa.Expressions
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/MemoryRegister.cs
Line coverage
87%
Covered lines: 14
Uncovered lines: 2
Coverable lines: 16
Total lines: 61
Line coverage: 87.5%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_Blocks()100%11100%
IsDeclared(...)100%210%
HasBlock(...)100%11100%
TryGetBlock(...)100%11100%
Declare(...)50%2266.66%
Declare(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/MemoryRegister.cs

#LineLine coverage
 1namespace Elsa.Expressions.Models;
 2
 3/// <summary>
 4/// Represents a register of memory.
 5/// </summary>
 6public class MemoryRegister
 7{
 8    /// <summary>
 9    /// Constructor.
 10    /// </summary>
 320911    public MemoryRegister(IDictionary<string, MemoryBlock>? blocks = null)
 12    {
 320913        Blocks = blocks ?? new Dictionary<string, MemoryBlock>();
 320914    }
 15
 16    /// <summary>
 17    /// The memory blocks declared in this register.
 18    /// </summary>
 1706119    public IDictionary<string, MemoryBlock> Blocks { get; }
 20
 21    /// <summary>
 22    /// Returns true if the specified memory block is declared in this register.
 23    /// </summary>
 024    public bool IsDeclared(MemoryBlockReference reference) => HasBlock(reference.Id);
 25
 26    /// <summary>
 27    /// Returns true if the specified memory block is declared in this register.
 28    /// </summary>
 33129    public bool HasBlock(string id) => Blocks.ContainsKey(id);
 30
 31    /// <summary>
 32    /// Returns the memory block with the specified ID.
 33    /// </summary>
 34    public bool TryGetBlock(string id, out MemoryBlock block)
 35    {
 1161836        block = null!;
 1161837        return Blocks.TryGetValue(id, out block!);
 38    }
 39
 40    /// <summary>
 41    /// Declares the memory for the specified memory block references.
 42    /// </summary>
 43    public void Declare(IEnumerable<MemoryBlockReference> references)
 44    {
 147845        foreach (var reference in references)
 046            Declare(reference);
 73947    }
 48
 49    /// <summary>
 50    /// Declares the memory for the specified memory block reference.
 51    /// </summary>
 52    public MemoryBlock Declare(MemoryBlockReference blockReference)
 53    {
 249254        if(Blocks.TryGetValue(blockReference.Id, out var block))
 1755            return block;
 56
 247557        block = blockReference.Declare();
 247558        Blocks[blockReference.Id] = block;
 247559        return block;
 60    }
 61}