< Summary

Information
Class: Anichron.Worker.Ingestion.LivePhotoLinker
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/LivePhotoLinker.cs
Tag: 228_36821334185
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Link(...)100%1010100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/LivePhotoLinker.cs

#LineLine coverage
 1using Anichron.Core.Domain;
 2using System.IO.Abstractions;
 3
 4namespace Anichron.Worker.Ingestion;
 5
 6internal sealed record LivePhotoLinkResult(
 7    IReadOnlyList<IngestionItem> Items,
 8    IReadOnlySet<string> ClaimedPaths);
 9
 10internal interface ILivePhotoLinker
 11{
 12    LivePhotoLinkResult Link(IEnumerable<string> filesInDirectory, string rootPath);
 13}
 14
 2515internal sealed class LivePhotoLinker(IFileSystem fileSystem) : ILivePhotoLinker
 16{
 17    public LivePhotoLinkResult Link(IEnumerable<string> filesInDirectory, string rootPath)
 2418    {
 2419        var heicFiles = new List<string>();
 2420        var movFilesByBaseName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 21
 14622        foreach (var path in filesInDirectory)
 3723        {
 3724            var ext = fileSystem.Path.GetExtension(path);
 3725            if (ext.Equals(MediaFileExtensions.Heic, StringComparison.OrdinalIgnoreCase))
 1326                heicFiles.Add(path);
 2427            else if (ext.Equals(MediaFileExtensions.Mov, StringComparison.OrdinalIgnoreCase))
 1328                movFilesByBaseName[fileSystem.Path.GetFileNameWithoutExtension(path)] = path;
 3729        }
 30
 2431        var items = new List<IngestionItem>(heicFiles.Count);
 2432        var claimedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 33
 9834        foreach (var heicPath in heicFiles)
 1335        {
 1336            claimedPaths.Add(heicPath);
 1337            var baseName = fileSystem.Path.GetFileNameWithoutExtension(heicPath);
 1338            var heicRelativePath = fileSystem.Path.GetRelativePath(rootPath, heicPath);
 39
 1340            if (movFilesByBaseName.TryGetValue(baseName, out var movPath))
 941            {
 942                var movRelativePath = fileSystem.Path.GetRelativePath(rootPath, movPath);
 943                items.Add(new LivePhotoPairItem(heicPath, heicRelativePath, movPath, movRelativePath));
 944                claimedPaths.Add(movPath);
 945            }
 46            else
 447            {
 448                items.Add(new SingleFileItem(heicPath, heicRelativePath, MediaType.Image));
 449            }
 1350        }
 51
 2452        return new LivePhotoLinkResult(items, claimedPaths);
 2453    }
 54}