< Summary

Information
Class: Anichron.Infrastructure.Storage.ProxyStore
Assembly: Anichron.Infrastructure
File(s): /home/runner/work/anichron/anichron/src/Anichron.Infrastructure/Storage/ProxyStore.cs
Tag: 19_45211875487
Line coverage
78%
Covered lines: 11
Uncovered lines: 3
Coverable lines: 14
Total lines: 45
Line coverage: 78.5%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%210%
.ctor(...)100%11100%
RootExists()100%11100%
OpenRead(...)100%22100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Infrastructure/Storage/ProxyStore.cs

#LineLine coverage
 1using Anichron.Core;
 2using System.IO.Abstractions;
 3
 4namespace Anichron.Infrastructure.Storage;
 5
 6public interface IProxyStore
 7{
 8    bool RootExists();
 9
 10    /// <summary>
 11    /// Opens a proxy for reading by its stored path, relative to the proxy root. Returns
 12    /// <see langword="null"/> when the file is missing or the path resolves outside the root.
 13    /// </summary>
 14    Stream? OpenRead(string proxyPath);
 15}
 16
 17public sealed class ProxyStore : IProxyStore
 18{
 19    private readonly IFileSystem fileSystem;
 20
 21    public ProxyStore()
 022        : this(new FileSystem())
 023    {
 024    }
 25
 3026    internal ProxyStore(IFileSystem fileSystem) => this.fileSystem = fileSystem;
 27
 228    public bool RootExists() => fileSystem.Directory.Exists(StoragePath.ProxiesRoot);
 29
 30    public Stream? OpenRead(string proxyPath)
 1331    {
 1332        if (StoragePath.ResolveProxy(proxyPath) is not { } fullPath)
 733            return null;
 34
 35        try
 636        {
 637            return fileSystem.FileStream.New(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
 38        }
 39        // Stryker disable once Block
 340        catch (Exception ex) when (ex is FileNotFoundException or DirectoryNotFoundException)
 241        {
 242            return null;
 43        }
 1244    }
 45}