< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Node.Models.PeerModel
Assembly: NLightning.Domain
File(s): /home/runner/work/NLightning/NLightning/src/NLightning.Domain/Node/Models/PeerModel.cs
Tag: 57_24045730253
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 84
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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_NodeId()100%210%
get_Host()100%210%
get_NodeId()100%210%
get_Port()100%210%
get_Host()100%210%
get_LastSeenAt()100%210%
get_Port()100%210%
get_Type()100%210%
get_LastSeenAt()100%210%
get_PeerAddressInfo()0%620%
get_Features()0%620%
get_Channels()100%210%
.ctor(...)100%210%
get_NegotiatedFeatures()0%620%
TryGetPeerService(...)0%620%
get_PeerAddressInfo()0%620%
get_Channels()100%210%
SetPeerService(...)0%620%
.ctor(...)100%210%
TryGetPeerService(...)0%620%
SetPeerService(...)0%620%

File(s)

/home/runner/work/NLightning/NLightning/src/NLightning.Domain/Node/Models/PeerModel.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2
 3namespace NLightning.Domain.Node.Models;
 4
 5using Channels.Models;
 6using Crypto.ValueObjects;
 7using Interfaces;
 8using Options;
 9using ValueObjects;
 10
 11public class PeerModel
 12{
 13    private PeerAddressInfo? _peerAddressInfo;
 14
 15    private IPeerService? _peerService;
 016
 017    public CompactPubKey NodeId { get; }
 018    public string Host { get; }
 019    public uint Port { get; }
 020    public string Type { get; }
 021    public DateTime LastSeenAt { get; set; }
 22
 23    public FeatureSet Features
 24    {
 025        get
 26        {
 027            return _peerService is null
 028                       ? throw new NullReferenceException($"{nameof(PeerModel)}.{nameof(Features)} was null")
 029                       : _peerService.Features.GetNodeFeatures();
 30        }
 031    }
 32
 033    public FeatureOptions NegotiatedFeatures
 34    {
 035        get
 036        {
 037            return _peerService is null
 038                       ? throw new NullReferenceException($"{nameof(PeerModel)}.{nameof(Features)} was null")
 039                       : _peerService.Features;
 40        }
 41    }
 042
 43    public PeerAddressInfo PeerAddressInfo
 044    {
 045        get
 46        {
 047            _peerAddressInfo ??= new PeerAddressInfo($"{NodeId}@{Host}:{Port}");
 048
 049            return _peerAddressInfo.Value;
 50        }
 51    }
 52
 053    public ICollection<ChannelModel>? Channels { get; set; }
 054
 055    public PeerModel(CompactPubKey nodeId, string host, uint port, string type)
 056    {
 057        NodeId = nodeId;
 058        Host = host;
 059        Port = port;
 060        Type = type;
 061    }
 62
 63    public bool TryGetPeerService([MaybeNullWhen(false)] out IPeerService peerService)
 64    {
 065        if (_peerService is not null)
 66        {
 067            peerService = _peerService;
 068            return true;
 69        }
 70
 071        peerService = null;
 072        return false;
 73    }
 74
 75    public void SetPeerService(IPeerService peerService)
 76    {
 077        ArgumentNullException.ThrowIfNull(peerService);
 78
 079        if (_peerService is not null)
 080            throw new InvalidOperationException("Peer service already set.");
 81
 082        _peerService = peerService;
 083    }
 84}