public void TestDirectoryMeta()
        {
            // Prepare data
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");

            GenerateDirNodeWithMetadata(sourceDataInfo.RootNode, 2);

            DirectoryTransferContext dirTransferContext = new DirectoryTransferContext();

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = true;

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                transferItem.TransferContext = dirTransferContext;

                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options      = transferOptions;
            };

            // Execute test case
            var result = this.ExecuteTestCase(sourceDataInfo, options);

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
        }
Пример #2
0
        public void TestDirectorySetAttributes()
        {
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            if (DMLibTestContext.SourceType != DMLibDataType.Local)
            {
                metadata.Add("foo", "bar");
            }

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            for (int i = 0; i < 3; ++i)
            {
                FileNode fileNode = new FileNode(DMLibTestBase.FileName + i)
                {
                    SizeInByte = DMLibTestBase.FileSizeInKB * 1024L,
                    Metadata   = metadata
                };

                sourceDataInfo.RootNode.AddFileNode(fileNode);
            }

            DirectoryTransferContext context = new DirectoryTransferContext()
            {
                SetAttributesCallbackAsync = async(destObj) =>
                {
                    dynamic destCloudObj = destObj;

                    destCloudObj.Properties.ContentType = SetAttributesTest.TestContentType;

                    destCloudObj.Metadata.Add("aa", "bb");
                }
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (node, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive    = true;
                transferItem.Options         = transferOptions;
                transferItem.TransferContext = context;
            };
            options.IsDirectoryTransfer = true;

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

            foreach (FileNode fileNode in sourceDataInfo.EnumerateFileNodes())
            {
                fileNode.Metadata.Add("aa", "bb");
            }

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
            VerificationHelper.VerifySingleTransferStatus(result, 3, 0, 0, 3 * DMLibTestBase.FileSizeInKB * 1024L);

            foreach (FileNode destFileNode in result.DataInfo.EnumerateFileNodes())
            {
                Test.Assert(TestContentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, TestContentType);
            }
        }
        public void TestSingleBlobWithEncryptionScope()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;
                transferOptions.EncryptionScope = Test.Data.Get(DMLibTestConstants.DestEncryptionScope);

                transferItem.Options = transferOptions;
            };

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

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

            string destEncryptionScope = result.DataInfo.RootNode.FileNodes.First().EncryptionScope;

            Test.Assert(string.Equals(destEncryptionScope, Test.Data.Get(DMLibTestConstants.DestEncryptionScope)),
                        "Encryption scope name in destination should be expected {0} == {1}", destEncryptionScope, Test.Data.Get(DMLibTestConstants.DestEncryptionScope));
        }
        public void TestBlobDirectoryWithEncryptionScope()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddMultipleFilesNormalSize(sourceDataInfo.RootNode, DMLibTestBase.FileName);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = true;

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.EncryptionScope = Test.Data.Get(DMLibTestConstants.DestEncryptionScope);
                transferOptions.Recursive       = true;

                transferItem.Options = transferOptions;
            };

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

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

            foreach (var fileNode in result.DataInfo.RootNode.EnumerateFileNodesRecursively())
            {
                string destEncryptionScope = result.DataInfo.RootNode.FileNodes.First().EncryptionScope;
                Test.Assert(string.Equals(destEncryptionScope, Test.Data.Get(DMLibTestConstants.DestEncryptionScope)),
                            "Encryption scope name in destination should be expected {0} == {1}", destEncryptionScope, Test.Data.Get(DMLibTestConstants.DestEncryptionScope));
            }
        }
Пример #5
0
        private void TestSetAttributesToLocal(bool IsDirectoryTransfer)
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            FileNode      fileNode       = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = DMLibTestBase.FileSizeInKB * 1024L,
            };

            sourceDataInfo.RootNode.AddFileNode(fileNode);

            TransferContext context;

            if (IsDirectoryTransfer)
            {
                context = new DirectoryTransferContext()
                {
                    SetAttributesCallbackAsync = async(destObj) =>
                    {
                        Test.Error("SetAttributes callback should not be invoked when destination is local");
                    }
                };
            }
            else
            {
                context = new SingleTransferContext()
                {
                    SetAttributesCallbackAsync = async(destObj) =>
                    {
                        Test.Error("SetAttributes callback should not be invoked when destination is local");
                    }
                };
            }

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (node, transferItem) =>
            {
                dynamic transferOptions = IsDirectoryTransfer ? DefaultTransferDirectoryOptions : DefaultTransferOptions;

                if (IsDirectoryTransfer)
                {
                    transferOptions.Recursive = true;
                }

                transferItem.Options         = transferOptions;
                transferItem.TransferContext = context;
            };

            options.IsDirectoryTransfer = IsDirectoryTransfer;

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

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
        }
Пример #6
0
        public void TestSetAttributes()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            FileNode      fileNode       = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = DMLibTestBase.FileSizeInKB * 1024L
            };

            if (DMLibTestContext.SourceType != DMLibDataType.Local)
            {
                fileNode.Metadata = new Dictionary <string, string>();
                fileNode.Metadata.Add("foo", "bar");
                fileNode.ContentLanguage = SetAttributesTest.TestContentLanguage;
            }

            sourceDataInfo.RootNode.AddFileNode(fileNode);

            TransferContext context = new SingleTransferContext()
            {
                SetAttributesCallbackAsync = async(destObj) =>
                {
                    dynamic destCloudObj = destObj;

                    destCloudObj.Properties.ContentType = SetAttributesTest.TestContentType;

                    destCloudObj.Metadata.Add("aa", "bb");
                }
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (node, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;
                transferItem.Options         = transferOptions;
                transferItem.TransferContext = context;
            };

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

            fileNode.Metadata.Add("aa", "bb");

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

            FileNode destFileNode = result.DataInfo.RootNode.GetFileNode(DMLibTestBase.FileName);

            Test.Assert(TestContentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, TestContentType);

            if (DMLibTestContext.SourceType != DMLibDataType.Local)
            {
                Test.Assert(SetAttributesTest.TestContentLanguage.Equals(destFileNode.ContentLanguage), "Verify ContentLanguage: {0}, expected {1}", destFileNode.ContentLanguage, SetAttributesTest.TestContentLanguage);
            }
        }
Пример #7
0
        private void TestDelimiter(char delimiter)
        {
            Test.Info("Test delimiter: {0}", delimiter);
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            string        fileName       = DMLibTestBase.FolderName + delimiter + DMLibTestBase.FolderName + delimiter + DMLibTestBase.FileName;

            DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, fileName, 1);

            TransferContext context = new DirectoryTransferContext();

            context.FileFailed += (sender, e) =>
            {
                Test.Info(e.Exception.StackTrace);
            };

            TestExecutionOptions <DMLibDataInfo> options = new TestExecutionOptions <DMLibDataInfo>()
            {
                IsDirectoryTransfer  = true,
                TransferItemModifier = (node, item) =>
                {
                    dynamic dirOptions = DefaultTransferDirectoryOptions;
                    dirOptions.Recursive = true;
                    dirOptions.Delimiter = delimiter;
                    item.Options         = dirOptions;
                    item.TransferContext = context;
                }
            };

            TestResult <DMLibDataInfo> result = this.ExecuteTestCase(sourceDataInfo, options);

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);
            DirNode       dirNode1         = new DirNode(FolderName);
            DirNode       dirNode2         = new DirNode(FolderName);
            FileNode      fileNode         = sourceDataInfo.RootNode.GetFileNode(fileName).Clone(DMLibTestBase.FileName);

            dirNode2.AddFileNode(fileNode);
            dirNode1.AddDirNode(dirNode2);
            expectedDataInfo.RootNode.AddDirNode(dirNode1);

            VerificationHelper.VerifySingleTransferStatus(result, 1, 0, 0, null);
            VerificationHelper.VerifyTransferSucceed(result, expectedDataInfo);
        }
        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);
        }
Пример #9
0
        public void DirectoryShouldTransfer()
        {
            // Prepare data
            int           totaFileNumber = DMLibTestConstants.FlatFileCount;
            int           expectedTransferred = totaFileNumber, transferred = 0;
            int           expectedSkipped = 0, skipped = 0;
            int           expectedFailed = 0, failed = 0;
            DMLibDataInfo sourceDataInfo = this.GenerateSourceDataInfo(FileNumOption.FlatFolder, 1024);

            DirectoryTransferContext dirTransferContext = new DirectoryTransferContext();

            List <String> notTransferredFileNames = new List <String>();

            dirTransferContext.ShouldTransferCallbackAsync = async(source, dest) =>
            {
                if (Helper.RandomBoolean())
                {
                    return(true);
                }
                else
                {
                    Interlocked.Decrement(ref expectedTransferred);
                    string fullName = DMLibTestHelper.TransferInstanceToString(source);
                    string fileName = fullName.Substring(fullName.IndexOf(DMLibTestBase.FileName));
                    lock (notTransferredFileNames)
                    {
                        notTransferredFileNames.Add(fileName);
                    }
                    Test.Info("{0} is filterred in ShouldTransfer.", fileName);
                    return(false);
                }
            };

            dirTransferContext.FileTransferred += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref transferred);
            };

            dirTransferContext.FileSkipped += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref skipped);
            };

            dirTransferContext.FileFailed += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref failed);
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = true;

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                transferItem.TransferContext = dirTransferContext;

                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options      = transferOptions;
            };

            // Execute test case
            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // Verify result
            DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone();
            DirNode       expectedRootNode = expectedDataInfo.RootNode;

            foreach (string fileNames in notTransferredFileNames)
            {
                expectedRootNode.DeleteFileNode(fileNames);
            }

            VerificationHelper.VerifyTransferSucceed(result, expectedDataInfo);
            Test.Assert(expectedTransferred == transferred, string.Format("Verify transferred number. Expected: {0}, Actual: {1}", expectedTransferred, transferred));
            Test.Assert(expectedSkipped == skipped, string.Format("Verify skipped number. Expected: {0}, Actual: {1}", expectedSkipped, skipped));
            Test.Assert(expectedFailed == failed, string.Format("Verify failed number. Expected: {0}, Actual: {1}", expectedFailed, failed));
        }
        public void TestDirectoryPreserveSMBProperties()
        {
            if (!CrossPlatformHelpers.IsWindows)
            {
                return;
            }
            CloudFileNtfsAttributes[] SMBFileAttributes =
            {
                CloudFileNtfsAttributes.ReadOnly,
                CloudFileNtfsAttributes.Hidden,
#if DEBUG
                CloudFileNtfsAttributes.System,
                CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Normal,
                CloudFileNtfsAttributes.Offline,
                CloudFileNtfsAttributes.NotContentIndexed,
                CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly | CloudFileNtfsAttributes.Hidden,
                CloudFileNtfsAttributes.System | CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Offline | CloudFileNtfsAttributes.NotContentIndexed | CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly |
                CloudFileNtfsAttributes.Hidden |
                CloudFileNtfsAttributes.System |
                CloudFileNtfsAttributes.Archive |
                CloudFileNtfsAttributes.NotContentIndexed |
                CloudFileNtfsAttributes.NoScrubData
#endif
            };

            for (int i = 0; i < SMBFileAttributes.Length; ++i)
            {
                Test.Info("Testing setting attributes {0} to directories", SMBFileAttributes[i]);
                // Prepare data
                DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
                GenerateDirNodeWithAttributes(sourceDataInfo.RootNode, 2, SMBFileAttributes[i]);

                DirectoryTransferContext dirTransferContext = new DirectoryTransferContext();

                var options = new TestExecutionOptions <DMLibDataInfo>();
                options.IsDirectoryTransfer = true;

                options.TransferItemModifier = (fileNode, transferItem) =>
                {
                    transferItem.TransferContext = dirTransferContext;

                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive             = true;
                    transferOptions.PreserveSMBAttributes = true;
                    transferItem.Options = transferOptions;
                };

#if DEBUG
                TestHookCallbacks.GetFileAttributesCallback = (path) =>
                {
                    if (path.EndsWith("\\") || path.Substring(0, path.Length - 2).EndsWith(DMLibTestBase.DirName))
                    {
                        if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                        {
                            return(FileAttributes.Directory);
                        }
                        else
                        {
                            return(Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory));
                        }
                    }
                    else
                    {
                        return(Helper.ToFileAttributes(SMBFileAttributes[i]));
                    }
                };

                TestHookCallbacks.SetFileAttributesCallback = (path, attributes) =>
                {
                    if (path.EndsWith("\\") || path.Substring(0, path.Length - 2).EndsWith(DMLibTestBase.DirName))
                    {
                        if (path.Substring(0, path.Length - 7).EndsWith("destroot") || path.Substring(0, path.Length - 6).EndsWith("destroot"))
                        {
                            Test.Assert(attributes == FileAttributes.Directory, "Directory attributes should be expected {0}", attributes);
                        }
                        else
                        {
                            if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                            {
                                Test.Assert(attributes == FileAttributes.Directory, "Directory attributes should be expected {0}", attributes);
                            }
                            else
                            {
                                Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory),
                                            "Directory attributes should be expected {0}", attributes);
                            }
                        }
                    }
                    else
                    {
                        Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i]),
                                    "File attributes should be expected {0}", attributes);
                    }
                };
#endif

                try
                {
                    // Execute test case
                    var result = this.ExecuteTestCase(sourceDataInfo, options);

                    options = new TestExecutionOptions <DMLibDataInfo>();
                    options.IsDirectoryTransfer = true;

                    TransferItem item = new TransferItem()
                    {
                        SourceObject        = SourceAdaptor.GetTransferObject(string.Empty, sourceDataInfo.RootNode),
                        DestObject          = DestAdaptor.GetTransferObject(string.Empty, sourceDataInfo.RootNode),
                        SourceType          = DMLibTestContext.SourceType,
                        DestType            = DMLibTestContext.DestType,
                        CopyMethod          = DMLibTestContext.CopyMethod.ToCopyMethod(),
                        IsDirectoryTransfer = true,
                        Options             = DefaultTransferDirectoryOptions
                    };

                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive             = true;
                    transferOptions.PreserveSMBAttributes = true;
                    item.Options = transferOptions;

                    item.TransferContext = new DirectoryTransferContext();
                    item.TransferContext.ShouldOverwriteCallbackAsync = async(s, d) =>
                    {
                        return(false);
                    };

                    List <TransferItem> items = new List <TransferItem>();
                    items.Add(item);

                    result = this.RunTransferItems(items, options);

                    VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                    if (DMLibTestContext.DestType == DMLibDataType.Local)
                    {
                        Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, false);
                    }
                    else
                    {
                        Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, true);
                    }
                }
                finally
                {
#if DEBUG
                    TestHookCallbacks.GetFileAttributesCallback = null;
                    TestHookCallbacks.SetFileAttributesCallback = null;
#endif
                }
            }
        }
        public void TestPreserveSMBProperties()
        {
            if (!CrossPlatformHelpers.IsWindows)
            {
                return;
            }
            CloudFileNtfsAttributes[] SMBFileAttributes =
            {
                CloudFileNtfsAttributes.ReadOnly,
                CloudFileNtfsAttributes.Hidden,
#if DEBUG
                CloudFileNtfsAttributes.System,
                CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Normal,
                CloudFileNtfsAttributes.Temporary,
                CloudFileNtfsAttributes.Offline,
                CloudFileNtfsAttributes.NotContentIndexed,
                CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly | CloudFileNtfsAttributes.Hidden,
                CloudFileNtfsAttributes.System | CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Temporary | CloudFileNtfsAttributes.Offline,
                CloudFileNtfsAttributes.NotContentIndexed | CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly |
                CloudFileNtfsAttributes.Hidden |
                CloudFileNtfsAttributes.System |
                CloudFileNtfsAttributes.Archive |
                CloudFileNtfsAttributes.Temporary |
                CloudFileNtfsAttributes.NotContentIndexed |
                CloudFileNtfsAttributes.NoScrubData
#endif
            };

            try
            {
                for (int i = 0; i < SMBFileAttributes.Length; ++i)
                {
#if DEBUG
                    TestHookCallbacks.GetFileAttributesCallback = (path) =>
                    {
                        if (path.EndsWith("\\") || path.EndsWith(DMLibTestBase.DirName))
                        {
                            if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                            {
                                return(FileAttributes.Directory);
                            }
                            else
                            {
                                return(Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory));
                            }
                        }
                        else
                        {
                            return(Helper.ToFileAttributes(SMBFileAttributes[i]));
                        }
                    };

                    TestHookCallbacks.SetFileAttributesCallback = (path, attributes) =>
                    {
                        if (path.EndsWith("\\") || path.EndsWith(DMLibTestBase.DirName))
                        {
                            if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                            {
                                Test.Assert(attributes == FileAttributes.Directory, "Directory attributes should be expected {0}", attributes);
                            }
                            else
                            {
                                Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory),
                                            "Directory attributes should be expected {0}", attributes);
                            }
                        }
                        else
                        {
                            Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i]),
                                        "File attributes should be expected {0}", attributes);
                        }
                    };
#endif

                    // Prepare data
                    DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
                    FileNode      fileNode       = new FileNode(DMLibTestBase.FileName);
                    fileNode.SizeInByte    = 1024;
                    fileNode.SMBAttributes = SMBFileAttributes[i];
                    sourceDataInfo.RootNode.AddFileNode(fileNode);

                    SingleTransferContext transferContext = new SingleTransferContext();

                    var options = new TestExecutionOptions <DMLibDataInfo>();

                    options.TransferItemModifier = (fileNodeVar, transferItem) =>
                    {
                        transferItem.TransferContext = transferContext;

                        dynamic transferOptions = DefaultTransferOptions;
                        transferOptions.PreserveSMBAttributes = true;
                        transferItem.Options = transferOptions;
                    };

                    // Execute test case
                    var result = this.ExecuteTestCase(sourceDataInfo, options);

                    VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                    if (DMLibTestContext.DestType == DMLibDataType.Local)
                    {
                        Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, false);
                    }
                    else
                    {
                        Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, true);
                    }
                }
            }
            finally
            {
#if DEBUG
                TestHookCallbacks.GetFileAttributesCallback = null;
                TestHookCallbacks.SetFileAttributesCallback = null;
#endif
            }
        }
        public void TestDirectoryPreserveSMBPropertiesResume()
        {
            if (!CrossPlatformHelpers.IsWindows)
            {
                return;
            }
            CloudFileNtfsAttributes[] SMBFileAttributes =
            {
                CloudFileNtfsAttributes.ReadOnly,
                CloudFileNtfsAttributes.Hidden,
#if DEBUG
                CloudFileNtfsAttributes.System,
                CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Normal,
                CloudFileNtfsAttributes.Offline,
                CloudFileNtfsAttributes.NotContentIndexed,
                CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly | CloudFileNtfsAttributes.Hidden,
                CloudFileNtfsAttributes.System | CloudFileNtfsAttributes.Archive,
                CloudFileNtfsAttributes.Offline | CloudFileNtfsAttributes.NotContentIndexed | CloudFileNtfsAttributes.NoScrubData,

                CloudFileNtfsAttributes.ReadOnly |
                CloudFileNtfsAttributes.Hidden |
                CloudFileNtfsAttributes.System |
                CloudFileNtfsAttributes.Archive |
                CloudFileNtfsAttributes.NotContentIndexed |
                CloudFileNtfsAttributes.NoScrubData
#endif
            };

            for (int i = 0; i < SMBFileAttributes.Length; ++i)
            {
                CancellationTokenSource tokenSource  = new CancellationTokenSource();
                TransferItem            transferItem = null;

                bool IsStreamJournal = random.Next(0, 2) == 0;
                using (Stream journalStream = new MemoryStream())
                {
                    Test.Info("Testing setting attributes {0} to directories", SMBFileAttributes[i]);
                    // Prepare data
                    DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
                    GenerateDirNodeWithAttributes(sourceDataInfo.RootNode, 2, SMBFileAttributes[i]);

                    DirectoryTransferContext dirTransferContext = null;

                    if (IsStreamJournal)
                    {
                        dirTransferContext = new DirectoryTransferContext(journalStream);
                    }
                    else
                    {
                        dirTransferContext = new DirectoryTransferContext();
                    }

                    var progressChecker = new ProgressChecker(14, 14 * 1024);
                    dirTransferContext.ProgressHandler = progressChecker.GetProgressHandler();

                    var options = new TestExecutionOptions <DMLibDataInfo>();
                    options.IsDirectoryTransfer = true;

                    options.TransferItemModifier = (fileNode, item) =>
                    {
                        item.TransferContext = dirTransferContext;

                        dynamic transferOptions = DefaultTransferDirectoryOptions;
                        transferOptions.Recursive             = true;
                        transferOptions.PreserveSMBAttributes = true;
                        item.Options           = transferOptions;
                        item.CancellationToken = tokenSource.Token;
                        transferItem           = item;
                    };

                    TransferCheckpoint checkpoint = null;

                    options.AfterAllItemAdded = () =>
                    {
                        // Wait until there are data transferred
                        progressChecker.DataTransferred.WaitOne();

                        if (!IsStreamJournal)
                        {
                            checkpoint = dirTransferContext.LastCheckpoint;
                        }

                        // Cancel the transfer and store the second checkpoint
                        tokenSource.Cancel();
                    };

#if DEBUG
                    TestHookCallbacks.GetFileAttributesCallback = (path) =>
                    {
                        if (path.EndsWith("\\") || path.Substring(0, path.Length - 2).EndsWith(DMLibTestBase.DirName))
                        {
                            if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                            {
                                return(FileAttributes.Directory);
                            }
                            else
                            {
                                return(Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory));
                            }
                        }
                        else
                        {
                            return(Helper.ToFileAttributes(SMBFileAttributes[i]));
                        }
                    };

                    TestHookCallbacks.SetFileAttributesCallback = (path, attributes) =>
                    {
                        if (path.EndsWith("\\") || path.Substring(0, path.Length - 2).EndsWith(DMLibTestBase.DirName))
                        {
                            if (path.Substring(0, path.Length - 7).EndsWith("destroot") || path.Substring(0, path.Length - 6).EndsWith("destroot"))
                            {
                                Test.Assert(attributes == FileAttributes.Directory, "Directory attributes should be expected {0}", attributes);
                            }
                            else
                            {
                                if (SMBFileAttributes[i] == CloudFileNtfsAttributes.Normal)
                                {
                                    Test.Assert(attributes == FileAttributes.Directory, "Directory attributes should be expected {0}", attributes);
                                }
                                else
                                {
                                    Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i] | CloudFileNtfsAttributes.Directory),
                                                "Directory attributes should be expected {0}", attributes);
                                }
                            }
                        }
                        else
                        {
                            Test.Assert(attributes == Helper.ToFileAttributes(SMBFileAttributes[i]),
                                        "File attributes should be expected {0}", attributes);
                        }
                    };
#endif

                    try
                    {
                        // Execute test case
                        var result = this.ExecuteTestCase(sourceDataInfo, options);

                        Test.Assert(result.Exceptions.Count == 1, "Verify job is cancelled");
                        Exception exception = result.Exceptions[0];
                        Helper.VerifyCancelException(exception);

                        TransferItem             resumeItem    = transferItem.Clone();
                        DirectoryTransferContext resumeContext = null;
                        journalStream.Position = 0;
                        if (IsStreamJournal)
                        {
                            resumeContext = new DirectoryTransferContext(journalStream);
                        }
                        else
                        {
                            resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(checkpoint));
                        }

                        resumeItem.TransferContext = resumeContext;

                        result = this.RunTransferItems(new List <TransferItem>()
                        {
                            resumeItem
                        }, new TestExecutionOptions <DMLibDataInfo>());
                        VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                        options = new TestExecutionOptions <DMLibDataInfo>();
                        options.IsDirectoryTransfer = true;

                        TransferItem item = new TransferItem()
                        {
                            SourceObject        = SourceAdaptor.GetTransferObject(string.Empty, sourceDataInfo.RootNode),
                            DestObject          = DestAdaptor.GetTransferObject(string.Empty, sourceDataInfo.RootNode),
                            SourceType          = DMLibTestContext.SourceType,
                            DestType            = DMLibTestContext.DestType,
                            CopyMethod          = DMLibTestContext.CopyMethod.ToCopyMethod(),
                            IsDirectoryTransfer = true,
                            Options             = DefaultTransferDirectoryOptions
                        };

                        dynamic transferOptions = DefaultTransferDirectoryOptions;
                        transferOptions.Recursive             = true;
                        transferOptions.PreserveSMBAttributes = true;
                        item.Options = transferOptions;

                        item.TransferContext = new DirectoryTransferContext();
                        item.TransferContext.ShouldOverwriteCallbackAsync = async(s, d) =>
                        {
                            return(false);
                        };

                        List <TransferItem> items = new List <TransferItem>();
                        items.Add(item);

                        result = this.RunTransferItems(items, options);

                        VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                        if (DMLibTestContext.DestType == DMLibDataType.Local)
                        {
                            Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, false);
                        }
                        else
                        {
                            Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, true);
                        }
                    }
                    finally
                    {
#if DEBUG
                        TestHookCallbacks.GetFileAttributesCallback = null;
                        TestHookCallbacks.SetFileAttributesCallback = null;
#endif
                    }
                }
            }
        }
Пример #13
0
        public void TestDirectoryPreserveSMBPermissionsResume()
        {
            if (!CrossPlatformHelpers.IsWindows)
            {
                return;
            }

            PreserveSMBPermissions preserveSMBPermissions =
                PreserveSMBPermissions.Owner
                | PreserveSMBPermissions.Group
                | PreserveSMBPermissions.DACL;

            string sampleSDDL = "O:S-1-5-21-2146773085-903363285-719344707-1375029G:S-1-5-21-2146773085-903363285-719344707-513D:(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)";
            CancellationTokenSource tokenSource  = new CancellationTokenSource();
            TransferItem            transferItem = null;

            bool IsStreamJournal = random.Next(0, 2) == 0;

            using (Stream journalStream = new MemoryStream())
            {
                // Prepare data
                DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
                GenerateDirNodeWithPermissions(sourceDataInfo.RootNode, 2, sampleSDDL);

                DirectoryTransferContext dirTransferContext = null;

                if (IsStreamJournal)
                {
                    dirTransferContext = new DirectoryTransferContext(journalStream);
                }
                else
                {
                    dirTransferContext = new DirectoryTransferContext();
                }

                var progressChecker = new ProgressChecker(14, 14 * 1024);
                dirTransferContext.ProgressHandler = progressChecker.GetProgressHandler();

                var options = new TestExecutionOptions <DMLibDataInfo>();
                options.IsDirectoryTransfer = true;

                options.TransferItemModifier = (fileNode, item) =>
                {
                    item.TransferContext = dirTransferContext;

                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = true;
                    transferOptions.PreserveSMBPermissions = preserveSMBPermissions;
                    item.Options           = transferOptions;
                    item.CancellationToken = tokenSource.Token;
                    transferItem           = item;
                };

                TransferCheckpoint checkpoint = null;

                options.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    progressChecker.DataTransferred.WaitOne();

                    if (!IsStreamJournal)
                    {
                        checkpoint = dirTransferContext.LastCheckpoint;
                    }

                    // Cancel the transfer and store the second checkpoint
                    tokenSource.Cancel();
                };

#if DEBUG
                TestHookCallbacks.UnderTesting = true;
                TestHookCallbacks.GetFilePermissionsCallback = (path, SMBPermissionType) =>
                {
                    Test.Assert(SMBPermissionType == preserveSMBPermissions, "The SMB permission type should be expected.");
                    return(sampleSDDL);
                };

                TestHookCallbacks.SetFilePermissionsCallback = (path, portableSDDL, SMBPermissionType) =>
                {
                    Test.Assert(SMBPermissionType == preserveSMBPermissions, "The SMB permission type should be expected.");
                    Test.Assert(portableSDDL.StartsWith(sampleSDDL),
                                "The SDDL value should be expected.");
                };
#endif

                try
                {
                    // Execute test case
                    var result = this.ExecuteTestCase(sourceDataInfo, options);

                    Test.Assert(result.Exceptions.Count == 1, "Verify job is cancelled");
                    Exception exception = result.Exceptions[0];
                    Helper.VerifyCancelException(exception);

                    TransferItem             resumeItem    = transferItem.Clone();
                    DirectoryTransferContext resumeContext = null;
                    journalStream.Position = 0;
                    if (IsStreamJournal)
                    {
                        resumeContext = new DirectoryTransferContext(journalStream);
                    }
                    else
                    {
                        resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(checkpoint));
                    }

                    resumeItem.TransferContext = resumeContext;

                    result = this.RunTransferItems(new List <TransferItem>()
                    {
                        resumeItem
                    }, new TestExecutionOptions <DMLibDataInfo>());
                    VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                    if (DMLibTestContext.DestType == DMLibDataType.CloudFile)
                    {
                        Helper.CompareSMBPermissions(sourceDataInfo.RootNode, result.DataInfo.RootNode, preserveSMBPermissions);
                    }
                }
                finally
                {
#if DEBUG
                    TestHookCallbacks.UnderTesting = false;
                    TestHookCallbacks.GetFilePermissionsCallback = null;
                    TestHookCallbacks.SetFilePermissionsCallback = null;
#endif
                }
            }
        }
Пример #14
0
        public void TestPreserveSMBPermissions()
        {
            if (!CrossPlatformHelpers.IsWindows)
            {
                return;
            }

            try
            {
                PreserveSMBPermissions preserveSMBPermissions =
                    PreserveSMBPermissions.Owner
                    | PreserveSMBPermissions.Group
                    | PreserveSMBPermissions.DACL;
                string sampleSDDL = "O:S-1-5-21-2146773085-903363285-719344707-1375029G:S-1-5-21-2146773085-903363285-719344707-513D:(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)";

#if DEBUG
                TestHookCallbacks.UnderTesting = true;
                TestHookCallbacks.GetFilePermissionsCallback = (path, SMBPermissionType) =>
                {
                    Test.Assert(SMBPermissionType == preserveSMBPermissions, "The SMB permission type should be expected.");
                    return(sampleSDDL);
                };

                TestHookCallbacks.SetFilePermissionsCallback = (path, portableSDDL, SMBPermissionType) =>
                {
                    Test.Assert(SMBPermissionType == preserveSMBPermissions, "The SMB permission type should be expected.");
                    Test.Assert(portableSDDL.StartsWith(sampleSDDL),
                                "The SDDL value should be expected.");
                };
#endif

                // Prepare data
                DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
                FileNode      fileNode       = new FileNode(DMLibTestBase.FileName);
                fileNode.SizeInByte   = 1024;
                fileNode.PortableSDDL = sampleSDDL;
                sourceDataInfo.RootNode.AddFileNode(fileNode);

                SingleTransferContext transferContext = new SingleTransferContext();

                var options = new TestExecutionOptions <DMLibDataInfo>();

                options.TransferItemModifier = (fileNodeVar, transferItem) =>
                {
                    transferItem.TransferContext = transferContext;

                    dynamic transferOptions = DefaultTransferOptions;
                    transferOptions.PreserveSMBPermissions = preserveSMBPermissions;
                    transferItem.Options = transferOptions;
                };

                // Execute test case
                var result = this.ExecuteTestCase(sourceDataInfo, options);

                VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                if (DMLibTestContext.DestType == DMLibDataType.CloudFile)
                {
                    Helper.CompareSMBPermissions(sourceDataInfo.RootNode, result.DataInfo.RootNode, preserveSMBPermissions);
                }
            }
            finally
            {
#if DEBUG
                TestHookCallbacks.UnderTesting = false;
                TestHookCallbacks.GetFilePermissionsCallback = null;
                TestHookCallbacks.SetFilePermissionsCallback = null;
#endif
            }
        }
Пример #15
0
        private void TestDirectorySetAttribute_Restart(
            int bigFileSizeInKB,
            int smallFileSizeInKB,
            int bigFileNum,
            int smallFileNum,
            Action <DirNode> bigFileDirAddFileAction,
            Action <DirNode> smallFileDirAddFileAction,
            SetAttributesCallbackAsync setAttributesCallback = null,
            Action <DMLibDataInfo> sourceDataInfoDecorator   = null)
        {
            int  totalFileNum     = bigFileNum + smallFileNum;
            long totalSizeInBytes = ((bigFileSizeInKB * bigFileNum) + (smallFileSizeInKB * smallFileNum)) * 1024;

            DMLibDataInfo sourceDataInfo   = new DMLibDataInfo(string.Empty);
            DirNode       bigFileDirNode   = new DirNode("big");
            DirNode       smallFileDirNode = new DirNode("small");

            sourceDataInfo.RootNode.AddDirNode(bigFileDirNode);
            sourceDataInfo.RootNode.AddDirNode(smallFileDirNode);
            bigFileDirAddFileAction(bigFileDirNode);
            smallFileDirAddFileAction(smallFileDirNode);

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            TransferItem transferItem = null;
            var          options      = new TestExecutionOptions <DMLibDataInfo> {
                LimitSpeed = true, IsDirectoryTransfer = true
            };

            using (Stream journalStream = new MemoryStream())
            {
                bool isStreamJournal = random.Next(0, 2) == 0;

                var transferContext = isStreamJournal ? new DirectoryTransferContext(journalStream) : new DirectoryTransferContext();
                transferContext.SetAttributesCallbackAsync = setAttributesCallback;

                var progressChecker = new ProgressChecker(totalFileNum, totalSizeInBytes, totalFileNum, null, 0, totalSizeInBytes);
                transferContext.ProgressHandler = progressChecker.GetProgressHandler();

                var eventChecker = new TransferEventChecker();
                eventChecker.Apply(transferContext);

                transferContext.FileFailed += (sender, e) =>
                {
                    Helper.VerifyCancelException(e.Exception);
                };

                options.TransferItemModifier = (fileName, item) =>
                {
                    dynamic dirOptions = DefaultTransferDirectoryOptions;
                    dirOptions.Recursive = true;

                    item.Options           = dirOptions;
                    item.CancellationToken = tokenSource.Token;
                    item.TransferContext   = transferContext;
                    transferItem           = item;
                };

                TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null;
                options.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    progressChecker.DataTransferred.WaitOne();

                    if (!isStreamJournal)
                    {
                        // Store the first checkpoint
                        firstCheckpoint = transferContext.LastCheckpoint;
                    }

                    Thread.Sleep(1000);

                    // Cancel the transfer and store the second checkpoint
                    tokenSource.Cancel();
                };

                // Cancel and store checkpoint for resume
                var result = this.ExecuteTestCase(sourceDataInfo, options);

                if (progressChecker.FailedFilesNumber <= 0)
                {
                    Test.Error("Verify file number in progress. Failed: {0}", progressChecker.FailedFilesNumber);
                }

                TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null;

                if (!isStreamJournal)
                {
                    secondCheckpoint = transferContext.LastCheckpoint;

                    Test.Info("Resume with the second checkpoint first.");
                    firstResumeCheckpoint  = secondCheckpoint;
                    secondResumeCheckpoint = firstCheckpoint;
                }

                // resume with firstResumeCheckpoint
                TransferItem resumeItem = transferItem.Clone();

                progressChecker.Reset();
                TransferContext resumeContext = null;

                if (isStreamJournal)
                {
                    resumeContext = new DirectoryTransferContext(journalStream)
                    {
                        ProgressHandler = progressChecker.GetProgressHandler()
                    };
                }
                else
                {
                    resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint))
                    {
                        ProgressHandler = progressChecker.GetProgressHandler()
                    };
                }

                resumeContext.SetAttributesCallbackAsync = setAttributesCallback;

                eventChecker.Reset();
                eventChecker.Apply(resumeContext);

                resumeItem.TransferContext = resumeContext;

                result = this.RunTransferItems(new List <TransferItem>()
                {
                    resumeItem
                }, new TestExecutionOptions <DMLibDataInfo>());

                sourceDataInfoDecorator?.Invoke(sourceDataInfo);

                VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
                VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes);
                VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                if (!isStreamJournal)
                {
                    // resume with secondResumeCheckpoint
                    resumeItem = transferItem.Clone();

                    progressChecker.Reset();
                    resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint))
                    {
                        ProgressHandler = progressChecker.GetProgressHandler(),

                        // Need this overwrite callback since some files is already transferred to destination
                        ShouldOverwriteCallbackAsync = DMLibInputHelper.GetDefaultOverwiteCallbackY(),

                        SetAttributesCallbackAsync = setAttributesCallback
                    };

                    eventChecker.Reset();
                    eventChecker.Apply(resumeContext);

                    resumeItem.TransferContext = resumeContext;

                    result = this.RunTransferItems(new List <TransferItem>()
                    {
                        resumeItem
                    }, new TestExecutionOptions <DMLibDataInfo>());

                    VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
                    VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes);
                    VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
                }
            }
        }
        public void TestSetAttributes()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            FileNode      fileNode       = new FileNode(DMLibTestBase.FileName)
            {
                SizeInByte = DMLibTestBase.FileSizeInKB * 1024L
            };

            if (DMLibTestContext.SourceType != DMLibDataType.Local)
            {
                fileNode.Metadata = new Dictionary <string, string>();
                fileNode.Metadata.Add("foo", "bar");
                fileNode.ContentLanguage = SetAttributesTest.TestContentLanguage;
            }

            sourceDataInfo.RootNode.AddFileNode(fileNode);

            TransferContext context = new SingleTransferContext()
            {
                SetAttributesCallbackAsync = SetAttributesCallbackTest
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (node, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;
                if ((DMLibTestContext.SourceType == DMLibDataType.CloudFile) &&
                    (DMLibTestContext.DestType == DMLibDataType.CloudFile))
                {
                    transferOptions.PreserveSMBPermissions = true;
                    transferOptions.PreserveSMBAttributes  = true;
                }

                transferItem.Options         = transferOptions;
                transferItem.TransferContext = context;
            };

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

            fileNode.Metadata.Add("aa", "bb");
            fileNode.Metadata.Add("filelength", fileNode.SizeInByte.ToString());

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

            FileNode destFileNode = result.DataInfo.RootNode.GetFileNode(DMLibTestBase.FileName);

            Test.Assert(TestContentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, TestContentType);

            if (DMLibTestContext.SourceType != DMLibDataType.Local)
            {
                Test.Assert(SetAttributesTest.TestContentLanguage.Equals(destFileNode.ContentLanguage), "Verify ContentLanguage: {0}, expected {1}", destFileNode.ContentLanguage, SetAttributesTest.TestContentLanguage);
            }

            if (DMLibTestContext.SourceType == DMLibDataType.CloudFile &&
                DMLibTestContext.DestType == DMLibDataType.CloudFile)
            {
                Helper.CompareSMBProperties(sourceDataInfo.RootNode, result.DataInfo.RootNode, true);
                Helper.CompareSMBPermissions(
                    sourceDataInfo.RootNode,
                    result.DataInfo.RootNode,
                    PreserveSMBPermissions.Owner | PreserveSMBPermissions.Group | PreserveSMBPermissions.DACL | PreserveSMBPermissions.SACL);
            }
        }