< Summary

Information
Class: Anichron.Worker.Ingestion.Classification.ProxyFileRows
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Classification/ProxyFileRows.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 37
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
Replace(...)100%66100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Classification/ProxyFileRows.cs

#LineLine coverage
 1using Anichron.Core.Data.Repository;
 2using Anichron.Core.Domain;
 3
 4namespace Anichron.Worker.Ingestion.Classification;
 5
 6internal static class ProxyFileRows
 7{
 8    /// <summary>
 9    /// Makes the asset's proxy rows describe <paramref name="replacements"/>, by type: an existing row of a
 10    /// type is updated in place, a missing type is added, and a type not among the replacements is removed.
 11    /// </summary>
 12    /// <param name="repository">Tracks the added and removed rows.</param>
 13    /// <param name="asset">The asset whose proxy rows change.</param>
 14    /// <param name="replacements">The proxies the asset has from now on, owned by the asset.</param>
 15    public static void Replace(IMediaAssetRepository repository, MediaAsset asset, IReadOnlyList<ProxyFile> replacements
 5916    {
 5917        var stale = asset.ProxyFiles.Where(old => replacements.All(proxy => proxy.ProxyType != old.ProxyType));
 26718        foreach (var proxy in stale.ToList())
 4519            repository.RemoveProxyFile(proxy);
 20
 5921        var added = new List<ProxyFile>();
 25922        foreach (var proxy in replacements)
 4123        {
 4124            if (asset.ProxyFiles.FirstOrDefault(old => old.ProxyType == proxy.ProxyType) is not { } existing)
 1825            {
 1826                added.Add(proxy);
 1827                continue;
 28            }
 29
 2330            existing.ProxyPath = proxy.ProxyPath;
 2331            existing.SizeBytes = proxy.SizeBytes;
 2332            existing.CreatedAt = proxy.CreatedAt;
 2333        }
 34
 5935        repository.AddProxyFiles(added);
 5936    }
 37}