< Summary

Information
Class: Anichron.Worker.Ingestion.LivePhotoLinker
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/LivePhotoLinker.cs
Tag: 19_45211875487
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
 5315internal sealed class LivePhotoLinker(IFileSystem fileSystem) : ILivePhotoLinker
 16{
 17    public LivePhotoLinkResult Link(IEnumerable<string> filesInDirectory, string rootPath)
 7118    {
 7119        var heicFiles = new List<string>();
 7120        var movFilesByBaseName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 21
 41522        foreach (var path in filesInDirectory)
 10123        {
 10124            var ext = fileSystem.Path.GetExtension(path);
 10125            if (ext.Equals(MediaFileExtensions.Heic, StringComparison.OrdinalIgnoreCase))
 1726                heicFiles.Add(path);
 8427            else if (ext.Equals(MediaFileExtensions.Mov, StringComparison.OrdinalIgnoreCase))
 1728                movFilesByBaseName[fileSystem.Path.GetFileNameWithoutExtension(path)] = path;
 10129        }
 30
 7131        var items = new List<IngestionItem>(heicFiles.Count);
 7132        var claimedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 33
 24734        foreach (var heicPath in heicFiles)
 1735        {
 1736            claimedPaths.Add(heicPath);
 1737            var baseName = fileSystem.Path.GetFileNameWithoutExtension(heicPath);
 1738            var heicRelativePath = fileSystem.Path.GetRelativePath(rootPath, heicPath);
 39
 1740            if (movFilesByBaseName.TryGetValue(baseName, out var movPath))
 1341            {
 1342                var movRelativePath = fileSystem.Path.GetRelativePath(rootPath, movPath);
 1343                items.Add(new LivePhotoPairItem(heicPath, heicRelativePath, movPath, movRelativePath));
 1344                claimedPaths.Add(movPath);
 1345            }
 46            else
 447            {
 448                items.Add(new SingleFileItem(heicPath, heicRelativePath, MediaType.Image));
 449            }
 1750        }
 51
 7152        return new LivePhotoLinkResult(items, claimedPaths);
 7153    }
 54}