< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.FeaturesTaggedField
Assembly: NLightning.Bolt11.Blazor
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/FeaturesTaggedField.cs
Tag: 49_19945309242
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 65
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%210%
get_Value()100%210%
get_Length()100%210%
.ctor(...)100%210%
WriteToBitWriter(...)100%210%
IsValid()100%210%
FromBitReader(...)0%620%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/FeaturesTaggedField.cs

#LineLine coverage
 1namespace NLightning.Bolt11.Models.TaggedFields;
 2
 3using Domain.Node;
 4using Domain.Utils;
 5using Enums;
 6using Interfaces;
 7
 8/// <summary>
 9/// Tagged field for features
 10/// </summary>
 11/// <remarks>
 12/// The features are a collection of features that are supported by the node.
 13/// </remarks>
 14/// <seealso cref="ITaggedField"/>
 15internal sealed class FeaturesTaggedField : ITaggedField
 16{
 017    public TaggedFieldTypes Type => TaggedFieldTypes.Features;
 018    internal FeatureSet Value { get; }
 019    public short Length { get; }
 20
 21    /// <summary>
 22    /// Initializes a new instance of the <see cref="DescriptionTaggedField"/> class.
 23    /// </summary>
 24    /// <param name="value">The Description</param>
 025    internal FeaturesTaggedField(FeatureSet value)
 26    {
 027        Value = value;
 028        Length = (short)(value.SizeInBits / 5 + (value.SizeInBits % 5 == 0 ? 0 : 1));
 029    }
 30
 31    /// <inheritdoc/>
 32    public void WriteToBitWriter(BitWriter bitWriter)
 33    {
 034        var shouldPad = Length * 5 / 8 == (Length * 5 - 7) / 8;
 35
 36        // Write data
 037        Value.WriteToBitWriter(bitWriter, Length * 5, shouldPad);
 038    }
 39
 40    /// <inheritdoc/>
 41    public bool IsValid()
 42    {
 043        return true;
 44    }
 45
 46    /// <summary>
 47    /// Reads a FeaturesTaggedField from a BitReader
 48    /// </summary>
 49    /// <param name="bitReader">The BitReader to read from</param>
 50    /// <param name="length">The length of the field</param>
 51    /// <returns>The FeaturesTaggedField</returns>
 52    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 53    internal static FeaturesTaggedField FromBitReader(BitReader bitReader, short length)
 54    {
 055        if (length <= 0)
 056            throw new ArgumentException(
 057                $"Invalid length for {nameof(FeaturesTaggedField)}. Length must be greater than 0",
 058                nameof(length));
 59
 060        var shouldPad = length * 5 / 8 == (length * 5 - 7) / 8;
 061        var features = FeatureSet.DeserializeFromBitReader(bitReader, length * 5, shouldPad);
 62
 063        return new FeaturesTaggedField(features);
 64    }
 65}