public void EnumerateFilesPassesCorrectArguments() { IDirectoryInformation info = Substitute.For <IDirectoryInformation>(); info.EnumerateFiles("foo", SearchOption.AllDirectories, 0); info.Received(1).EnumerateChildren(ChildType.File, "foo", SearchOption.AllDirectories, 0); }
protected override ExitCode ExecuteFileTask() { var fileService = this.GetService <IFileService>(); Table output = Table.Create( new ColumnFormat(1), new ColumnFormat(1), new ColumnFormat(1, ContentVisibility.Default, Justification.Right), new ColumnFormat(4)); output.HasHeader = false; int directoryCount = 0; int fileCount = 0; ulong totalSize = 0; IDirectoryInformation directory = fileService.GetDirectoryInfo(GetFullTargetPath()); foreach (var subdir in directory.EnumerateDirectories().OrderBy(i => i.Name)) { directoryCount++; this.AddToTable(output, subdir); } foreach (var file in directory.EnumerateFiles().OrderBy(i => i.Name)) { fileCount++; totalSize += file.Length; this.AddToTable(output, file); } this.Loggers[LoggerType.Status].WriteLine($" Directory of {directory.Path}"); this.Loggers[LoggerType.Status].WriteLine(); this.Loggers[LoggerType.Result].Write(output); this.Loggers[LoggerType.Status].WriteLine(); this.Loggers[LoggerType.Status].WriteLine($" {directoryCount} Dir(s) {fileCount} File(s) {totalSize:N0} bytes"); return(ExitCode.Success); }