private void AlphaFS_Directory_Compress_And_Decompress(bool isNetwork, bool recursive) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.RandomDirectoryFullPath; Console.WriteLine("Input Directory Path: [{0}]", folder); var folderAaa = System.IO.Path.Combine(folder, "folder-aaa"); var folderBbb = System.IO.Path.Combine(folder, "folder-bbb"); var folderCcc = System.IO.Path.Combine(folderBbb, "folder-ccc"); System.IO.Directory.CreateDirectory(folderAaa); System.IO.Directory.CreateDirectory(folderBbb); System.IO.Directory.CreateDirectory(folderCcc); var fileAaa = System.IO.Path.Combine(folderAaa, "file-aaa.txt"); var fileBbb = System.IO.Path.Combine(folderAaa, "file-bbb.txt"); var fileCcc = System.IO.Path.Combine(folder, "file-ccc.txt"); var fileDdd = System.IO.Path.Combine(folder, "file-ddd.txt"); using (System.IO.File.CreateText(fileAaa)) { } using (System.IO.File.CreateText(fileBbb)) { } using (System.IO.File.CreateText(fileCcc)) { } using (System.IO.File.CreateText(fileDdd)) { } Alphaleonis.Win32.Filesystem.Directory.Compress(folder, recursive ? Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive : Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.None); DirectoryAssert.IsCompressed(folder); DirectoryAssert.IsCompressed(folderAaa); DirectoryAssert.IsCompressed(folderBbb); FileAssert.IsCompressed(fileCcc); FileAssert.IsCompressed(fileDdd); if (recursive) { DirectoryAssert.IsCompressed(folderCcc); FileAssert.IsCompressed(fileAaa); FileAssert.IsCompressed(fileBbb); } else { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } Alphaleonis.Win32.Filesystem.Directory.Decompress(folder, recursive ? Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive : Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.None); if (recursive) { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } else { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } } Console.WriteLine(); }
private void Directory_Compress_Decompress(bool isNetwork, bool recursive) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, "Directory.Decompress")) { var rootFolder = rootDir.RandomFileFullPath + ".txt"; Console.WriteLine("\nInput Directory Path: [{0}]", rootFolder); var folderAaa = System.IO.Path.Combine(rootFolder, "folder-aaa"); var folderBbb = System.IO.Path.Combine(rootFolder, "folder-bbb"); var folderCcc = System.IO.Path.Combine(folderBbb, "folder-ccc"); System.IO.Directory.CreateDirectory(folderAaa); System.IO.Directory.CreateDirectory(folderBbb); System.IO.Directory.CreateDirectory(folderCcc); var fileAaa = System.IO.Path.Combine(folderAaa, "file-aaa.txt"); var fileBbb = System.IO.Path.Combine(folderAaa, "file-bbb.txt"); var fileCcc = System.IO.Path.Combine(rootFolder, "file-ccc.txt"); var fileDdd = System.IO.Path.Combine(rootFolder, "file-ddd.txt"); using (System.IO.File.CreateText(fileAaa)) { } using (System.IO.File.CreateText(fileBbb)) { } using (System.IO.File.CreateText(fileCcc)) { } using (System.IO.File.CreateText(fileDdd)) { } Alphaleonis.Win32.Filesystem.Directory.Compress(rootFolder, recursive ? Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive : Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.None); DirectoryAssert.IsCompressed(rootFolder); DirectoryAssert.IsCompressed(folderAaa); DirectoryAssert.IsCompressed(folderBbb); FileAssert.IsCompressed(fileCcc); FileAssert.IsCompressed(fileDdd); if (recursive) { DirectoryAssert.IsCompressed(folderCcc); FileAssert.IsCompressed(fileAaa); FileAssert.IsCompressed(fileBbb); } else { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } Alphaleonis.Win32.Filesystem.Directory.Decompress(rootFolder, recursive ? Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive : Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.None); if (recursive) { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } else { DirectoryAssert.IsNotCompressed(folderCcc); FileAssert.IsNotCompressed(fileAaa); FileAssert.IsNotCompressed(fileBbb); } } Console.WriteLine(); }