public void GetFileShareUsageTest() { string fileShareName = CloudFileUtil.GenerateUniqueFileShareName(); string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); var fileShare = fileUtil.EnsureFileShareExists(fileShareName); try { CommandAgent.GetFileShareByName(fileShareName); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, fileShareName), 1); fileUtil.CreateFile(fileShare.GetRootDirectoryReference(), cloudFileName); CommandAgent.Clear(); CommandAgent.GetFileShareByName(fileShareName); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, fileShareName, 1), 1); } finally { fileUtil.DeleteFileShareIfExists(fileShareName); } }
public void DownloadFileUsingRelativePathAfterChangedDefaultLocation() { string currentPath = CommandAgent.GetCurrentLocation(); try { string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true); var sourceFile = fileUtil.CreateFile(this.fileShare, cloudFileName, localFilePath); CommandAgent.ChangeLocation(Test.Data.Get("TempDir")); UploadAndDownloadFileInternal( sourceFile, FileUtil.GetFileContentMD5(localFilePath), destination => CommandAgent.DownloadFile(this.fileShare, cloudFileName, ".", true)); var result = CommandAgent.Invoke(); result.AssertNoResult(); Test.Assert(new FileInfo(Path.Combine(Test.Data.Get("TempDir"), cloudFileName)).Exists, "File should exist after downloaded."); } finally { CommandAgent.Clear(); CommandAgent.ChangeLocation(currentPath); } }
public void GetDirsToListDir() { fileUtil.CleanupDirectory(this.fileShare.GetRootDirectoryReference()); var dirNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); fileUtil.CleanupDirectory(this.fileShare.GetRootDirectoryReference()); var dirs = dirNames.Select(name => fileUtil.EnsureDirectoryExists(this.fileShare, name)).ToList(); var fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); var files = fileNames.Select(name => fileUtil.CreateFile(dirs[0], name)).ToList(); CommandAgent.GetFile(this.fileShare, dirNames[0]); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFile"); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, Enumerable.Empty <CloudFileDirectory>()); foreach (var dir in dirs) { fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); files.AddRange(fileNames.Select(name => fileUtil.CreateFile(dir, name)).ToList()); } CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFile"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, Enumerable.Empty <CloudFileDirectory>()); fileUtil.CleanupDirectory(this.fileShare.GetRootDirectoryReference()); }
public void CreateDirectoryWithPathStartsWithSlash() { string dir1 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal("/" + dir1); CommandAgent.Clear(); string dir2 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal("\\" + dir2); CommandAgent.Clear(); }
public void CreateDirectoryWith255Unicodes() { if (OSType.Windows != AgentFactory.GetOSType()) { return; } foreach (var dirName in FileNamingGenerator.GenerateValidateUnicodeName(FileNamingGenerator.MaxFileNameLength)) { this.CreateDirectoryInternal(dirName, traceCommand: false); CommandAgent.Clear(); } }
public void GetFilesFromRelativePathWhereIntermediatePathMightNotExistTest() { var fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 10)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); var dir = fileUtil.EnsureFolderStructure(this.fileShare, "a/b/c"); fileUtil.CleanupDirectory(dir); CommandAgent.Clear(); IExecutionResult result; if (lang == Language.NodeJS) { CommandAgent.GetFile(this.fileShare, "a/c/./../b/./e/.."); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(Enumerable.Empty <CloudFile>(), new[] { dir }); } else { CommandAgent.GetFile(this.fileShare, "a/c/./../b/./c/e/.."); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory("a/b/c")); } CommandAgent.Clear(); var files = fileNames.Select(name => fileUtil.CreateFile(dir, name)).ToList(); if (lang == Language.NodeJS) { CommandAgent.GetFile(this.fileShare, "a/c/./../b/./c/e/.."); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, Enumerable.Empty <CloudFileDirectory>()); } else { CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare, string.Format("a/c/./../b/./c/e/../{0}", fileNames[0])); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileNames[0], "a/b/c")); } }
public void GetFilesToGetFileContent() { var fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); fileUtil.CleanupDirectory(this.fileShare.GetRootDirectoryReference()); string sourceFolder = Path.Combine(Test.Data.Get("TempDir"), Utility.GenNameString("")); FileUtil.CreateNewFolder(sourceFolder); var filePaths = fileNames.Select(name => Path.Combine(sourceFolder, name)).ToList(); foreach (var filePath in filePaths) { FileUtil.GenerateSmallFile(filePath, Utility.GetRandomTestCount(5, 10), true); } var files = fileNames.Select(name => fileUtil.CreateFile(this.fileShare, name, Path.Combine(sourceFolder, name))).ToList(); string destFolder = Path.Combine(Test.Data.Get("TempDir"), Utility.GenNameString("")); FileUtil.CreateNewFolder(destFolder); CommandAgent.GetFile(this.fileShare, fileNames[0]); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFileContent"); ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Destination", destFolder); CommandAgent.Invoke(); CommandAgent.AssertNoError(); string destMD5 = FileUtil.GetFileContentMD5(Path.Combine(destFolder, fileNames[0])); string srcMD5 = FileUtil.GetFileContentMD5(Path.Combine(sourceFolder, fileNames[0])); Test.Assert(destMD5.Equals(srcMD5), "Destination content should be the same with the source"); FileUtil.CleanDirectory(destFolder); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFileContent"); ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Destination", destFolder); CommandAgent.Invoke(); CommandAgent.AssertNoError(); foreach (var fileName in fileNames) { destMD5 = FileUtil.GetFileContentMD5(Path.Combine(destFolder, fileNames[0])); srcMD5 = FileUtil.GetFileContentMD5(Path.Combine(sourceFolder, fileNames[0])); Test.Assert(destMD5.Equals(srcMD5), "Destination content should be the same with the source"); } }
public void GetFilesFromSubDirectoryUsingRelativePathFromRootTest() { var dir = fileUtil.EnsureFolderStructure(this.fileShare, "a/b/c"); fileUtil.CleanupDirectory(dir); CommandAgent.Clear(); IExecutionResult result; if (lang == Language.NodeJS) { CommandAgent.GetFile(this.fileShare, "a/b/.././b/../b/"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(Enumerable.Empty <CloudFile>(), new[] { dir }); } else { CommandAgent.GetFile(this.fileShare, "a/b/.././b/../b/c"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory("a/b/c")); } CommandAgent.Clear(); var file = fileUtil.CreateFile(dir, "d"); if (lang == Language.NodeJS) { CommandAgent.GetFile(this.fileShare, "a/b/.././b/../b/c"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(new[] { file }, Enumerable.Empty <CloudFileDirectory>()); } else { CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare, "a/b/.././b/../b/c/d"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile("d", "a/b/c")); } }
public void CreateDirectoryWithRelativePath() { var baseDir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName()); string dir1 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal( () => CommandAgent.NewDirectory(baseDir, "../" + dir1), dir1); CommandAgent.Clear(); string dir2 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal( () => CommandAgent.NewDirectory(baseDir, "./c/../../" + dir2), dir2); CommandAgent.Clear(); }
public void CreateDirectoryWithRelativePathContainsDoubleSlash() { var baseDir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName()); string dir1 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal( () => CommandAgent.NewDirectory(baseDir, "..//" + dir1), dir1); CommandAgent.Clear(); baseDir.GetDirectoryReference("a").CreateIfNotExists(); string dir2 = CloudFileUtil.GenerateUniqueDirectoryName(); this.CreateDirectoryInternal( () => CommandAgent.NewDirectory(baseDir, @"//a\\" + dir2), string.Format("{0}/a/{1}", baseDir.Name, dir2)); CommandAgent.Clear(); }
public void GetFilesFromSubDirectoryUsingRelativePathTest() { var dir = fileUtil.EnsureFolderStructure(this.fileShare, "a/b/c"); fileUtil.CleanupDirectory(dir); var file = fileUtil.CreateFile(dir, "d"); CommandAgent.Clear(); CommandAgent.GetFile(dir.Parent, "../b/./c"); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory("a/b/c")); CommandAgent.Clear(); CommandAgent.GetFile(dir.Parent, "../b/./c/d"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile("d", "a/b/c")); }
public void GetFilesFromRootTest() { var fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); var dirNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); var dir = this.fileShare.GetRootDirectoryReference(); fileUtil.CleanupDirectory(dir); var files = fileNames.Select(name => fileUtil.CreateFile(dir, name)).ToList(); var dirs = dirNames.Select(name => fileUtil.EnsureDirectoryExists(dir, name)).ToList(); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, dirs); // xPlat doesn't have the "file show" command. It only has the "file list" command which is only target for the directory if (lang != Language.NodeJS) { CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare, fileNames[0]); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileNames[0])); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.Name, fileNames[0]); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileNames[0])); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.GetRootDirectoryReference(), fileNames[0]); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileNames[0])); } }
public void UploadAndDownload0SizeFile() { string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); string localFilePath2 = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); FileUtil.GenerateSmallFile(localFilePath, 0, true); CommandAgent.UploadFile(this.fileShare, localFilePath, cloudFileName, true); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); Test.Assert(fileShare.GetRootDirectoryReference().GetFileReference(cloudFileName).Exists(), "File should exist after uploaded."); CommandAgent.Clear(); CommandAgent.DownloadFile(this.fileShare.GetRootDirectoryReference(), cloudFileName, localFilePath2, true); result = CommandAgent.Invoke(); if (UtilBase.AgentOSType == OSType.Windows) { Test.Assert(File.Exists(localFilePath2), "File should exist after uploaded."); } Test.Assert(FileUtil.GetFileContentMD5(localFilePath) == FileUtil.GetFileContentMD5(localFilePath2), "The download file MD5 {0} should match Uploaded File MD5 {1}.", FileUtil.GetFileContentMD5(localFilePath2), FileUtil.GetFileContentMD5(localFilePath)); }
public void GetNonExistFile() { fileUtil.CleanupDirectory(this.fileShare.GetRootDirectoryReference()); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare, "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.Name, "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.GetRootDirectoryReference(), "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); }
public void CreateShareWhichHasBeenDeletedAndGCed() { const int CreateShareInterval = 10000; const int CreateShareRetryLimit = 10; string fileShareName = CloudFileUtil.GenerateUniqueFileShareName(); var fileShare = fileUtil.EnsureFileShareExists(fileShareName); // Delete the share first. fileShare.Delete(); Stopwatch watch = Stopwatch.StartNew(); // Try to create the share try { for (int i = 0; i < CreateShareRetryLimit; i++) { Thread.Sleep(CreateShareInterval); Test.Info("Try to create a share which has just been deleted. RetryCount = {0}", i); CommandAgent.NewFileShare(fileShareName); var result = CommandAgent.Invoke(); if (!CommandAgent.HadErrors) { Test.Info("Successfully created the file share at round {0}.", i); return; } CommandAgent.AssertErrors(errorRecord => errorRecord.AssertError(AssertUtil.ShareBeingDeletedFullQualifiedErrorId)); CommandAgent.Clear(); } Test.Error("Failed to create the file share within the given retry count {0}. Total time passed is {1}", CreateShareRetryLimit, watch.Elapsed); } finally { fileUtil.DeleteFileShareIfExists(fileShareName); } }
public void UploadLocalFileUsingRelativePathAfterChangedDefaultLocation() { string currentPath = CommandAgent.GetCurrentLocation(); try { string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), cloudFileName); FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true); CommandAgent.ChangeLocation(Test.Data.Get("TempDir")); CommandAgent.UploadFile(this.fileShare, cloudFileName, cloudFileName, true); var result = CommandAgent.Invoke(); result.AssertNoResult(); var file = this.fileShare.GetRootDirectoryReference().GetFileReference(cloudFileName); Test.Assert(file.Exists(), "File shold exist after uploaded."); } finally { CommandAgent.Clear(); CommandAgent.ChangeLocation(currentPath); } }
public void GetFileInNonExistShare() { CommandAgent.Clear(); CommandAgent.GetFile("nonexistshare", "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(fileUtil.GetShareReference("nonexistshare"), "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.GetRootDirectoryReference().GetDirectoryReference("NonExistDir"), "NonExistFile"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile("nonexistshare"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ShareNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(fileUtil.GetShareReference("nonexistshare")); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ShareNotFoundFullQualifiedErrorId)); CommandAgent.Clear(); CommandAgent.GetFile(this.fileShare.GetRootDirectoryReference().GetDirectoryReference("NonExistDir")); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ResourceNotFoundFullQualifiedErrorId)); }
public void GetFilePipeliningWithGetShareTest() { var directoryName = CloudFileUtil.GenerateUniqueDirectoryName(); var directory = fileUtil.EnsureDirectoryExists(this.fileShare, directoryName); fileUtil.CleanupDirectory(directory); CommandAgent.GetFileShareByName(this.fileShare.Name); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFile"); ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", directoryName); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(directoryName)); CommandAgent.Clear(); var fileName = CloudFileUtil.GenerateUniqueFileName(); var file = fileUtil.CreateFile(this.fileShare.GetRootDirectoryReference(), fileName); CommandAgent.GetFileShareByName(this.fileShare.Name); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFile"); ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", fileName); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileName)); CommandAgent.Clear(); List <CloudFileDirectory> dirs = new List <CloudFileDirectory>(); List <CloudFile> files = new List <CloudFile>(); dirs.Add(directory); files.Add(file); CommandAgent.GetFileShareByName(this.fileShare.Name); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFile"); result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, dirs); }
public void DownloadFileCheckMD5() { string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true); string previousMD5 = FileUtil.GetFileContentMD5(localFilePath); var sourceFile = fileUtil.CreateFile(this.fileShare, cloudFileName, localFilePath); if (sourceFile.Properties.ContentMD5 != previousMD5) { sourceFile.Properties.ContentMD5 = previousMD5; sourceFile.SetProperties(); } var destination = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); // Download file and check its MD5 CommandAgent.DownloadFile(this.fileShare.Name, cloudFileName, destination, true, CheckMd5: true); var result = CommandAgent.Invoke(); result.AssertNoResult(); string destinationMD5 = FileUtil.GetFileContentMD5(destination); Test.Assert( destinationMD5.Equals(previousMD5, StringComparison.Ordinal), "MD5 checksum of the downloaded file mismatches. Expected: {0}, Actural: {1}.", previousMD5, destinationMD5); sourceFile.Properties.ContentMD5 = ""; sourceFile.SetProperties(); // File's ContentMD5 property is empty, download file and check its MD5 CommandAgent.Clear(); CommandAgent.DownloadFile(this.fileShare.Name, cloudFileName, destination, true, CheckMd5: true); result = CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidOperationExceptionFullQualifiedErrorId)); destinationMD5 = FileUtil.GetFileContentMD5(destination); Test.Assert( destinationMD5.Equals(previousMD5, StringComparison.Ordinal), "MD5 checksum of the downloaded file mismatches. Expected: {0}, Actural: {1}.", previousMD5, destinationMD5); // File's ContentMD5 property is empty, download file without check MD5. CommandAgent.Clear(); CommandAgent.DownloadFile(this.fileShare.Name, cloudFileName, destination, true, CheckMd5: false); result = CommandAgent.Invoke(); result.AssertNoResult(); destinationMD5 = FileUtil.GetFileContentMD5(destination); Test.Assert( destinationMD5.Equals(previousMD5, StringComparison.Ordinal), "MD5 checksum of the downloaded file mismatches. Expected: {0}, Actural: {1}.", previousMD5, destinationMD5); }