< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Protocol.Tlv.Converters.ChannelTypeTlvConverter
Assembly: NLightning.Infrastructure
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure/Protocol/Tlv/Converters/ChannelTypeTlvConverter.cs
Tag: 30_15166811759
Line coverage
71%
Covered lines: 5
Uncovered lines: 2
Coverable lines: 7
Total lines: 45
Line coverage: 71.4%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConvertToBase(...)100%11100%
ConvertFromBase(...)50%5.02460%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure/Protocol/Tlv/Converters/ChannelTypeTlvConverter.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2
 3namespace NLightning.Infrastructure.Protocol.Tlv.Converters;
 4
 5using Domain.Protocol.Constants;
 6using Domain.Protocol.Tlv;
 7using Domain.Protocol.Tlv.Converters;
 8
 9public class ChannelTypeTlvConverter : ITlvConverter<ChannelTypeTlv>
 10{
 11    public BaseTlv ConvertToBase(ChannelTypeTlv tlv)
 12    {
 1213        tlv.Value = tlv.ChannelType;
 14
 1215        return tlv;
 16    }
 17
 18    public ChannelTypeTlv ConvertFromBase(BaseTlv baseTlv)
 19    {
 1220        if (baseTlv.Type != TlvConstants.CHANNEL_TYPE)
 21        {
 022            throw new InvalidCastException("Invalid TLV type");
 23        }
 24
 1225        if (baseTlv.Length == 0)
 26        {
 027            throw new InvalidCastException("Invalid length");
 28        }
 29
 1230        return new ChannelTypeTlv(baseTlv.Value);
 31    }
 32
 33    [ExcludeFromCodeCoverage]
 34    BaseTlv ITlvConverter.ConvertFromBase(BaseTlv tlv)
 35    {
 36        return ConvertFromBase(tlv);
 37    }
 38
 39    [ExcludeFromCodeCoverage]
 40    BaseTlv ITlvConverter.ConvertToBase(BaseTlv tlv)
 41    {
 42        return ConvertToBase(tlv as ChannelTypeTlv
 43                             ?? throw new InvalidCastException($"Error converting BaseTlv to {nameof(ChannelTypeTlv)}"))
 44    }
 45}