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 DownloadBatchFilesFromListingResult() { int numberOfFilesToDownload = this.randomProvider.Next(5, 20); List <CloudFile> files = new List <CloudFile>(); List <string> fileNames = new List <string>(); for (int i = 0; i < numberOfFilesToDownload; i++) { string cloudFileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true); files.Add(fileUtil.CreateFile(this.fileShare, cloudFileName, localFilePath)); File.Delete(localFilePath); fileNames.Add(cloudFileName.ToLowerInvariant()); } DirectoryInfo localDir = new DirectoryInfo(Test.Data.Get("TempDir")); CommandAgent.GetFile(this.fileShare); ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("Get-AzureStorageFileContent"); ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Destination", localDir.FullName); CommandAgent.Invoke(); CommandAgent.AssertNoError(); var localFilesInfo = localDir.GetFiles(); foreach (var fileInfo in localFilesInfo) { fileNames.Remove(fileInfo.Name.ToLowerInvariant()); } Test.Assert(fileNames.Count == 0, "All files should be downloaded while missing: {0}", string.Join(",", fileNames)); }
public void CreateDirectoryAndListThroughPSHTest() { string directoryName = CloudFileUtil.GenerateUniqueDirectoryName(); this.mountedShareRoot.CreateSubdirectory(directoryName); CommandAgent.GetFile(this.fileShare); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(directoryName)); }
public void GetFilesFromEmptyFolderTest() { var dir = this.fileShare.GetRootDirectoryReference(); fileUtil.CleanupDirectory(dir); CommandAgent.GetFile(this.fileShare); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(Enumerable.Empty <CloudFile>(), Enumerable.Empty <CloudFileDirectory>()); }
public void GetFilesUsingInvalidFileShareObjectTest() { var invalidFileShareName = CloudFileUtil.GenerateUniqueFileShareName(); fileUtil.DeleteFileShareIfExists(invalidFileShareName); CommandAgent.GetFile(fileUtil.Client.GetShareReference(invalidFileShareName)); var result = CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError( AssertUtil.ShareBeingDeletedFullQualifiedErrorId, AssertUtil.ShareNotFoundFullQualifiedErrorId, AssertUtil.ProtocolErrorFullQualifiedErrorId)); }
public void GetFilesFromDirectoryTest() { var fileNames = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList(); var directoryName = CloudFileUtil.GenerateUniqueDirectoryName(); var dir = fileUtil.EnsureDirectoryExists(this.fileShare, directoryName); fileUtil.CleanupDirectory(dir); var files = fileNames.Select(name => fileUtil.CreateFile(dir, name)).ToList(); CommandAgent.GetFile(dir); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertFileListItems(files, Enumerable.Empty <CloudFileDirectory>()); }
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 CreateFileAndListThroughPSHTest() { string fileName = CloudFileUtil.GenerateUniqueFileName(); string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()); byte[] randomContent = new byte[10240]; this.randomProvider.NextBytes(randomContent); using (var stream = File.Create(Path.Combine(this.mountedShareRoot.FullName, fileName))) { stream.Write(randomContent, 0, randomContent.Length); } CommandAgent.GetFile(this.fileShare); var result = CommandAgent.Invoke(); CommandAgent.AssertNoError(); result.AssertObjectCollection(obj => obj.AssertCloudFile(fileName)); }
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 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 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 GetFilesFromSubDirectoryOfRootTest() { CommandAgent.GetFile(this.fileShare, "../a"); CommandAgent.Invoke(); CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidResourceFullQualifiedErrorId, AssertUtil.AuthenticationFailedFullQualifiedErrorId)); }