示例#1
0
        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);
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
 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);
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
 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);
     }
 }
示例#9
0
 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);
     }
 }
示例#10
0
 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);
     }
 }