public void TestOpenHidden() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file25.ext").ToString(); var fi = new FileInfo(tempLongPathFilename); using (fi.Create()) { } try { Assert.Throws <UnauthorizedAccessException>(() => { File.SetAttributes(fi.FullName, File.GetAttributes(fi.FullName) | FileAttributes.Hidden); using (var fileStream = fi.Open(FileMode.Create)) { Assert.IsNotNull(fileStream); } }); } finally { File.Delete(tempLongPathFilename); } }
public void TestCreate() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file19.ext").ToString(); var fi = new FileInfo(tempLongPathFilename); Assert.IsFalse(fi.Exists); using (fi.Create()) { } try { Assert.IsTrue(File.Exists(fi.FullName)); // don't use FileInfo.Exists, it caches existance } finally { fi.Delete(); } }
public void TestOpenHidden() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file25.ext").ToString(); var fi = new FileInfo(tempLongPathFilename); using (fi.Create()) { } try { File.SetAttributes(fi.FullName, File.GetAttributes(fi.FullName) | FileAttributes.Hidden); using (var fileStream = fi.Open(FileMode.Create)) { Assert.IsNotNull(fileStream); } } finally { File.Delete(tempLongPathFilename); } }
public void TestGetFileSystemInfosWithSearchAndOptionNoResults() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(0, di.GetFileSystemInfos("gibberish", SearchOption.TopDirectoryOnly).Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestGetFileSystemInfosWithSearch() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(2, di.GetFileSystemInfos("*").Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestEnumerateFilesWithSearchRecursiveAndOption() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(0, di.EnumerateFiles("gibberish", SearchOption.AllDirectories).Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestEnumerateFiles() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(1, di.EnumerateFiles().Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestEnumerateFileSystemInfosWithSearchNoResults() { var di = new DirectoryInfo(longPathDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(0, di.EnumerateFileSystemInfos("gibberish").Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestEnumerateFilesWithSearchAndOption() { var di = new DirectoryInfo(longPathDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(Path.Combine(newDi.FullName, "filename")); using (fi.Create()) { } try { Assert.AreEqual(1, di.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }