< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.Utilities.APIResponses.BaseResponseResult
Assembly: ZhEaIsNsAaBn.Utilities.APIResponses
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.APIResponses/BaseResponseResult.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 48
Line coverage: 100%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteResultAsync(...)62.5%88100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.APIResponses/BaseResponseResult.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.Options;
 3
 4namespace ZhEaIsNsAaBn.Utilities.APIResponses;
 5
 6/// <summary>
 7/// The <see cref="ObjectResult"/> returned by <see cref="BaseResponse.ToAPI"/>. When it executes, a status that came fr
 8/// resolved again with the app's <see cref="APIResponsesSettings"/> from the request services (defaults when none are r
 9/// </summary>
 10public sealed class BaseResponseResult : ObjectResult
 11{
 12    private readonly BaseResponse _response;
 13
 14
 15    /// <summary>Creates the result.</summary>
 16    /// <param name="response">The response body.</param>
 17    /// <exception cref="ArgumentNullException"><paramref name="response"/> is <see langword="null"/>.</exception>
 6918    public BaseResponseResult( BaseResponse response ) : base( response )
 19    {
 6920        ArgumentNullException.ThrowIfNull( response );
 21
 6922        _response  = response;
 6923        StatusCode = response.Status;
 6924    }
 25
 26
 27    /// <summary>Resolves the status (see <see cref="APIResponsesSettings"/>), then writes the response.</summary>
 28    /// <param name="context">The action context.</param>
 29    /// <returns>A task that completes when the response is written.</returns>
 30    public override Task ExecuteResultAsync( ActionContext context )
 31    {
 6632        ArgumentNullException.ThrowIfNull( context );
 33
 6634        if ( _response.StatusFromErrors )
 35        {
 6036            var settings = context.HttpContext.RequestServices?.GetService<IOptions<APIResponsesSettings>>()?.Value;
 37
 6038            if ( settings is not null )
 39            {
 6040                _response.Status = (int) settings.StatusFor( _response.Errors );
 6041                StatusCode       = _response.Status;
 42            }
 43        }
 44
 45
 6646        return base.ExecuteResultAsync( context );
 47    }
 48}