< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Serialization.ValueObjects.ChannelIdTypeSerializer
Assembly: NLightning.Infrastructure.Serialization
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Serialization/ValueObjects/ChannelIdTypeSerializer.cs
Tag: 36_15743069263
Line coverage
72%
Covered lines: 8
Uncovered lines: 3
Coverable lines: 11
Total lines: 54
Line coverage: 72.7%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SerializeAsync()50%2.06275%
DeserializeAsync()100%11100%
NLightning-Domain-Serialization-Interfaces-IValueObjectTypeSerializer-DeserializeAsync()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Serialization/ValueObjects/ChannelIdTypeSerializer.cs

#LineLine coverage
 1using System.Buffers;
 2using NLightning.Domain.Interfaces;
 3using NLightning.Domain.Serialization.Interfaces;
 4
 5namespace NLightning.Infrastructure.Serialization.ValueObjects;
 6
 7using Domain.Channels.Constants;
 8using Domain.Channels.ValueObjects;
 9
 10public class ChannelIdTypeSerializer : IValueObjectTypeSerializer<ChannelId>
 11{
 12    /// <summary>
 13    /// Serializes a ChannelId value into a stream.
 14    /// </summary>
 15    /// <param name="valueObject">The ChannelId value to serialize.</param>
 16    /// <param name="stream">The stream where the serialized value will be written.</param>
 17    /// <returns>A task that represents the asynchronous serialization operation.</returns>
 18    /// <exception cref="ArgumentNullException">Thrown when the stream is null.</exception>
 19    /// <exception cref="IOException">Thrown when an I/O error occurs during the write operation.</exception>
 20    public async Task SerializeAsync(IValueObject valueObject, Stream stream)
 21    {
 14022        if (valueObject is not ChannelId channelId)
 023            throw new ArgumentException("Value object must be of type ChannelId.", nameof(valueObject));
 24
 14025        await stream.WriteAsync(channelId);
 14026    }
 27
 28    /// <summary>
 29    /// Deserializes a ChannelId value from a stream.
 30    /// </summary>
 31    /// <param name="stream">The stream from which the ChannelId value will be deserialized.</param>
 32    /// <returns>A task that represents the asynchronous deserialization operation, containing the deserialized ChannelI
 33    /// <exception cref="ArgumentException">Thrown when the stream is empty or contains insufficient data for deserializ
 34    /// <exception cref="IOException">Thrown when an I/O error occurs during the read operation.</exception>
 35    public async Task<ChannelId> DeserializeAsync(Stream stream)
 36    {
 17237        var buffer = ArrayPool<byte>.Shared.Rent(ChannelConstants.ChannelIdLength);
 38
 39        try
 40        {
 17241            await stream.ReadExactlyAsync(buffer.AsMemory()[..ChannelConstants.ChannelIdLength]);
 42
 16843            return new ChannelId(buffer);
 44        }
 45        finally
 46        {
 17247            ArrayPool<byte>.Shared.Return(buffer);
 48        }
 16849    }
 50    async Task<IValueObject> IValueObjectTypeSerializer.DeserializeAsync(Stream stream)
 51    {
 052        return await DeserializeAsync(stream);
 053    }
 54}