Esempio n. 1
0
        private void FileInfo_Refresh(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var file      = tempRoot.RandomTxtFileFullPath;
                var fiSysIo   = new System.IO.FileInfo(file + "-System.IO.txt");
                var fiAlphaFS = new Alphaleonis.Win32.Filesystem.FileInfo(file + "-AlphaFS.txt");

                Console.WriteLine("System.IO Input File Path: [{0}]", fiSysIo.FullName);
                Console.WriteLine("AlphaFS   Input File Path: [{0}]", fiAlphaFS.FullName);


                var existsSysIo = fiSysIo.Exists;
                var exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");


                var fsSysIo   = fiSysIo.Create();
                var fsAlphaFS = fiAlphaFS.Create();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");


                fiSysIo.Refresh();
                fiAlphaFS.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The file does not exists, but is expected to.");


                fsSysIo.Close();
                fsAlphaFS.Close();
                fiSysIo.Delete();
                fiAlphaFS.Delete();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The file does not exists, but is expected to.");


                fiSysIo.Refresh();
                fiAlphaFS.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");
            }

            Console.WriteLine();
        }
        private void FileInfo_Attributes(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                var file     = rootDir.RandomFileFullPath;
                var fileInfo = new Alphaleonis.Win32.Filesystem.FileInfo(file + "-AlphaFS");

                Console.WriteLine("\nAlphaFS Input File Path: [{0}]", fileInfo.FullName);

                using (fileInfo.Create())
                {
                    fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.ReadOnly) != 0, "The file is not ReadOnly, but is expected to.");

                    fileInfo.Attributes &= ~System.IO.FileAttributes.ReadOnly;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.ReadOnly) == 0, "The file is ReadOnly, but is expected not to.");


                    fileInfo.Attributes |= System.IO.FileAttributes.Hidden;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.Hidden) != 0, "The file is not Hidden, but is expected to.");

                    fileInfo.Attributes &= ~System.IO.FileAttributes.Hidden;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.Hidden) == 0, "The file is Hidden, but is expected not to.");


                    fileInfo.Attributes |= System.IO.FileAttributes.System;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.System) != 0, "The file is not System, but is expected to.");

                    fileInfo.Attributes &= ~System.IO.FileAttributes.System;
                    Assert.IsTrue((fileInfo.Attributes & System.IO.FileAttributes.System) == 0, "The file is System, but is expected not to.");
                }
            }

            Console.WriteLine();
        }
Esempio n. 3
0
        private void FileInfo_Attributes(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var file = tempRoot.RandomTxtFileFullPath;

                var alphaFSFileInfo = new Alphaleonis.Win32.Filesystem.FileInfo(file);


                Console.WriteLine("Input File Path: [{0}]", alphaFSFileInfo.FullName);

                using (alphaFSFileInfo.Create())
                {
                    alphaFSFileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.ReadOnly) != 0, "The file is not ReadOnly, but is expected to.");

                    alphaFSFileInfo.Attributes &= ~System.IO.FileAttributes.ReadOnly;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.ReadOnly) == 0, "The file is ReadOnly, but is expected not to.");


                    alphaFSFileInfo.Attributes |= System.IO.FileAttributes.Hidden;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.Hidden) != 0, "The file is not Hidden, but is expected to.");

                    alphaFSFileInfo.Attributes &= ~System.IO.FileAttributes.Hidden;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.Hidden) == 0, "The file is Hidden, but is expected not to.");


                    alphaFSFileInfo.Attributes |= System.IO.FileAttributes.System;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.System) != 0, "The file is not System, but is expected to.");

                    alphaFSFileInfo.Attributes &= ~System.IO.FileAttributes.System;
                    Assert.IsTrue((alphaFSFileInfo.Attributes & System.IO.FileAttributes.System) == 0, "The file is System, but is expected not to.");
                }
            }

            Console.WriteLine();
        }
Esempio n. 4
0
        private void FileInfo_Refresh(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "FileInfo.Refresh"))
            {
                var file      = rootDir.RandomFileFullPath;
                var fiSysIo   = new System.IO.FileInfo(file + "-System.IO.txt");
                var fiAlphaFS = new Alphaleonis.Win32.Filesystem.FileInfo(file + "-AlphaFS.txt");

                Console.WriteLine("\nSystem.IO Input File Path: [{0}]", fiSysIo.FullName);
                Console.WriteLine("AlphaFS   Input File Path: [{0}]", fiAlphaFS.FullName);


                var existsSysIo = fiSysIo.Exists;
                var exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");


                var fsSysIo   = fiSysIo.Create();
                var fsAlphaFS = fiAlphaFS.Create();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");


                fiSysIo.Refresh();
                fiAlphaFS.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The file does not exists, but is expected to.");


                fsSysIo.Close();
                fsAlphaFS.Close();
                fiSysIo.Delete();
                fiAlphaFS.Delete();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The file does not exists, but is expected to.");


                fiSysIo.Refresh();
                fiAlphaFS.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fiAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The file exists, but is expected not to.");
            }

            Console.WriteLine();
        }
 public override Stream Create()
 {
     return(instance.Create());
 }
Esempio n. 6
0
        private void DumpRefresh(bool isLocal)
        {
            #region Setup

            Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network);

            string tempPathSysIo = Path.GetTempPath("FileInfo.Refresh()-file-SysIo-" + Path.GetRandomFileName());
            string tempPath      = Path.GetTempPath("FileInfo.Refresh()-file-AlphaFS-" + Path.GetRandomFileName());
            if (!isLocal)
            {
                tempPathSysIo = Path.LocalToUnc(tempPathSysIo);
            }
            if (!isLocal)
            {
                tempPath = Path.LocalToUnc(tempPath);
            }

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

            #endregion // Setup

            #region Refresh

            try
            {
                System.IO.FileInfo fiSysIo = new System.IO.FileInfo(tempPathSysIo);
                FileInfo           fi      = new FileInfo(tempPath);

                bool existsSysIo = fiSysIo.Exists;
                bool exists      = fi.Exists;
                Console.WriteLine("\nnew FileInfo(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false
                Assert.AreEqual(existsSysIo, exists);

                FileStream fsSysIo = fiSysIo.Create();
                FileStream fs      = fi.Create();
                existsSysIo = fiSysIo.Exists;
                exists      = fi.Exists;
                Console.WriteLine("\nfi.Create(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false
                Assert.AreEqual(existsSysIo, exists);

                fiSysIo.Refresh();
                fi.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fi.Exists;
                Console.WriteLine("\nfi.Refresh(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
                Assert.AreEqual(existsSysIo, exists);

                fsSysIo.Close();
                fs.Close();
                existsSysIo = fiSysIo.Exists;
                exists      = fi.Exists;
                Console.WriteLine("\nfi.Close(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
                Assert.AreEqual(existsSysIo, exists);

                fiSysIo.Delete();
                fi.Delete();
                existsSysIo = fiSysIo.Exists;
                exists      = fi.Exists;
                Console.WriteLine("\nfi.Delete(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
                Assert.AreEqual(existsSysIo, exists);

                fiSysIo.Refresh();
                fi.Refresh();
                existsSysIo = fiSysIo.Exists;
                exists      = fi.Exists;
                Console.WriteLine("\nfi.Refresh(): Exists (Should be False): [{0}]", exists); // false
                Assert.AreEqual(existsSysIo, exists);
            }
            finally
            {
                File.Delete(tempPath);
                Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");

                File.Delete(tempPathSysIo);
                Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");
                Console.WriteLine();
            }

            #endregion // Refresh
        }
Esempio n. 7
0
      private void DumpRefresh(bool isLocal)
      {
         #region Setup

         Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network);

         string tempPathSysIo = Path.GetTempPath("FileInfo.Refresh()-file-SysIo-" + Path.GetRandomFileName());
         string tempPath = Path.GetTempPath("FileInfo.Refresh()-file-AlphaFS-" + Path.GetRandomFileName());
         if (!isLocal) tempPathSysIo = Path.LocalToUnc(tempPathSysIo);
         if (!isLocal) tempPath = Path.LocalToUnc(tempPath);

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

         #endregion // Setup

         #region Refresh

         try
         {
            System.IO.FileInfo fiSysIo = new System.IO.FileInfo(tempPathSysIo);
            FileInfo fi = new FileInfo(tempPath);

            bool existsSysIo = fiSysIo.Exists;
            bool exists = fi.Exists;
            Console.WriteLine("\nnew FileInfo(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false
            Assert.AreEqual(existsSysIo, exists);

            FileStream fsSysIo = fiSysIo.Create();
            FileStream fs = fi.Create();
            existsSysIo = fiSysIo.Exists;
            exists = fi.Exists;
            Console.WriteLine("\nfi.Create(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // false
            Assert.AreEqual(existsSysIo, exists);

            fiSysIo.Refresh();
            fi.Refresh();
            existsSysIo = fiSysIo.Exists;
            exists = fi.Exists;
            Console.WriteLine("\nfi.Refresh(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
            Assert.AreEqual(existsSysIo, exists);

            fsSysIo.Close();
            fs.Close();
            existsSysIo = fiSysIo.Exists;
            exists = fi.Exists;
            Console.WriteLine("\nfi.Close(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
            Assert.AreEqual(existsSysIo, exists);

            fiSysIo.Delete();
            fi.Delete();
            existsSysIo = fiSysIo.Exists;
            exists = fi.Exists;
            Console.WriteLine("\nfi.Delete(): Exists (Should be {0}): [{1}]", existsSysIo, exists); // true
            Assert.AreEqual(existsSysIo, exists);
            
            fiSysIo.Refresh();
            fi.Refresh();
            existsSysIo = fiSysIo.Exists;
            exists = fi.Exists;
            Console.WriteLine("\nfi.Refresh(): Exists (Should be False): [{0}]", exists); // false
            Assert.AreEqual(existsSysIo, exists);
         }
         finally
         {
            File.Delete(tempPath);
            Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");

            File.Delete(tempPathSysIo);
            Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");
            Console.WriteLine();
         }

         #endregion // Refresh
      }