public void TestFileShareSnapshotsCopyToBase() { int fileCount = 3; string snapshotFile = "snapshotFile"; DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); sourceDataInfo.IsFileShareSnapshot = true; DMLibDataHelper.AddMultipleFiles(sourceDataInfo.RootNode, snapshotFile, fileCount, 1024); SourceAdaptor.Cleanup(); SourceAdaptor.CreateIfNotExists(); SourceAdaptor.GenerateData(sourceDataInfo); CloudFileDataAdaptor fileAdaptor = (SourceAdaptor as CloudFileDataAdaptor); CloudFileDirectory SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, sourceDataInfo.RootNode) as CloudFileDirectory; CloudFileDirectory DestObject = fileAdaptor.fileHelper.FileClient.GetShareReference(fileAdaptor.ShareName).GetRootDirectoryReference(); // transfer File and finished succssfully Task <TransferStatus> task = TransferManager.CopyDirectoryAsync( SourceObject, DestObject, DMLibTestContext.IsAsync, new CopyDirectoryOptions() { Recursive = true }, new DirectoryTransferContext() { ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite }); Test.Assert(task.Wait(15 * 60 * 100), "Tansfer finished in time."); Test.Assert(task.Result.NumberOfFilesFailed == 0, "No Failed File."); Test.Assert(task.Result.NumberOfFilesSkipped == 0, "No Skipped File."); Test.Assert(task.Result.NumberOfFilesTransferred == fileCount, string.Format("Transferred file :{0} == {1}", task.Result.NumberOfFilesTransferred, fileCount)); // verify that Files in Share Snapshot is transferred IEnumerable <IListFileItem> sourceFiles = SourceObject.ListFilesAndDirectories(HelperConst.DefaultFileOptions); foreach (IListFileItem item in sourceFiles) { if (item is CloudFile) { CloudFile srcFile = item as CloudFile; CloudFile destFile = DestObject.GetFileReference(srcFile.Name); srcFile.FetchAttributes(); destFile.FetchAttributes(); Test.Assert(srcFile.Properties.ContentMD5 == destFile.Properties.ContentMD5, string.Format("File {0} MD5 :{1} == {2}", srcFile.Name, srcFile.Properties.ContentMD5, destFile.Properties.ContentMD5)); } } }
private void TestSASTokenOfEachVersion(string targetSASVersion, bool isDirectoryTransfer) { Test.Info("Testing version of {0}", targetSASVersion); DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024); var options = new TestExecutionOptions <DMLibDataInfo>(); options.IsDirectoryTransfer = isDirectoryTransfer; options.TransferItemModifier = (fileNode, transferItem) => { dynamic transferOptions = isDirectoryTransfer ? DefaultTransferDirectoryOptions : DefaultTransferOptions; transferItem.Options = transferOptions; if (isDirectoryTransfer) { transferItem.TransferContext = new DirectoryTransferContext(); transferItem.TransferContext.FileFailed += (source, e) => { Test.Error(e.Exception.ToString()); }; DirectoryOptions dirOptions = transferItem.Options as DirectoryOptions; dirOptions.Recursive = true; } else { transferItem.TransferContext = new SingleTransferContext(); } transferItem.TransferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite; }; string sourceSAS = null; string destSAS = null; switch (DMLibTestContext.SourceType) { case DMLibDataType.CloudBlob: case DMLibDataType.AppendBlob: case DMLibDataType.BlockBlob: case DMLibDataType.PageBlob: if ((DMLibTestContext.SourceType == DMLibDataType.AppendBlob) && (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0)) { break; } SourceAdaptor.CreateIfNotExists(); CloudBlobDataAdaptor blobAdaptor = SourceAdaptor as CloudBlobDataAdaptor; sourceSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(), new SharedAccessBlobPolicy { Permissions = isDirectoryTransfer ? SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List : SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }, null, null, null, targetSASVersion); break; case DMLibDataType.CloudFile: if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0) { break; } SourceAdaptor.CreateIfNotExists(); CloudFileDataAdaptor fileAdaptor = SourceAdaptor as CloudFileDataAdaptor; sourceSAS = Util.SASGenerator.GetSharedAccessSignature( fileAdaptor.GetBaseShare(), new SharedAccessFilePolicy { Permissions = isDirectoryTransfer ? SharedAccessFilePermissions.List | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }, null, null, null, targetSASVersion); break; default: break; } if (!DMLibTestContext.IsAsync || (string.CompareOrdinal(targetSASVersion, "2014-02-14") >= 0)) { switch (DMLibTestContext.DestType) { case DMLibDataType.CloudBlob: case DMLibDataType.AppendBlob: case DMLibDataType.BlockBlob: case DMLibDataType.PageBlob: if ((DMLibTestContext.DestType == DMLibDataType.AppendBlob) && (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0)) { break; } DestAdaptor.CreateIfNotExists(); CloudBlobDataAdaptor blobAdaptor = DestAdaptor as CloudBlobDataAdaptor; destSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(), new SharedAccessBlobPolicy { Permissions = DMLibTestContext.IsAsync ? SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read : SharedAccessBlobPermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }, null, null, null, targetSASVersion); break; case DMLibDataType.CloudFile: if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0) { break; } DestAdaptor.CreateIfNotExists(); CloudFileDataAdaptor fileAdaptor = DestAdaptor as CloudFileDataAdaptor; destSAS = Util.SASGenerator.GetSharedAccessSignature( fileAdaptor.GetBaseShare(), new SharedAccessFilePolicy { Permissions = DMLibTestContext.IsAsync ? SharedAccessFilePermissions.Write | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Write, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1) }, null, null, null, targetSASVersion); break; default: break; } } if (null != sourceSAS) { options.SourceCredentials = new StorageCredentials(sourceSAS); } if (null != destSAS) { options.DestCredentials = new StorageCredentials(destSAS); } var result = this.ExecuteTestCase(sourceDataInfo, options); VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); }