private void File_Create(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.RandomTxtFileFullPath; #if NET35 // MSDN: .NET 4+ Trailing spaces are removed from the end of the path parameter before deleting the directory. file += "\u3000"; // EMspace #endif Console.WriteLine("Input File Path: [{0}]\n", file); long fileLength; var tenNumbers = "0123456789"; var ten = tenNumbers.Length; using (var fs = Alphaleonis.Win32.Filesystem.File.Create(file)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". fs.Write(UnitTestConstants.StringToByteArray(tenNumbers), 0, ten); fileLength = fs.Length; } Assert.IsTrue(System.IO.File.Exists(file), "File should exist."); Assert.IsTrue(fileLength == ten, "The file is: {0} bytes, but is expected to be: {1} bytes.", fileLength, ten); } Console.WriteLine(); }
private void Open_Create(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; Console.WriteLine("\nInput File Path: [{0}]", file); long fileLength; var ten = UnitTestConstants.TenNumbers.Length; using (var fs = Alphaleonis.Win32.Filesystem.File.Open(file, System.IO.FileMode.Create)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". fs.Write(UnitTestConstants.StringToByteArray(UnitTestConstants.TenNumbers), 0, ten); fileLength = fs.Length; } Assert.IsTrue(System.IO.File.Exists(file), "The file does not exists, but is expected to."); Assert.IsTrue(fileLength == ten, "The file is: {0} bytes, but is expected to be: {1} bytes.", fileLength, ten); } Console.WriteLine(); }
private void File_Open_Create(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.RandomTxtFileFullPath; Console.WriteLine("Input File Path: [{0}]", file); long fileLength; var tenNumbers = "0123456789"; var ten = tenNumbers.Length; using (var fs = Alphaleonis.Win32.Filesystem.File.Open(file, System.IO.FileMode.Create)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". fs.Write(UnitTestConstants.StringToByteArray(tenNumbers), 0, ten); fileLength = fs.Length; } Assert.IsTrue(System.IO.File.Exists(file), "The file does not exists, but is expected to."); Assert.IsTrue(fileLength == ten, "The file is: {0} bytes, but is expected to be: {1} bytes.", fileLength, ten); } Console.WriteLine(); }
private void File_GetCompressedSize(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, "File-GetCompressedSize")) { var file = rootDir.RandomFileFullPath + ".txt"; Console.WriteLine("\nInput File Path: [{0}]", file); long streamLength; var thousand = 100 * UnitTestConstants.TenNumbers.Length; var compressedSize = 4096; // Size: 9,76 KB(10.000 bytes) // Size on disk: 12,0 KB(12.288 bytes) using (var fs = System.IO.File.Create(file)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". for (var count = 0; count < thousand; count++) { fs.Write(UnitTestConstants.StringToByteArray(UnitTestConstants.TenNumbers), 0, UnitTestConstants.TenNumbers.Length); } streamLength = fs.Length; } // Compress file. // Size on disk: 4,00 KB (4.096 bytes) Alphaleonis.Win32.Filesystem.File.Compress(file); var fileLength = Alphaleonis.Win32.Filesystem.File.GetCompressedSize(file); Assert.IsTrue(fileLength == compressedSize && fileLength != streamLength, "File should be [{0}] bytes in size.", compressedSize); } Console.WriteLine(); }
private void AlphaFS_File_GetCompressedSize(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var file = tempRoot.RandomTxtFileFullPath; Console.WriteLine("Input File Path: [{0}]", file); long streamLength; var tenNumbers = "0123456789"; var thousand = 100 * tenNumbers.Length; var compressedSize = 4096; // Size: 9,76 KB(10.000 bytes) // Size on disk: 12,0 KB(12.288 bytes) using (var fs = System.IO.File.Create(file)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". for (var count = 0; count < thousand; count++) { fs.Write(UnitTestConstants.StringToByteArray(tenNumbers), 0, tenNumbers.Length); } streamLength = fs.Length; } // Compress file. // Size on disk: 4,00 KB (4.096 bytes) Alphaleonis.Win32.Filesystem.File.Compress(file); var fileLength = Alphaleonis.Win32.Filesystem.File.GetCompressedSize(file); Assert.IsTrue(fileLength == compressedSize && fileLength != streamLength, "File should be [{0}] bytes in size.", compressedSize); } Console.WriteLine(); }
private void File_Create(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, "File.Create")) { var file = rootDir.RandomFileFullPath + ".txt"; #if NET35 // MSDN: .NET 4+ Trailing spaces are removed from the end of the path parameter before deleting the directory. file += UnitTestConstants.EMspace; #endif Console.WriteLine("\nInput File Path: [{0}]\n", file); long fileLength; var ten = UnitTestConstants.TenNumbers.Length; using (var fs = Alphaleonis.Win32.Filesystem.File.Create(file)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". fs.Write(UnitTestConstants.StringToByteArray(UnitTestConstants.TenNumbers), 0, ten); fileLength = fs.Length; } Assert.IsTrue(System.IO.File.Exists(file), "File should exist."); Assert.IsTrue(fileLength == ten, "The file is: {0} bytes, but is expected to be: {1} bytes.", fileLength, ten); } Console.WriteLine(); }
private void File_GetSize(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, "File-GetSize")) { var file = rootDir.RandomFileFullPath + ".txt"; Console.WriteLine("\nInput File Path: [{0}]]", file); long streamLength; var ten = UnitTestConstants.TenNumbers.Length; using (var fs = System.IO.File.Create(file)) { // According to NotePad++, creates a file type: "ANSI", which is reported as: "Unicode (UTF-8)". fs.Write(UnitTestConstants.StringToByteArray(UnitTestConstants.TenNumbers), 0, ten); streamLength = fs.Length; } var fileLength = Alphaleonis.Win32.Filesystem.File.GetSize(file); Assert.IsTrue(fileLength == ten && fileLength == streamLength, "File should be [{0}] bytes in size.", ten); } Console.WriteLine(); }