private IReadOnlyFileSystem GetFileSystem() { IReadOnlyFileSystem fileSystem = Substitute.For <IReadOnlyFileSystem>(); IFileProvider fileProvider = GetFileProvider(); fileSystem.GetInputFile(Arg.Any <FilePath>()).Returns(x => { FilePath path = x.ArgAt <FilePath>(0); if (!path.IsAbsolute) { path = new FilePath("/" + path.FullPath); } return(fileProvider.GetFile(path)); }); fileSystem.GetInputDirectory(Arg.Any <DirectoryPath>()).Returns(x => fileProvider.GetDirectory(x.ArgAt <DirectoryPath>(0))); return(fileSystem); }
/// <summary> /// Gets matching input files based on globbing patterns and/or absolute paths. If any absolute paths /// are provided, only those that actually exist are returned. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="patterns">The globbing patterns and/or absolute paths.</param> /// <returns>All input files that match the globbing patterns and/or absolute paths.</returns> public static IEnumerable <IFile> GetInputFiles(this IReadOnlyFileSystem fileSystem, IEnumerable <string> patterns) { _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); return(fileSystem.GetFiles(fileSystem.GetInputDirectory(), patterns)); }
/// <summary> /// Gets a directory representing an input. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns>An input directory.</returns> public static IDirectory GetInputDirectory(this IReadOnlyFileSystem fileSystem) => fileSystem.GetInputDirectory(NormalizedPath.Null);