コード例 #1
0
 /// <summary>
 /// Walk directories in the current directory. Allows filtering by attributes. Folders with the given attributes will be skipped as well.
 /// </summary>
 /// <param name="fileSystemInformation">If the information is not a directory, returns an empty enumerable.</param>
 public static IEnumerable <IDirectoryInformation> EnumerateDirectories(
     this IDirectoryInformation directoryInformation,
     string searchPattern             = "*",
     SearchOption searchOption        = SearchOption.TopDirectoryOnly,
     FileAttributes excludeAttributes = FileAttributes.Hidden | FileAttributes.System | FileAttributes.ReparsePoint)
 {
     return(directoryInformation.EnumerateChildren(ChildType.Directory, searchPattern, searchOption, excludeAttributes).OfType <IDirectoryInformation>());
 }
コード例 #2
0
ファイル: FileCleanerTests.cs プロジェクト: ramarag/XTask
        public void CleanupHandlesDirectoryExceptions()
        {
            IFileService fileServiceProvider = Substitute.For <IFileService>();
            MemoryStream memoryStream        = new MemoryStream();

            fileServiceProvider.CreateFileStream("").ReturnsForAnyArgs(memoryStream);
            IDirectoryInformation directoryInfo = Substitute.For <IDirectoryInformation>();
            IFileInformation      fileInfo      = Substitute.For <IFileInformation>();

            directoryInfo.EnumerateChildren().ReturnsForAnyArgs(new IFileInformation[] { fileInfo });
            fileServiceProvider.GetPathInfo("").ReturnsForAnyArgs(directoryInfo);

            using (FileCleaner cleaner = new FileCleaner("Test", fileServiceProvider))
            {
                fileServiceProvider.WhenForAnyArgs(f => f.DeleteDirectory("")).Do(a => { throw new Exception("TestException"); });
            }
        }