< Summary

Information
Class: OzonOrdersWeb.Filters.SupplierQuotationRawResponseFilter
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Filters/SupplierQuotationRawResponseFilter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 34
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Order()100%210%
.ctor(...)100%210%
OnActionExecutionAsync()0%110100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Filters/SupplierQuotationRawResponseFilter.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Mvc;
 2using Microsoft.AspNetCore.Mvc.Filters;
 3using Services.ApiServices.ApiSupplierRequestLog;
 4
 5namespace OzonOrdersWeb.Filters;
 6
 7/// <summary>Добавляет к результату проценки исходные тела ответов внешнего API до маппинга в PreOrderItem.</summary>
 8public sealed class SupplierQuotationRawResponseFilter : IAsyncActionFilter, IOrderedFilter
 9{
 10    private readonly ApiSupplierRequestLogStore _logs;
 11
 12    // Внешний слой: история и фильтры проценки должны по-прежнему видеть обычный результат контроллера.
 013    public int Order => -100;
 14
 015    public SupplierQuotationRawResponseFilter(ApiSupplierRequestLogStore logs) => _logs = logs;
 16
 17    public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
 18    {
 019        var executed = await next();
 020        if (executed.Exception is not null || executed.Result is not ObjectResult result) return;
 21
 022        var providerKey = SupplierQuotationHistoryFilter.ResolveProviderKey(executed.Controller.GetType().Name);
 023        if (providerKey is null ||
 024            !string.Equals(context.ActionDescriptor.RouteValues["action"], "Search", StringComparison.OrdinalIgnoreCase)
 025            !string.Equals(context.HttpContext.Request.Query["includeRawApiResponse"], "true", StringComparison.OrdinalI
 26
 027        var rawResponses = _logs.GetCurrentRequestResponses(providerKey);
 028        result.Value = new
 029        {
 030            items = result.Value,
 031            rawApiResponses = rawResponses.Select(x => new { x.Method, x.Endpoint, x.StatusCode, x.Response })
 032        };
 033    }
 34}