< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.ValueObjects.ChannelId
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/ChannelId.cs
Tag: 30_15166811759
Line coverage
68%
Covered lines: 11
Uncovered lines: 5
Coverable lines: 16
Total lines: 64
Line coverage: 68.7%
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
get_Zero()100%11100%
.ctor(...)100%22100%
Equals(...)0%620%
Equals(...)100%11100%
GetHashCode()100%210%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%210%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/ChannelId.cs

#LineLine coverage
 1namespace NLightning.Domain.ValueObjects;
 2
 3using Interfaces;
 4
 5/// <summary>
 6/// Represents a channel id.
 7/// </summary>
 8/// <remarks>
 9/// The channel id is a unique identifier for a channel.
 10/// </remarks>
 11public readonly struct ChannelId : IValueObject, IEquatable<ChannelId>
 12{
 13    public const int LENGTH = 32;
 14
 15    private readonly byte[] _value;
 16
 32017    public static ChannelId Zero => new(new byte[LENGTH]);
 18
 19    public ChannelId(ReadOnlySpan<byte> value)
 20    {
 53221        if (value.Length != LENGTH)
 22        {
 423            throw new ArgumentException($"ChannelId must be {LENGTH} bytes", nameof(value));
 24        }
 25
 52826        _value = value.ToArray();
 52827    }
 28
 29    #region Overrides
 30    public override bool Equals(object? obj)
 31    {
 032        if (obj is ChannelId other)
 33        {
 034            return Equals(other);
 35        }
 36
 037        return false;
 38    }
 39
 18440    public bool Equals(ChannelId other) => _value.SequenceEqual(other._value);
 41
 42    public override int GetHashCode()
 43    {
 044        return BitConverter.ToInt32(_value, 0);
 45    }
 46    #endregion
 47
 48    #region Operators
 3649    public static implicit operator byte[](ChannelId c) => c._value;
 14050    public static implicit operator ReadOnlyMemory<byte>(ChannelId c) => c._value;
 851    public static implicit operator ChannelId(byte[] value) => new(value);
 052    public static implicit operator ChannelId(Span<byte> value) => new(value);
 53
 54    public static bool operator ==(ChannelId left, ChannelId right)
 55    {
 2456        return left.Equals(right);
 57    }
 58
 59    public static bool operator !=(ChannelId left, ChannelId right)
 60    {
 1261        return !(left == right);
 62    }
 63    #endregion
 64}