public void FileExtensions_AesTests() { const string testFileData = "A whole new testing world."; var folderList = new List <string> { "Aes" }; var baseFolderPath = string.Format(@"{0}{1}", WebsiteSharePath, @"Aes"); var baseFilePath = string.Format(@"{0}\{1}", baseFolderPath, "AesFile_"); using (new Impersonation(Domain, Username, Password)) { Assert.IsTrue(Directory.Exists(WebsiteSharePath)); FileExtensions.CreateDirectories(WebsiteSharePath, folderList, Domain, Username); // CreateFile | ReadFile var createFilePath = string.Format("{0}{1}", baseFilePath, "CreateFile.txt"); FileExtensions.CreateFile(createFilePath, Domain, Username, testFileData); var createFileData = FileExtensions.ReadFile(createFilePath, Domain, Username); Assert.AreEqual(testFileData, createFileData); // CreateFileAsync | ReadFileAsync var createFileAsyncPath = string.Format("{0}{1}", baseFilePath, "CreateFileAsync.txt"); FileExtensions.CreateFileAsync(createFileAsyncPath, Domain, Username, testFileData).Wait(); var createFileDataAsync = FileExtensions.ReadFileAsync(createFileAsyncPath, Domain, Username).Result; Assert.AreEqual(testFileData, createFileDataAsync); // CreateAesEncryptedFile | ReadAesEncryptedFile var createAesEncryptedFilePath = string.Format("{0}{1}", baseFilePath, "CreateAesEncryptedFile.txt"); FileExtensions.CreateAesEncrytpedFile(createAesEncryptedFilePath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize); var createAesEncryptedFileData = FileExtensions.ReadAesEncryptedFile(createAesEncryptedFilePath, Domain, Username, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize); Assert.AreEqual(testFileData, createAesEncryptedFileData); // CreateAesEncryptedFileAsync | ReadAesEncryptedFileAsync var createAesEncryptedFileAsyncPath = string.Format("{0}{1}", baseFilePath, "CreateAesEncryptedFileAsync.txt"); FileExtensions.CreateAesEncrytpedFileAsync(createAesEncryptedFileAsyncPath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Wait(); var createAesEncryptedFileDataAsync = FileExtensions.ReadAesEncryptedFileAsync(createAesEncryptedFileAsyncPath, Domain, Username, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Result; Assert.AreEqual(testFileData, createAesEncryptedFileDataAsync); var appendTestFileData = testFileData + testFileData; // AppendFile | ReadFile var appendFilePath = string.Format("{0}{1}", baseFilePath, "AppendFile.txt"); FileExtensions.CreateFile(appendFilePath, Domain, Username, testFileData); FileExtensions.AppendFile(appendFilePath, Domain, Username, testFileData); var appendFileData = FileExtensions.ReadFile(appendFilePath, Domain, Username); Assert.AreEqual(appendTestFileData, appendFileData); // AppendFileAsync | ReadFileAsync var appendFileAsyncPath = string.Format("{0}{1}", baseFilePath, "AppendFileAsync.txt"); FileExtensions.CreateFileAsync(appendFileAsyncPath, Domain, Username, testFileData).Wait(); FileExtensions.AppendFileAsync(appendFileAsyncPath, Domain, Username, testFileData).Wait(); var appendFileDataAsync = FileExtensions.ReadFileAsync(appendFileAsyncPath, Domain, Username).Result; Assert.AreEqual(appendTestFileData, appendFileDataAsync); // AppendAesEncryptedFile | ReadAesEncryptedFile var appendAesEncryptedFilePath = string.Format("{0}{1}", baseFilePath, "AppendAesEncryptedFile.txt"); FileExtensions.CreateAesEncrytpedFile(appendAesEncryptedFilePath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize); FileExtensions.AppendAesEncrytpedFile(appendAesEncryptedFilePath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize); var appendAesEncryptedFileData = FileExtensions.ReadAesEncryptedFile(appendAesEncryptedFilePath, Domain, Username, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize); Assert.AreEqual(appendTestFileData, appendAesEncryptedFileData); // AppendAesEncryptedFileAsync | ReadAesEncryptedFileAsync var appendAesEncryptedFileAsyncPath = string.Format("{0}{1}", baseFilePath, "AppendAesEncryptedFileAsync.txt"); FileExtensions.CreateAesEncrytpedFileAsync(appendAesEncryptedFileAsyncPath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Wait(); FileExtensions.AppendAesEncrytpedFileAsync(appendAesEncryptedFileAsyncPath, Domain, Username, testFileData, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Wait(); var appendAesEncryptedFileDataAsync = FileExtensions.ReadAesEncryptedFileAsync(appendAesEncryptedFileAsyncPath, Domain, Username, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Result; Assert.AreEqual(appendTestFileData, appendAesEncryptedFileDataAsync); // AppendAesEncryptedFileBytesAsync | ReadAesEncryptedFileBytesAsync var testFileDataBytes = Encoding.UTF32.GetBytes(testFileData); var appendAesEncryptedFileBytesAsyncPath = string.Format("{0}{1}", baseFilePath, "AppendAesEncryptedFileBytesAsync.txt"); FileExtensions.CreateAesEncrytpedFileBytesAsync(appendAesEncryptedFileBytesAsyncPath, Domain, Username, testFileDataBytes, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Wait(); FileExtensions.AppendAesEncrytpedFileBytesAsync(appendAesEncryptedFileBytesAsyncPath, Domain, Username, testFileDataBytes, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Wait(); var appendAesEncryptedFileDataBytesAsync = FileExtensions.ReadAesEncryptedFileBytesAsync(appendAesEncryptedFileBytesAsyncPath, Domain, Username, AesPassword, AesSalt, AesPasswordIterations, AesInitialVector, AesKeySize).Result; var appendAesEncryptedFileDataDecodedAsync = Encoding.UTF32.GetString(appendAesEncryptedFileDataBytesAsync); Assert.AreEqual(appendTestFileData, appendAesEncryptedFileDataDecodedAsync); FileExtensions.DeleteDirectories(baseFolderPath, Domain, Username); Assert.IsFalse(Directory.Exists(baseFolderPath)); } }