private void File_ExportImportEncryptedFileRaw(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.ExportImportEncryptedFileRaw"))
            {
                // Create an encrypted file to use for testing
                var inputFile = System.IO.Path.Combine(rootDir.Directory.FullName, "test.txt");
                System.IO.File.WriteAllText(inputFile, "Test file #1");

                Alphaleonis.Win32.Filesystem.File.Encrypt(inputFile);
                Console.WriteLine("\nEncrypted Input File: [{0}]", inputFile);


                // Export the file using the method under test.
                var exportedFile = System.IO.Path.Combine(rootDir.Directory.FullName, "export.dat");
                using (var fs = System.IO.File.Create(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw(inputFile, fs);
                Console.WriteLine("\nExported Input File: [{0}]", exportedFile);


                FileAssert.Exists(exportedFile);
                FileAssert.IsNotEncrypted(exportedFile);
                FileAssert.AreNotEqual(inputFile, exportedFile);


                // Import the file again.
                var importedFile = System.IO.Path.Combine(rootDir.Directory.FullName, "import.txt");
                using (var fs = System.IO.File.OpenRead(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw(fs, importedFile);
                Console.WriteLine("\nImported Input File: [{0}]", importedFile);


                // Verify that the imported file contents are equal to the original ones.
                FileAssert.Exists(importedFile);
                FileAssert.AreEqual(inputFile, importedFile);
                FileAssert.IsEncrypted(importedFile);
            }
        }
Beispiel #2
0
        private void AlphaFS_File_ExportImportEncryptedFileRaw(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                // Create an encrypted file to use for testing
                var inputFile = System.IO.Path.Combine(tempRoot.Directory.FullName, "test.txt");
                System.IO.File.WriteAllText(inputFile, "Test file #1");

                Alphaleonis.Win32.Filesystem.File.Encrypt(inputFile);
                Console.WriteLine("Encrypted Input File: [{0}]", inputFile);


                // Export the file using the method under test.
                var exportedFile = System.IO.Path.Combine(tempRoot.Directory.FullName, "export.dat");

                using (var fs = System.IO.File.Create(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw(inputFile, fs);

                Console.WriteLine("\nExported Input File: [{0}]", exportedFile);


                FileAssert.Exists(exportedFile);
                FileAssert.IsNotEncrypted(exportedFile);
                FileAssert.AreNotEqual(inputFile, exportedFile);


                // Import the file again.
                var importedFile = System.IO.Path.Combine(tempRoot.Directory.FullName, "import.txt");

                using (var fs = System.IO.File.OpenRead(exportedFile))
                    Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw(fs, importedFile);

                Console.WriteLine("\nImported Input File: [{0}]", importedFile);


                // Verify that the imported file contents are equal to the original ones.
                FileAssert.Exists(importedFile);
                FileAssert.AreEqual(inputFile, importedFile);
                FileAssert.IsEncrypted(importedFile);
            }

            Console.WriteLine();
        }