Exemplo n.º 1
0
        private void DumpClassByHandleFileInfo(bool isLocal)
        {
            Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network);
            var tempPath = Path.GetTempPath("File.GetFileInfoByHandle()-" + Path.GetRandomFileName());

            if (!isLocal)
            {
                tempPath = Path.LocalToUnc(tempPath);
            }

            Console.WriteLine("\nInput File Path: [{0}]", tempPath);

            var stream = File.Create(tempPath);

            stream.WriteByte(1);

            UnitTestConstants.StopWatcher(true);
            var bhfi = File.GetFileInfoByHandle(stream.SafeFileHandle);

            Console.WriteLine(UnitTestConstants.Reporter());

            Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));

            Assert.AreEqual(System.IO.File.GetCreationTimeUtc(tempPath), bhfi.CreationTimeUtc);
            Assert.AreEqual(System.IO.File.GetLastAccessTimeUtc(tempPath), bhfi.LastAccessTimeUtc);
            Assert.AreEqual(System.IO.File.GetLastWriteTimeUtc(tempPath), bhfi.LastWriteTimeUtc);

            stream.Close();

            File.Delete(tempPath, true);
            Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");
            Console.WriteLine();
        }
 public static ByHandleFileInfo GetFileInfoByHandle(SafeFileHandle handle)
 {
     return(File.GetFileInfoByHandle(handle));
 }