< Summary

Information
Class: Amusoft.DotnetNew.Tests.Templating.TempDirectory
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Templating/TempDirectory.cs
Tag: 127_14865883074
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 60
Line coverage: 100%
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%11100%
get_Path()100%11100%
Dispose()100%22100%
GetFileContentAsync()100%11100%
GetRelativePaths()100%11100%

File(s)

/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Templating/TempDirectory.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using Amusoft.DotnetNew.Tests.Diagnostics;
 8using Amusoft.DotnetNew.Tests.Interfaces;
 9using Amusoft.DotnetNew.Tests.Scopes;
 10
 11namespace Amusoft.DotnetNew.Tests.Templating;
 12
 13/// <summary>
 14/// Temporary directory
 15/// </summary>
 16internal class TempDirectory : ITempDirectory
 17{
 18  /// <summary>
 19  /// Constructor
 20  /// </summary>
 721  internal TempDirectory()
 22  {
 723    var directory = System.IO.Path.Combine(
 724      System.IO.Path.GetTempPath(),
 725      Guid.NewGuid().ToString("N")
 726    ).TrimEnd(System.IO.Path.DirectorySeparatorChar);
 27
 728    Path = new PathSource(directory);
 729    Directory.CreateDirectory(Path.Directory.OriginalPath);
 730    LoggingScope.TryAddResult(new TextResult($"Created temp directory at {Path.Directory.OriginalPath}"));
 731  }
 32
 3633  public IPathSource Path { get; }
 34
 35  private bool _disposed;
 36  /// <summary>
 37  /// Dispose
 38  /// </summary>
 39  public void Dispose()
 40  {
 741    if (_disposed)
 142      return;
 643    _disposed = true;
 44
 645    Directory.Delete(Path.Directory.OriginalPath, true);
 646    LoggingScope.TryAddResult(new TextResult($"Deleting temp directory {Path.Directory.OriginalPath}"));
 647    GC.SuppressFinalize(this);
 648  }
 49
 50  public async Task<string> GetFileContentAsync(string relativePath, CancellationToken cancellationToken)
 51  {
 152    return await File.ReadAllTextAsync(Path.PathTranslator.GetAbsolutePath(relativePath).OriginalPath, cancellationToken
 153  }
 54
 55  public IEnumerable<string> GetRelativePaths()
 56  {
 157    return Directory.EnumerateFiles(Path.Directory.OriginalPath, "*", SearchOption.AllDirectories)
 258      .Select(d => Path.PathTranslator.GetRelativePath(d).VirtualPath);
 59  }
 60}