public void TestFindFileInfo() { int ix = 0; FileInfo[] expected = new DirectoryInfo(TestFolder).GetFiles("*"); FindFile.FilesIn(TestFolder, args => { FindFile.Info e = args.GetInfo(); Assert.AreEqual(expected[ix].Attributes, e.Attributes); Assert.AreEqual(expected[ix].FullName, e.FullPath); Assert.AreEqual(expected[ix].Extension, e.Extension); Assert.AreEqual(expected[ix].Name, e.Name); Assert.AreEqual(expected[ix].Length, e.Length); Assert.AreEqual(expected[ix].CreationTimeUtc, e.CreationTimeUtc); Assert.AreEqual(expected[ix].LastAccessTimeUtc, e.LastAccessTimeUtc); Assert.AreEqual(expected[ix].LastWriteTimeUtc, e.LastWriteTimeUtc); Assert.AreEqual(FindFile.UncPrefix + expected[ix].FullName, e.FullPathUnc); Assert.AreEqual(Path.GetDirectoryName(expected[ix].FullName).TrimEnd('\\'), e.ParentPath.TrimEnd('\\')); Assert.AreEqual(FindFile.UncPrefix + Path.GetDirectoryName(expected[ix].FullName).TrimEnd('\\'), e.ParentPathUnc.TrimEnd('\\')); ix++; }); Assert.AreEqual(expected.Length, ix); }
public void TestFileFoundArgs() { int ix = 0; FileInfo[] expected = new DirectoryInfo(TestFolder).GetFiles(); FindFile.FilesIn(TestFolder, e => { Assert.AreEqual(expected[ix].Attributes, e.Attributes); Assert.AreEqual(expected[ix].FullName, e.FullPath); Assert.AreEqual(expected[ix].Extension, e.Extension); Assert.AreEqual(expected[ix].Name, e.Name); Assert.AreEqual(expected[ix].Length, e.Length); Assert.AreEqual(expected[ix].CreationTimeUtc, e.CreationTimeUtc); Assert.AreEqual(expected[ix].LastAccessTimeUtc, e.LastAccessTimeUtc); Assert.AreEqual(expected[ix].LastWriteTimeUtc, e.LastWriteTimeUtc); Assert.AreEqual(FindFile.UncPrefix + expected[ix].FullName, e.FullPathUnc); Assert.AreEqual(Path.GetDirectoryName(expected[ix].FullName).TrimEnd('\\'), e.ParentPath.TrimEnd('\\')); Assert.AreEqual(FindFile.UncPrefix + Path.GetDirectoryName(expected[ix].FullName).TrimEnd('\\'), e.ParentPathUnc.TrimEnd('\\')); Assert.AreEqual(false, e.CancelEnumeration); Assert.AreEqual(false, e.IsCompressed); Assert.AreEqual(false, e.IsDirectory); Assert.AreEqual(false, e.IsEncrypted); Assert.AreEqual(false, e.IsHidden); Assert.AreEqual(false, e.IsOffline); Assert.AreEqual(false, e.IsReadOnly); Assert.AreEqual(false, e.IsReparsePoint); Assert.AreEqual(false, e.IsSystem); ix++; }); Assert.AreEqual(expected.Length, ix); }
public void TestFilesAndFolders() { int files = 0, folders = 0, total = 0; string dir = TestFolder; FindFile.FilesIn(dir, e => { Assert.IsTrue(File.Exists(e.FullPath)); files++; }); FindFile.FoldersIn(dir, e => { Assert.IsTrue(Directory.Exists(e.FullPath)); folders++; }); FindFile.FilesAndFoldersIn(dir, e => { Assert.IsTrue(File.Exists(e.FullPath) || Directory.Exists(e.FullPath)); total++; }); Assert.AreEqual(3, files); Assert.AreEqual(1, folders); Assert.AreEqual(4, total); }