< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Serialization.ValueObjects.ChainHashTypeSerializer
Assembly: NLightning.Infrastructure.Serialization
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Serialization/ValueObjects/ChainHashTypeSerializer.cs
Tag: 30_15166811759
Line coverage
72%
Covered lines: 8
Uncovered lines: 3
Coverable lines: 11
Total lines: 53
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-ValueObjects-IValueObjectTypeSerializer-DeserializeAsync()100%210%

File(s)

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

#LineLine coverage
 1using System.Buffers;
 2
 3namespace NLightning.Infrastructure.Serialization.ValueObjects;
 4
 5using Domain.Serialization.ValueObjects;
 6using Domain.ValueObjects;
 7using Domain.ValueObjects.Interfaces;
 8
 9public class ChainHashTypeSerializer : IValueObjectTypeSerializer<ChainHash>
 10{
 11    /// <summary>
 12    /// Serializes a ChainHash value into a stream.
 13    /// </summary>
 14    /// <param name="valueObject">The ChainHash value to serialize.</param>
 15    /// <param name="stream">The stream where the serialized value will be written.</param>
 16    /// <returns>A task that represents the asynchronous serialization operation.</returns>
 17    /// <exception cref="ArgumentNullException">Thrown when the stream is null.</exception>
 18    /// <exception cref="IOException">Thrown when an I/O error occurs during the write operation.</exception>
 19    public async Task SerializeAsync(IValueObject valueObject, Stream stream)
 20    {
 1221        if (valueObject is not ChainHash chainHash)
 022            throw new ArgumentException("Value object must be of type ChainHash.", nameof(valueObject));
 23
 1224        await stream.WriteAsync(chainHash);
 1225    }
 26
 27    /// <summary>
 28    /// Deserializes a ChainHash value from a stream.
 29    /// </summary>
 30    /// <param name="stream">The stream from which the ChainHash value will be deserialized.</param>
 31    /// <returns>A task that represents the asynchronous deserialization operation, containing the deserialized ChainHas
 32    /// <exception cref="ArgumentException">Thrown when the stream is empty or contains insufficient data for deserializ
 33    /// <exception cref="IOException">Thrown when an I/O error occurs during the read operation.</exception>
 34    public async Task<ChainHash> DeserializeAsync(Stream stream)
 35    {
 2036        var buffer = ArrayPool<byte>.Shared.Rent(ChainHash.LENGTH);
 37
 38        try
 39        {
 2040            await stream.ReadExactlyAsync(buffer.AsMemory()[..ChainHash.LENGTH]);
 41
 1642            return new ChainHash(buffer);
 43        }
 44        finally
 45        {
 2046            ArrayPool<byte>.Shared.Return(buffer);
 47        }
 1648    }
 49    async Task<IValueObject> IValueObjectTypeSerializer.DeserializeAsync(Stream stream)
 50    {
 051        return await DeserializeAsync(stream);
 052    }
 53}