public void CanRecurseFromRoot() { string root = Path.GetPathRoot(Path.GetTempPath()); using (var recursed = new DirectoryRecursed(root, new EnumerationOptions { AttributesToSkip = FileAttributes.System, RecurseSubdirectories = true })) { while (recursed.MoveNext()) { if (recursed.LastDirectory != null) { Assert.Equal(root, recursed.LastDirectory); return; } // Should start with the root and shouldn't have a separator after the root Assert.StartsWith(root, recursed.Current); Assert.True(recursed.Current.LastIndexOf(Path.DirectorySeparatorChar) < root.Length, $"should have no separators pasth the root '{root}' in in '{recursed.Current}'"); } Assert.NotNull(recursed.LastDirectory); } }
public void SpecialDirectoriesAreNotUpForRecursion() { using (var recursed = new DirectoryRecursed(TestDirectory, new EnumerationOptions { ReturnSpecialDirectories = true, RecurseSubdirectories = true, AttributesToSkip = 0 })) { List <string> results = new List <string>(); while (recursed.MoveNext()) { results.Add(recursed.Current); } Assert.Equal(0, recursed.ShouldRecurseCalls); Assert.Contains("..", results); } }
public void CanRecurseFromRoot() { string root = Path.GetPathRoot(Path.GetTempPath()); using (var recursed = new DirectoryRecursed(root, new EnumerationOptions { AttributesToSkip = FileAttributes.System, RecurseSubdirectories = true })) { while (recursed.MoveNext()) { if (recursed.LastDirectory != null) { Assert.Equal(root, recursed.LastDirectory); return; } // Should not get back a full path without a single separator (C:\foo.txt or /foo.txt) Assert.Equal(Path.DirectorySeparatorChar, recursed.Current.SingleOrDefault(c => c == Path.DirectorySeparatorChar)); } Assert.NotNull(recursed.LastDirectory); } }