< Summary

Information
Class: Amusoft.DotnetNew.Tests.Scaffolding.Scaffold
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Scaffolding/Scaffold.cs
Tag: 127_14865883074
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 123
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%
BuildAsync()100%11100%
RestoreAsync()100%11100%
TestAsync()100%11100%
GetFileContentAsync()100%11100%
GetAllFileContentsAsync()100%88100%
GetAbsoluteRootPath()100%11100%
GetRelativeDirectoryPaths()100%11100%
Dispose()100%22100%

File(s)

/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Scaffolding/Scaffold.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Runtime.CompilerServices;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using Amusoft.DotnetNew.Tests.CLI;
 8using Amusoft.DotnetNew.Tests.Interfaces;
 9using Amusoft.DotnetNew.Tests.Templating;
 10
 11namespace Amusoft.DotnetNew.Tests.Scaffolding;
 12
 13/// <summary>
 14///
 15/// </summary>
 16public class Scaffold : IDisposable
 17{
 18  private readonly ITempDirectory _tempDirectory;
 19  private readonly IDotnetCli _cli;
 20
 921  internal Scaffold(ITempDirectory tempDirectory, IDotnetCli cli)
 22  {
 923    _tempDirectory = tempDirectory;
 924    _cli = cli;
 925  }
 26
 27  /// <summary>
 28  /// Builds the project at a given path
 29  /// </summary>
 30  /// <param name="relativePath">relative path of the project/solution you want to build within the scaffold. e.g. src/S
 31  /// <param name="arguments">build arguments</param>
 32  /// <param name="cancellationToken">cancellation token</param>
 33  /// <param name="verbosity"></param>
 34  /// <param name="restore"></param>
 35  public async Task BuildAsync(string relativePath, string? arguments, CancellationToken cancellationToken, Verbosity ve
 36  {
 137    await _cli.BuildAsync(_tempDirectory.Path.PathTranslator.GetAbsolutePath(relativePath).OriginalPath, arguments, verb
 138  }
 39
 40  /// <summary>
 41  /// Builds the project at a given path
 42  /// </summary>
 43  /// <param name="relativePath">relative path of the project/solution you want to build within the scaffold. e.g. src/S
 44  /// <param name="arguments">build arguments</param>
 45  /// <param name="cancellationToken">cancellation token</param>
 46  /// <param name="verbosity"></param>
 47  public async Task RestoreAsync(string relativePath, string? arguments, CancellationToken cancellationToken, Verbosity 
 48  {
 149    await _cli.RestoreAsync(_tempDirectory.Path.PathTranslator.GetAbsolutePath(relativePath).OriginalPath, arguments, ve
 150  }
 51
 52  /// <summary>
 53  /// Builds the project at a given path
 54  /// </summary>
 55  /// <param name="relativePath">relative path of the project/solution you want to build within the scaffold. e.g. src/S
 56  /// <param name="arguments">build arguments</param>
 57  /// <param name="cancellationToken">cancellation token</param>
 58  /// <param name="verbosity"></param>
 59  public async Task TestAsync(string relativePath, string? arguments, CancellationToken cancellationToken, Verbosity ver
 60  {
 161    await _cli.TestAsync(_tempDirectory.Path.PathTranslator.GetAbsolutePath(relativePath).OriginalPath, arguments, verbo
 162  }
 63
 64  /// <summary>
 65  /// Returns the file contents for a given relative path
 66  /// </summary>
 67  /// <param name="relativePath">path relative to scaffold folder</param>
 68  /// <param name="cancellationToken">cancellation token</param>
 69  /// <returns></returns>
 70  public async Task<string> GetFileContentAsync(string relativePath, CancellationToken cancellationToken = default)
 71  {
 572    return await _tempDirectory.GetFileContentAsync(relativePath, cancellationToken).ConfigureAwait(false);
 573  }
 74
 75  /// <summary>
 76  /// Returns the content of all scaffolded files
 77  /// </summary>
 78  /// <param name="filter">true removes a file from the results, false keeps it</param>
 79  /// <param name="cancellationToken"></param>
 80  /// <returns></returns>
 81  public async IAsyncEnumerable<FileContent> GetAllFileContentsAsync(RelativeFileFilter? filter = default, [EnumeratorCa
 82  {
 383    var filterInstance = filter ?? TemplatingDefaults.Instance.GetAllFileContentsFilter;
 2484    foreach (var relativePath in GetRelativeDirectoryPaths())
 85    {
 986      if(filterInstance(relativePath))
 87        continue;
 88
 589      cancellationToken.ThrowIfCancellationRequested();
 590      var content = await GetFileContentAsync(relativePath, cancellationToken);
 591      yield return new FileContent(relativePath, content);
 592    }
 393  }
 94
 95  /// <summary>
 96  /// Returns the directory path of the scaffold
 97  /// </summary>
 98  /// <returns></returns>
 199  public string GetAbsoluteRootPath() => _tempDirectory.Path.File.OriginalPath;
 100
 101  /// <summary>
 102  /// Gets all paths within the temp directory with their relative paths
 103  /// </summary>
 104  /// <returns></returns>
 105  public IEnumerable<string> GetRelativeDirectoryPaths()
 106  {
 12107    return _tempDirectory.GetRelativePaths().OrderBy(d => d);
 108  }
 109
 110  private bool _disposed;
 111  /// <summary>
 112  ///
 113  /// </summary>
 114  public void Dispose()
 115  {
 2116    if (_disposed)
 1117      return;
 1118    _disposed = true;
 119
 1120    _tempDirectory.Dispose();
 1121    GC.SuppressFinalize(this);
 1122  }
 123}