public void FilePattern_CloudBlob_NoPattern_1()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder1", "testfile2"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder1", "4testfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "subfolder4", "test5"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "testfile234"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "TESTFILE345"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "testYfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "f_arbitrary.exe"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "测试x文件"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "testfile1"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "TestFile2"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "测试文件2"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder2", "folder_file"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder2", "测试文件三"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder2", "测试四文件"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "TeSTfIle"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile1"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile2"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testXfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testXXfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "测试文件"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "..a123"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(true, expectedResult);
        }
Beispiel #2
0
        public void DummySingleBlobDownload()
        {
            // Single dummy blob should behave the same as empty blob.
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add(Constants.DirectoryBlobMetadataKey, "true");

            Test.Info("Metadata is =====================");
            foreach (var keyValue in metadata)
            {
                Test.Info("name:{0}  value:{1}", keyValue.Key, keyValue.Value);
            }

            DMLibDataInfo sourceDataInfo  = new DMLibDataInfo(string.Empty);
            FileNode      dummyFolderNode = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = 0L,
                Metadata   = metadata
            };

            sourceDataInfo.RootNode.AddFileNode(dummyFolderNode);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = false;

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");

            dummyFolderNode.Metadata = new Dictionary <string, string>();
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
Beispiel #3
0
        public void TransferInAllDirections()
        {
            List <TransferItem> allItems = AllTransferDirectionTest.GetTransformItemsForAllDirections(resume: false);

            // Execution
            var result = this.RunTransferItems(allItems, new TestExecutionOptions <DMLibDataInfo>());

            // Verify all files are transfered successfully
            Test.Assert(result.Exceptions.Count == 0, "Verify no exception occurs.");
            foreach (DMLibDataType destDataType in DataTypes)
            {
                if (DMLibDataType.Stream == destDataType || DMLibDataType.URI == destDataType)
                {
                    continue;
                }

                DataAdaptor <DMLibDataInfo> destAdaptor = GetDestAdaptor(destDataType);
                DMLibDataInfo destDataInfo = destAdaptor.GetTransferDataInfo(string.Empty);

                foreach (FileNode destFileNode in destDataInfo.EnumerateFileNodes())
                {
                    FileNode sourceFileNode = expectedFileNodes[destFileNode.Name];

                    if (IsCloudService(destDataType))
                    {
                        IDictionary <string, string> metadata = new Dictionary <string, string>();
                        metadata.Add("aa", "bb");
                        sourceFileNode.ContentLanguage = "EN";
                        sourceFileNode.Metadata        = metadata;
                    }
                    Test.Assert(DMLibDataHelper.Equals(sourceFileNode, destFileNode), "Verify transfer result.");
                }
            }
        }
        public void FilePattern_Local_WildChar_1()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder1", "testfile2"));
            if (CrossPlatformHelpers.IsWindows)
            {
                nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "TESTFILE345"));
            }

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "testfile234"));

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "testfile1"));

            if (CrossPlatformHelpers.IsWindows)
            {
                nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "TestFile2"));
            }

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile1"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testfile2"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(true, expectedResult, "testfile*");
        }
Beispiel #5
0
        public static void AddMultipleFilesTotalSize(DirNode dirNode, string filePrefix, int fileNumber, int totalSizeInKB, DateTime?lmt = null)
        {
            int fileSizeInKB = totalSizeInKB / fileNumber;

            fileSizeInKB = fileSizeInKB == 0 ? 1 : fileSizeInKB;
            DMLibDataHelper.AddMultipleFiles(dirNode, filePrefix, fileNumber, fileSizeInKB, lmt: lmt);
        }
Beispiel #6
0
        public static void AddTreeTotalSize(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int totalSizeInKB, DateTime?lmt = null)
        {
            int fileNumber;

            if (width <= 1)
            {
                fileNumber = (depth + 1) * width;
            }
            else
            {
                int widthPowDepth = width;
                for (int i = 0; i < depth; ++i)
                {
                    widthPowDepth *= width;
                }

                fileNumber = width * (widthPowDepth - 1) / (width - 1);
            }

            int fileSizeInKB = totalSizeInKB / fileNumber;

            fileSizeInKB = fileSizeInKB == 0 ? 1 : fileSizeInKB;

            DMLibDataHelper.AddTree(dirNode, dirPrefix, filePrefix, width, depth, fileSizeInKB, lmt: lmt);
        }
        public DMLibDataInfo GenerateSourceDataInfo(FileNumOption fileNumOption, int totalSizeInKB, string folderName = "")
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(folderName);

            if (fileNumOption == FileNumOption.FileTree)
            {
                DMLibDataHelper.AddTreeTotalSize(
                    sourceDataInfo.RootNode,
                    DMLibTestBase.DirName,
                    DMLibTestBase.FileName,
                    DMLibTestConstants.RecursiveFolderWidth,
                    DMLibTestConstants.RecursiveFolderDepth,
                    totalSizeInKB);
            }
            else if (fileNumOption == FileNumOption.FlatFolder)
            {
                DMLibDataHelper.AddMultipleFilesTotalSize(
                    sourceDataInfo.RootNode,
                    DMLibTestBase.FileName,
                    DMLibTestConstants.FlatFileCount,
                    totalSizeInKB);
            }
            else if (fileNumOption == FileNumOption.OneFile)
            {
                DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, DMLibTestBase.FileName, totalSizeInKB);
            }

            return(sourceDataInfo);
        }
        private void GenerateDir(DirNode dirNode, string parentPath)
        {
            string dirPath = Path.Combine(parentPath, dirNode.Name);

            if (!string.IsNullOrEmpty(dirNode.Content))
            {
                CreateSymlink(dirPath, dirNode.Content);

                Test.Info("Building symlinked dir info of {0}", dirPath);
                dirNode.BuildSymlinkedDirNode();
                return;
            }

            DMLibDataHelper.CreateLocalDirIfNotExists(dirPath);

            foreach (var file in dirNode.FileNodes)
            {
                GenerateFile(file, dirPath);
            }

            foreach (var subDir in dirNode.NormalDirNodes)
            {
                GenerateDir(subDir, dirPath);
            }

            foreach (var subDir in dirNode.SymlinkedDirNodes)
            {
                CreateSymlink(Path.Combine(dirPath, subDir.Name), subDir.Content);

                Test.Info("Building symlinked dir info of {0}", Path.Combine(dirPath, subDir.Name));
                subDir.BuildSymlinkedDirNode();
            }
        }
        public void TransferBigSizeObject()
        {
            int originParallel = TransferManager.Configurations.ParallelOperations;

            TransferManager.Configurations.ParallelOperations = 4;
            try
            {
                DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
                DMLibDataHelper.AddMultipleFilesBigSize(sourceDataInfo.RootNode, DMLibTestBase.FileName);

                var option = new TestExecutionOptions <DMLibDataInfo>();
                var result = this.ExecuteTestCase(sourceDataInfo, option);

                Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
                Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");

                if (!(DMLibTestContext.DestType == DMLibDataType.Local || DMLibTestContext.DestType == DMLibDataType.Stream))
                {
                    this.ValidateDestinationMD5ByDownloading(result.DataInfo, option);
                }
            }
            finally
            {
                TransferManager.Configurations.ParallelOperations = originParallel;
            }
        }
Beispiel #10
0
        public static void AddTree(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int fileSizeInKB, FileAttributes?fa = null, DateTime?lmt = null)
        {
            for (int i = 0; i < width; ++i)
            {
                string   fileName = i == 0 ? filePrefix : filePrefix + "_" + i;
                FileNode fileNode = new FileNode(fileName)
                {
                    SizeInByte       = 1024L * fileSizeInKB,
                    FileAttr         = fa,
                    LastModifiedTime = lmt,
                };

                dirNode.AddFileNode(fileNode);
            }

            if (depth > 0)
            {
                for (int i = 0; i < width; ++i)
                {
                    string  dirName    = i == 0 ? dirPrefix : dirPrefix + "_" + i;
                    DirNode subDirNode = dirNode.GetDirNode(dirName);
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(dirName);
                        dirNode.AddDirNode(subDirNode);
                    }

                    DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt);
                }
            }
        }
        public void TransferDirectoryDifferentSizeObject()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo("rootfolder");

            DMLibDataHelper.AddMultipleFilesNormalSize(sourceDataInfo.RootNode, BVT.UnicodeFileName);

            var options = new TestExecutionOptions <DMLibDataInfo>()
            {
                IsDirectoryTransfer  = true,
                TransferItemModifier = (notUsed, item) =>
                {
                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = true;
                    item.Options = transferOptions;
                },
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // For sync copy, recalculate md5 of destination by downloading the file to local.
            if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
            {
                DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
            }

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
Beispiel #12
0
 public static void AddMultipleFiles(
     DirNode dirNode,
     string filePrefix,
     int fileNumber,
     int fileSizeInKB,
     FileAttributes?fa         = null,
     DateTime?lmt              = null,
     string cacheControl       = null,
     string contentDisposition = null,
     string contentEncoding    = null,
     string contentLanguage    = null,
     string contentType        = null,
     string md5 = null,
     IDictionary <string, string> metadata = null)
 {
     DMLibDataHelper.AddTree(
         dirNode,
         string.Empty,
         filePrefix,
         fileNumber,
         0,
         fileSizeInKB,
         fa,
         lmt,
         cacheControl,
         contentDisposition,
         contentEncoding,
         contentLanguage,
         contentType,
         md5,
         metadata);
 }
Beispiel #13
0
        public void TestMetadata()
        {
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add(FileOp.NextCIdentifierString(random), FileOp.NextNormalString(random));
            metadata.Add(FileOp.NextCIdentifierString(random), FileOp.NextNormalString(random));

            Test.Info("Metadata is =====================");
            foreach (var keyValue in metadata)
            {
                Test.Info("name:{0}  value:{1}", keyValue.Key, keyValue.Value);
            }

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            FileNode      fileNode       = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = DMLibTestBase.FileSizeInKB * 1024L,
                Metadata   = metadata
            };

            sourceDataInfo.RootNode.AddFileNode(fileNode);

            var result = this.ExecuteTestCase(sourceDataInfo, new TestExecutionOptions <DMLibDataInfo>());

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
Beispiel #14
0
        private void GenerateDir(DirNode dirNode, CloudFileDirectory cloudFileDir, string parentPath)
        {
            string dirPath = Path.Combine(parentPath, dirNode.Name);

            DMLibDataHelper.CreateLocalDirIfNotExists(dirPath);
            cloudFileDir.CreateIfNotExists(HelperConst.DefaultFileOptions);

            if (null != cloudFileDir.Parent)
            {
                if (null != dirNode.SMBAttributes)
                {
                    cloudFileDir.Properties.NtfsAttributes = dirNode.SMBAttributes;
                }

                if (dirNode.CreationTime.HasValue)
                {
                    cloudFileDir.Properties.CreationTime = dirNode.CreationTime;
                }
                if (dirNode.LastWriteTime.HasValue)
                {
                    cloudFileDir.Properties.LastWriteTime = dirNode.LastWriteTime;
                }
                if (null != dirNode.PortableSDDL)
                {
                    cloudFileDir.FilePermission = dirNode.PortableSDDL;
                }
                cloudFileDir.SetProperties(HelperConst.DefaultFileOptions);

                cloudFileDir.FetchAttributes(null, HelperConst.DefaultFileOptions);

                dirNode.CreationTime  = cloudFileDir.Properties.CreationTime;
                dirNode.LastWriteTime = cloudFileDir.Properties.LastWriteTime;

                if ((null != dirNode.Metadata) &&
                    (dirNode.Metadata.Count > 0))
                {
                    cloudFileDir.Metadata.Clear();

                    foreach (var keyValuePair in dirNode.Metadata)
                    {
                        cloudFileDir.Metadata.Add(keyValuePair);
                    }

                    cloudFileDir.SetMetadata(null, HelperConst.DefaultFileOptions);
                }
            }

            foreach (var subDir in dirNode.DirNodes)
            {
                CloudFileDirectory subCloudFileDir = cloudFileDir.GetDirectoryReference(subDir.Name);
                this.GenerateDir(subDir, subCloudFileDir, dirPath);
            }

            foreach (var file in dirNode.FileNodes)
            {
                CloudFile cloudFile = cloudFileDir.GetFileReference(file.Name);
                this.GenerateFile(file, cloudFile, dirPath);
            }
        }
        private void GenerateFile(FileNode fileNode, CloudBlob cloudBlob, List <FileNode> snapshotList)
        {
            this.CheckFileNode(fileNode);

            if ((StorageBlob.BlobType.PageBlob == cloudBlob.BlobType) && (fileNode.SizeInByte % 512 != 0))
            {
                throw new InvalidOperationException(string.Format("Can only generate page blob which size is multiple of 512bytes. Expected size is {0}", fileNode.SizeInByte));
            }

            string tempFileName  = Guid.NewGuid().ToString();
            string localFilePath = Path.Combine(this.TempFolder, tempFileName);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            BlobRequestOptions storeMD5Options = new BlobRequestOptions()
            {
                RetryPolicy         = new LinearRetry(TimeSpan.FromSeconds(90), 3),
                StoreBlobContentMD5 = true,
            };

            cloudBlob.UploadFromFile(localFilePath, null, storeMD5Options);

            if (null != fileNode.MD5 ||
                null != fileNode.ContentType ||
                null != fileNode.CacheControl ||
                null != fileNode.ContentDisposition ||
                null != fileNode.ContentEncoding ||
                null != fileNode.ContentLanguage)
            {
                cloudBlob.Properties.ContentMD5         = fileNode.MD5;
                cloudBlob.Properties.ContentType        = fileNode.ContentType;
                cloudBlob.Properties.CacheControl       = fileNode.CacheControl;
                cloudBlob.Properties.ContentDisposition = fileNode.ContentDisposition;
                cloudBlob.Properties.ContentEncoding    = fileNode.ContentEncoding;
                cloudBlob.Properties.ContentLanguage    = fileNode.ContentLanguage;
                cloudBlob.SetProperties(options: HelperConst.DefaultBlobOptions);
            }

            if (null != fileNode.Metadata && fileNode.Metadata.Count > 0)
            {
                cloudBlob.Metadata.Clear();
                foreach (var metaData in fileNode.Metadata)
                {
                    cloudBlob.Metadata.Add(metaData);
                }

                cloudBlob.SetMetadata(options: HelperConst.DefaultBlobOptions);
            }

            cloudBlob.FetchAttributes(options: HelperConst.DefaultBlobOptions);
            this.BuildFileNode(cloudBlob, fileNode);

            for (int i = 0; i < fileNode.SnapshotsCount; ++i)
            {
                CloudBlob snapshot = cloudBlob.Snapshot();
                snapshotList.Add(this.BuildSnapshotFileNode(snapshot, fileNode.Name));
            }
        }
        public void FilePattern_CloudBlob_NoPattern_2()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult);
        }
        private void GenerateFile(FileNode fileNode, CloudFile cloudFile, string parentPath)
        {
            this.CheckFileNode(fileNode);

            string tempFileName  = Guid.NewGuid().ToString();
            string localFilePath = Path.Combine(parentPath, tempFileName);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            FileRequestOptions storeMD5Options = new FileRequestOptions()
            {
                RetryPolicy          = DMLibTestConstants.DefaultRetryPolicy,
                StoreFileContentMD5  = true,
                MaximumExecutionTime = DMLibTestConstants.DefaultExecutionTimeOut
            };

            cloudFile.UploadFromFile(localFilePath, options: storeMD5Options);

            if (null != fileNode.MD5 ||
                null != fileNode.ContentType ||
                null != fileNode.CacheControl ||
                null != fileNode.ContentDisposition ||
                null != fileNode.ContentEncoding ||
                null != fileNode.ContentLanguage)
            {
                // set user defined MD5 to cloud file
                cloudFile.Properties.ContentMD5         = fileNode.MD5;
                cloudFile.Properties.ContentType        = fileNode.ContentType;
                cloudFile.Properties.CacheControl       = fileNode.CacheControl;
                cloudFile.Properties.ContentDisposition = fileNode.ContentDisposition;
                cloudFile.Properties.ContentEncoding    = fileNode.ContentEncoding;
                cloudFile.Properties.ContentLanguage    = fileNode.ContentLanguage;

                cloudFile.SetProperties(options: HelperConst.DefaultFileOptions);
            }

            if (null != fileNode.SMBAttributes)
            {
                cloudFile.Properties.NtfsAttributes = fileNode.SMBAttributes;
                cloudFile.Properties.CreationTime   = fileNode.CreationTime;
                cloudFile.Properties.LastWriteTime  = fileNode.LastWriteTime;
                cloudFile.SetProperties(options: HelperConst.DefaultFileOptions);
            }

            if (null != fileNode.Metadata && fileNode.Metadata.Count > 0)
            {
                cloudFile.Metadata.Clear();
                foreach (var metaData in fileNode.Metadata)
                {
                    cloudFile.Metadata.Add(metaData);
                }

                cloudFile.SetMetadata(options: HelperConst.DefaultFileOptions);
            }

            this.BuildFileNode(cloudFile, fileNode);
        }
        public void TransferBigSizeObject()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddMultipleFilesBigSize(sourceDataInfo.RootNode, DMLibTestBase.FileName);

            var result = this.ExecuteTestCase(sourceDataInfo, new TestExecutionOptions<DMLibDataInfo>());

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
        public void FilePattern_Local_FilePath_1()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder1", "4testfile"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(true, expectedResult, "folder1\\subfolder1\\4testfile");
        }
        public void FilePattern_CloudBlob_Prefix_4()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "TestFile2"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(true, expectedResult, "folder1/TestFile");
        }
        public void FilePattern_CloudFile_FilePath_2()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "TestFile2"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult, FormalizeSearchPattern("folder1\\TestFile2"));
        }
        public void FilePattern_CloudFile_Unicode_2()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder2", "测试四文件"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult, "folder2/测试四文件");
        }
        public void FilePattern_Local_DoubleDotValid_3()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "..a123"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult, "..*");
        }
        public void FilePattern_Local_FilePath_3()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "f_arbitrary.exe"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult, FormalizeSearchPattern("folder1\\subfolder2\\f_arbitrary.exe"));
        }
        public void FilePattern_Local_WildChar_4()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "testXfile"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(false, expectedResult, "test?file");
        }
Beispiel #26
0
        public void DummyDirectoryBlobDownload()
        {
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add(Constants.DirectoryBlobMetadataKey, "true");

            Test.Info("Metadata is =====================");
            foreach (var keyValue in metadata)
            {
                Test.Info("name:{0}  value:{1}", keyValue.Key, keyValue.Value);
            }

            DMLibDataInfo sourceDataInfo  = new DMLibDataInfo(string.Empty);
            FileNode      dummyFolderNode = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = 0L,
                Metadata   = metadata
            };

            DirNode  dirNode    = new DirNode(DMLibTestBase.FileName);
            FileNode actualFile = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = DMLibTestBase.FileSizeInKB * 1024L,
            };

            dirNode.AddFileNode(actualFile);

            sourceDataInfo.RootNode.AddFileNode(dummyFolderNode);
            sourceDataInfo.RootNode.AddDirNode(dirNode);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.DestTransferDataInfo    = destDataInfo;
            options.DisableDestinationFetch = true;
            options.IsDirectoryTransfer     = true;
            options.TransferItemModifier    = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options      = transferOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");

            DataAdaptor <DMLibDataInfo> destAdaptor = GetDestAdaptor(DMLibDataType.Local);

            destDataInfo = destAdaptor.GetTransferDataInfo(destDataInfo.RootPath);
            sourceDataInfo.RootNode.DeleteFileNode(DMLibTestBase.FileName);

            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, destDataInfo), "Verify transfer result.");
        }
        private void GenerateFile(FileNode fileNode, string parentPath)
        {
            this.CheckFileNode(fileNode);

            string localFilePath = Path.Combine(parentPath, fileNode.Name);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            FileInfo fileInfo = new FileInfo(localFilePath);

            this.BuildFileNode(fileInfo, fileNode);
        }
Beispiel #28
0
        public static void AddTree(
            DirNode dirNode,
            string dirPrefix,
            string filePrefix,
            int width,
            int depth,
            int fileSizeInKB,
            FileAttributes?fa         = null,
            DateTime?lmt              = null,
            string cacheControl       = null,
            string contentDisposition = null,
            string contentEncoding    = null,
            string contentLanguage    = null,
            string contentType        = null,
            string md5 = null,
            IDictionary <string, string> metadata = null)
        {
            for (int i = 0; i < width; ++i)
            {
                string   fileName = i == 0 ? filePrefix : filePrefix + "_" + i;
                FileNode fileNode = new FileNode(fileName)
                {
                    SizeInByte         = 1024L * fileSizeInKB,
                    FileAttr           = fa,
                    LastModifiedTime   = lmt,
                    CacheControl       = cacheControl,
                    ContentDisposition = contentDisposition,
                    ContentEncoding    = contentEncoding,
                    ContentLanguage    = contentLanguage,
                    ContentType        = contentType,
                    MD5      = md5,
                    Metadata = metadata
                };

                dirNode.AddFileNode(fileNode);
            }

            if (depth > 0)
            {
                for (int i = 0; i < width; ++i)
                {
                    string  dirName    = i == 0 ? dirPrefix : dirPrefix + "_" + i;
                    DirNode subDirNode = dirNode.GetDirNode(dirName);
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(dirName);
                        dirNode.AddDirNode(subDirNode);
                    }

                    DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt);
                }
            }
        }
Beispiel #29
0
        public void FollowSymlink_1_BrokenSymlink()
        {
#if DNXCORE50
            if (!CrossPlatformHelpers.IsLinux)
            {
                return;
            }

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo("rootfolder");

            var dirNode = new DirNode($"{UnicodeFileName}{FolderSuffix}");
            dirNode.AddFileNode(new FileNode($"{UnicodeFileName}{FileSuffix}")
            {
                SizeInByte = 1024
            });

            sourceDataInfo.RootNode.AddDirNode(dirNode);
            sourceDataInfo.RootNode.AddDirNode(DirNode.SymlinkedDir($"{UnicodeFileName}{SymlinkSuffix}", dirNode.Name, dirNode));
            dirNode = new DirNode($"{UnicodeFileName}{FolderSuffix}_1");
            sourceDataInfo.RootNode.AddDirNode(DirNode.SymlinkedDir($"{UnicodeFileName}{SymlinkSuffix}_1", dirNode.Name, dirNode));

            SourceAdaptor.GenerateData(sourceDataInfo);

            sourceDataInfo.RootNode.DeleteDirNode($"{UnicodeFileName}{SymlinkSuffix}_1");

            var options = new TestExecutionOptions <DMLibDataInfo>()
            {
                IsDirectoryTransfer    = true,
                DisableSourceGenerator = true,
                DisableSourceCleaner   = true,
                TransferItemModifier   = (notUsed, item) =>
                {
                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = true;
                    (transferOptions as UploadDirectoryOptions).FollowSymlink = true;
                    item.Options = transferOptions;
                },
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // For sync copy, recalculate md5 of destination by downloading the file to local.
            if (IsCloudService(DMLibTestContext.DestType) && (DMLibTestContext.CopyMethod != DMLibCopyMethod.ServiceSideAsyncCopy))
            {
                DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
            }

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
#endif
        }
        public void FilePattern_CloudBlob_Prefix_3()
        {
            HashSet <FileNode> nodesToKeep    = new HashSet <FileNode>();
            DMLibDataInfo      expectedResult = SourceDataInfo.Clone();

            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "subfolder4", "test5"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "TESTFILE345"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "testYfile"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "f_arbitrary.exe"));
            nodesToKeep.Add(DMLibDataHelper.GetFileNode(expectedResult.RootNode, "folder1", "subfolder2", "测试x文件"));
            DMLibDataHelper.RemoveAllFileNodesExcept(expectedResult.RootNode, nodesToKeep);

            this.TestSearchPattern(true, expectedResult, "folder1/subfolder2");
        }