< Summary

Information
Class: ArturRios.Util.Http.HttpOutput<T>
Assembly: ArturRios.Util
File(s): D:\Repositories\dotnet-util\src\Http\HttpOutput.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 44
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 5
Fully covered methods: 4
Total methods: 5
Method coverage: 100%
Full method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_StatusCode()100%11100%
get_Headers()100%11100%
get_Body()100%11100%
ReadContent()100%11100%

File(s)

D:\Repositories\dotnet-util\src\Http\HttpOutput.cs

#LineLine coverage
 1using System.Net;
 2using System.Net.Http.Headers;
 3using Newtonsoft.Json;
 4
 5namespace ArturRios.Util.Http;
 6
 7/// <summary>
 8/// Represents a typed HTTP response output, including status, headers, and a deserialized body.
 9/// </summary>
 10/// <typeparam name="TBody">The type of the deserialized response body.</typeparam>
 711public class HttpOutput<TBody>(HttpResponseMessage responseMessage)
 12{
 13    /// <summary>
 14    /// Gets or sets the HTTP status code returned by the server.
 15    /// </summary>
 1316    public HttpStatusCode StatusCode { get; set; } = responseMessage.StatusCode;
 17
 18    /// <summary>
 19    /// Gets or sets the HTTP response headers.
 20    /// </summary>
 721    public HttpResponseHeaders Headers { get; set; } = responseMessage.Headers;
 22
 23    /// <summary>
 24    /// Gets or sets the deserialized response body.
 25    /// </summary>
 2126    public TBody? Body { get; set; }
 27
 28    /// <summary>
 29    /// Reads the response content as a string and deserializes it into <typeparamref name="TBody"/>.
 30    /// </summary>
 31    public async Task ReadContent()
 732    {
 733        var body = await responseMessage.Content.ReadAsStringAsync();
 34
 35        try
 736        {
 737            Body = JsonConvert.DeserializeObject<TBody>(body);
 638        }
 139        catch (JsonReaderException)
 140        {
 141            Body = default;
 142        }
 743    }
 44}