< Summary - Estud

Information
Class: Estud.Back.Shared.HttpExtensions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Shared/Extensions/HttpExtensions.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 33
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToError()100%11100%
DeserializeTo()100%11100%
Resolve()100%66100%

File(s)

/home/runner/work/syki/syki/Back/Shared/Extensions/HttpExtensions.cs

#LineLine coverage
 1using System.Net;
 2using Newtonsoft.Json;
 3
 4namespace Estud.Back.Shared;
 5
 6public static class HttpExtensions
 7{
 8    public static async Task<ErrorOut> ToError(this HttpResponseMessage httpResponse)
 9    {
 43610        var responseAsString = await httpResponse.Content.ReadAsStringAsync();
 43611        return JsonConvert.DeserializeObject<ErrorOut>(responseAsString)!;
 43612    }
 13
 14    public static async Task<T> DeserializeTo<T>(this HttpResponseMessage httpResponse)
 15    {
 279016        var responseAsString = await httpResponse.Content.ReadAsStringAsync();
 279017        return JsonConvert.DeserializeObject<T>(responseAsString)!;
 279018    }
 19
 20    public static async Task<OneOf<T, ErrorOut>> Resolve<T>(this HttpResponseMessage httpResponse)
 21    {
 344422        if (httpResponse.IsSuccessStatusCode)
 276423            return await httpResponse.DeserializeTo<T>();
 24
 68025        if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
 13026            return UnauthorizedErrorOut.I;
 27
 55028        if (httpResponse.StatusCode == HttpStatusCode.Forbidden)
 11429            return ForbiddenErrorOut.I;
 30
 43631        return await httpResponse.ToError();
 344432    }
 33}

Methods/Properties

ToError()
DeserializeTo()
Resolve()