< Summary

Information
Class: OzonOrdersWeb.WebServices.Currency.CurrencyRatesViewBagService
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Currency/CurrencyRatesViewBagService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 36
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
StartFetch()100%210%
GetRatesAsync(...)100%210%
ApplyToViewData(...)100%210%
SetViewBagAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Currency/CurrencyRatesViewBagService.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Mvc.ViewFeatures;
 2using Services.PriceСlculationServices;
 3
 4namespace OzonOrdersWeb.WebServices.Currency;
 5
 6public sealed class CurrencyRatesViewBagService : ICurrencyRatesViewBagService
 7{
 8    private readonly ICurrencyRateFetcher _currencyRateFetcher;
 9
 010    public CurrencyRatesViewBagService(ICurrencyRateFetcher currencyRateFetcher)
 11    {
 012        _currencyRateFetcher = currencyRateFetcher;
 013    }
 14
 15    public CurrencyRateFetchTasks StartFetch() =>
 016        new(
 017            _currencyRateFetcher.GetUSDRateAsync(),
 018            _currencyRateFetcher.GetEURRateAsync(),
 019            _currencyRateFetcher.GetBYNRateAsync());
 20
 21    public Task<CurrencyRatesSnapshot> GetRatesAsync(CancellationToken cancellationToken = default) =>
 022        StartFetch().ToSnapshotAsync();
 23
 24    public void ApplyToViewData(ViewDataDictionary viewData, CurrencyRatesSnapshot rates)
 25    {
 026        viewData["RateUSD"] = rates.RateUsd;
 027        viewData["RateEUR"] = rates.RateEur;
 028        viewData["RateBYN"] = rates.RateByn;
 029    }
 30
 31    public async Task SetViewBagAsync(ViewDataDictionary viewData, CancellationToken cancellationToken = default)
 32    {
 033        var rates = await GetRatesAsync(cancellationToken);
 034        ApplyToViewData(viewData, rates);
 035    }
 36}