Ejemplo n.º 1
0
        public void AssertFileListItems(IEnumerable <CloudFile> files, IEnumerable <CloudFileDirectory> directories)
        {
            var fileList      = new List <string>(files.Select(x => CloudFileUtil.GetFullPath(x).Trim(CloudFileUtil.PathSeparators)));
            var directoryList = new List <string>(directories.Select(x => CloudFileUtil.GetFullPath(x).Trim(CloudFileUtil.PathSeparators)));

            foreach (var psObject in this.result)
            {
                string        fullPath;
                List <string> expectedList;
                if (psObject.ImmediateBaseObject is CloudFile)
                {
                    var fileObject = (CloudFile)psObject.ImmediateBaseObject;
                    fullPath     = CloudFileUtil.GetFullPath(fileObject).Trim(CloudFileUtil.PathSeparators);
                    expectedList = fileList;
                }
                else if (psObject.ImmediateBaseObject is CloudFileDirectory)
                {
                    var directoryObject = (CloudFileDirectory)psObject.ImmediateBaseObject;
                    fullPath     = CloudFileUtil.GetFullPath(directoryObject).Trim(CloudFileUtil.PathSeparators);
                    expectedList = directoryList;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unexpected output object: {0}.", psObject.ImmediateBaseObject));
                }

                Test.Assert(expectedList.Remove(fullPath), "Path {0} was found in the expected list.", fullPath);
            }

            Test.Assert(fileList.Count == 0, "{0} leftover items in file list.", fileList.Count);
            Test.Assert(directoryList.Count == 0, "{0} leftover items in directory list.", directoryList.Count);
        }
Ejemplo n.º 2
0
        public void AssertCloudFileDirectory(object directoryObj, List <string> directoryPathes)
        {
            var directoryObject = ((PSObject)directoryObj).ImmediateBaseObject as CloudFileDirectory;

            Test.Assert(directoryObject != null, "Output object should be an instance of CloudFileDirectory.");
            string fullPath = CloudFileUtil.GetFullPath(directoryObject).Trim(CloudFileUtil.PathSeparators);

            Test.Assert(directoryPathes.Remove(fullPath), "Prefix of the directory object '{0}' should be within the given collection.", fullPath);
        }
Ejemplo n.º 3
0
        public void AssertCloudFileDirectory(object directoryObj, string directoryPath)
        {
            var directoryObject = ((PSObject)directoryObj).ImmediateBaseObject as CloudFileDirectory;

            Test.Assert(directoryObject != null, "Output object should be an instance of CloudFileDirectory.");
            string fullPath = CloudFileUtil.GetFullPath(directoryObject).Trim(CloudFileUtil.PathSeparators);

            Test.Assert(fullPath.Equals(directoryPath.Trim(CloudFileUtil.PathSeparators), StringComparison.OrdinalIgnoreCase), "Prefix of the directory object should match the given parameter. Expected: {0}, Actual: {1}", directoryPath, fullPath);
        }
        public void CreateDirectoryUnderExistingDirectory()
        {
            string dirName    = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory  = fileUtil.EnsureDirectoryExists(this.fileShare, dirName);
            string subDirName = CloudFileUtil.GenerateUniqueDirectoryName();
            string fullPath   = CloudFileUtil.GetFullPath(directory.GetDirectoryReference(subDirName));

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(directory, subDirName),
                fullPath.TrimEnd('/'));
        }
Ejemplo n.º 5
0
        public void UploadToADeletedFolder()
        {
            string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);
            var dir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName());

            dir.Delete();
            CommandAgent.UploadFile(this.fileShare, localFilePath, CloudFileUtil.GetFullPath(dir) + "/");
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ParentNotFoundFullQualifiedErrorId));
        }
Ejemplo n.º 6
0
        public void AssertCloudFile(object fileObj, List <CloudFile> files)
        {
            var fileObject = ((PSObject)fileObj).ImmediateBaseObject as CloudFile;

            Test.Assert(fileObject != null, "Output object should be an instance of CloudFile.");

            string fileObjectFullName = CloudFileUtil.GetFullPath(fileObject);

            CloudFile matchingFile = files.FirstOrDefault(file => CloudFileUtil.GetFullPath(file).Equals(fileObjectFullName, StringComparison.OrdinalIgnoreCase));

            Test.Assert(matchingFile != null, "Output CloudFile object {0} was not found in the expecting list.", fileObjectFullName);
            files.Remove(matchingFile);
        }
Ejemplo n.º 7
0
        public void UploadingToNonExistingDirectory()
        {
            string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);

            string cloudDirectoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteDirectoryIfExists(this.fileShare, cloudDirectoryName);
            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();
            var    file          = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(cloudDirectoryName).GetFileReference(cloudFileName);

            CommandAgent.UploadFile(this.fileShare, localFilePath, CloudFileUtil.GetFullPath(file));
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ParentNotFoundFullQualifiedErrorId));
        }
Ejemplo n.º 8
0
        public void AssertCloudFile(object fileObj, string fileName, string path = null)
        {
            var fileObject = ((PSObject)fileObj).ImmediateBaseObject as CloudFile;

            Test.Assert(fileObject != null, "Output object should be an instance of CloudFile.");

            // FIXME: Walk around a issue in XSCL where the CloudFile.Name property sometimes returns
            // full path of the file.
            string fileObjectName = fileObject.Name.Split(CloudFileUtil.PathSeparators, StringSplitOptions.RemoveEmptyEntries).Last();

            Test.Assert(fileObjectName.Equals(fileName, StringComparison.OrdinalIgnoreCase), "Name of the file object should match the given parameter. Expected: {0}, Actual: {1}", fileName, fileObjectName);
            if (path != null)
            {
                string fullPath = CloudFileUtil.GetFullPath(fileObject.Parent).Trim(CloudFileUtil.PathSeparators);
                Test.Assert(fileObject.Parent != null, "Since file is not on root folder, the parent directory should not be null.");
                Test.Assert(fullPath.Equals(path.Trim(CloudFileUtil.PathSeparators), StringComparison.OrdinalIgnoreCase), "Prefix of the directory object should match the path of the file. Expected: {0}, Actual: {1}", path, fullPath);
            }
        }
Ejemplo n.º 9
0
        private void UploadAndDownloadFileInternal(CloudFile sourceFile, string md5Checksum, Action <string> getContentAction, Func <string> getDestination = null, bool assertNoError = true)
        {
            var destination = getDestination == null?Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName()) : getDestination();

            try
            {
                Test.Info("Download source file {0} to destination {1}.", sourceFile.Uri.OriginalString, destination);
                getContentAction(destination);
                var result = CommandAgent.Invoke();

                if (assertNoError)
                {
                    CommandAgent.AssertNoError();
                    if (lang == Language.NodeJS)
                    {
                        result.AssertObjectCollection(obj => result.AssertCloudFile(obj, CloudFileUtil.GetFullPath(sourceFile)));
                    }
                    else
                    {
                        result.AssertNoResult();
                    }

                    if (File.Exists(destination))
                    {
                        string destinationMD5 = FileUtil.GetFileContentMD5(destination);
                        Test.Assert(
                            destinationMD5.Equals(md5Checksum, StringComparison.Ordinal),
                            "MD5 checksum of the downloaded file mismatches. Expected: {0}, Actural: {1}.",
                            md5Checksum,
                            destinationMD5);
                    }
                }
            }
            finally
            {
                if (File.Exists(destination))
                {
                    FileUtil.RemoveFile(destination);
                }
            }
        }