< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Protocol.Models.TlvStream
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/Models/TLVStream.cs
Tag: 30_15166811759
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 69
Line coverage: 83.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Add(...)100%22100%
Add(...)83.33%6.29680%
GetTlvs()100%11100%
TryGetTlv(...)100%11100%
Any()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/Models/TLVStream.cs

#LineLine coverage
 1namespace NLightning.Domain.Protocol.Models;
 2
 3using Tlv;
 4using ValueObjects;
 5
 6/// <summary>
 7/// A series of (possibly zero) TLVs
 8/// </summary>
 9public sealed class TlvStream
 10{
 22011    private readonly SortedDictionary<BigSize, BaseTlv> _tlvs = [];
 12
 13    /// <summary>
 14    /// Add a TLV to the stream
 15    /// </summary>
 16    /// <param name="baseTlv">The TLV to add</param>
 17    public void Add(BaseTlv baseTlv)
 18    {
 17219        if (!_tlvs.TryAdd(baseTlv.Type, baseTlv))
 20        {
 421            throw new ArgumentException($"A TLV with type {baseTlv.Type} already exists.");
 22        }
 16823    }
 24
 25    /// <summary>
 26    /// Add a series of TLV to the stream
 27    /// </summary>
 28    /// <param name="tlvs">The TLVs to add</param>
 29    public void Add(params BaseTlv?[] tlvs)
 30    {
 27231        foreach (var tlv in tlvs)
 32        {
 9633            if (tlv is null)
 34                continue;
 35
 9636            if (!_tlvs.TryAdd(tlv.Type, tlv))
 37            {
 038                throw new ArgumentException($"A TLV with type {tlv.Type} already exists.");
 39            }
 40        }
 4041    }
 42
 43    /// <summary>
 44    /// Get all TLVs in the stream
 45    /// </summary>
 46    public IEnumerable<BaseTlv> GetTlvs()
 47    {
 4048        return _tlvs.Values;
 49    }
 50
 51    /// <summary>
 52    /// Get a specific TLV from the stream
 53    /// </summary>
 54    /// <param name="type">The type of TLV to get</param>
 55    /// <param name="tlv">The TLV to get</param>
 56    /// <returns></returns>
 57    public bool TryGetTlv(BigSize type, out BaseTlv? tlv)
 58    {
 9659        return _tlvs.TryGetValue(type, out tlv);
 60    }
 61
 62    /// <summary>
 63    /// Check if any TLVs are present
 64    /// </summary>
 65    public bool Any()
 66    {
 067        return _tlvs.Count != 0;
 68    }
 69}