예제 #1
0
 public CloudFileDataAdaptor(TestAccount testAccount, string shareName, SourceOrDest sourceOrDest)
 {
     this.testAccount      = testAccount;
     this.fileHelper       = new CloudFileHelper(testAccount.Account);
     this.shareName        = shareName;
     this.defaultShareName = shareName;
     this.tempFolder       = Guid.NewGuid().ToString();
     this.SourceOrDest     = sourceOrDest;
 }
 private static void CleanupData(SourceOrDest sourceOrDest, DMLibDataType dataType)
 {
     if (SourceOrDest.Source == sourceOrDest)
     {
         GetSourceAdaptor(dataType).Cleanup();
     }
     else
     {
         GetDestAdaptor(dataType).Cleanup();
     }
 }
        private static DMLibDataInfo GetDataInfo(SourceOrDest sourceOrDest, DMLibDataType dataType)
        {
            var dataInfos = GetDataInfos(sourceOrDest);

            if (!dataInfos.ContainsKey(dataType.ToString()))
            {
                throw new ArgumentException(
                          string.Format("{0} transfer data info of specified dataType doesn't exist: {1}", sourceOrDest == SourceOrDest.Source ? "Source" : "Destination", dataType.ToString()), "dataType");
            }

            return(dataInfos[dataType.ToString()]);
        }
        private static DMLibDataInfo GetDataInfo(SourceOrDest sourceOrDest, DMLibDataType dataType)
        {
            var dataInfos = GetDataInfos(sourceOrDest);

            if (!dataInfos.ContainsKey(dataType.ToString()))
            {
                throw new ArgumentException(
                    string.Format("{0} transfer data info of specified dataType doesn't exist: {1}", sourceOrDest == SourceOrDest.Source ? "Source" : "Destination", dataType.ToString()), "dataType");
            }

            return dataInfos[dataType.ToString()];
        }
        private static void PrepareData(SourceOrDest sourceOrDest, DMLibDataType dataType, DMLibDataInfo dataInfo)
        {
            var dataInfos = GetDataInfos(sourceOrDest);
            CleanupData(sourceOrDest, dataType);

            if (SourceOrDest.Source == sourceOrDest)
            {
                GetSourceAdaptor(dataType).GenerateData(dataInfo);
                SetSourceDataInfo(dataType, dataInfo);
            }
            else
            {
                GetDestAdaptor(dataType).GenerateData(dataInfo);
                SetDestDataInfo(dataType, dataInfo);
            }
        }
        private static void PrepareData(SourceOrDest sourceOrDest, DMLibDataType dataType, DMLibDataInfo dataInfo)
        {
            var dataInfos = GetDataInfos(sourceOrDest);

            CleanupData(sourceOrDest, dataType);

            if (SourceOrDest.Source == sourceOrDest)
            {
                GetSourceAdaptor(dataType).GenerateData(dataInfo);
                SetSourceDataInfo(dataType, dataInfo);
            }
            else
            {
                GetDestAdaptor(dataType).GenerateData(dataInfo);
                SetDestDataInfo(dataType, dataInfo);
            }
        }
        private static string GetConnectionString(SourceOrDest sourceOrDest, DMLibDataType dataType)
        {
            IDictionary <string, string> connectionStrings = SourceOrDest.Source == sourceOrDest ? sourceConnectionStrings : destConnectionStrings;
            string key = DMLibTestBase.GetLocationKey(dataType);

            string connectionString;

            if (connectionStrings.TryGetValue(key, out connectionString))
            {
                return(connectionString);
            }

            if (SourceOrDest.Dest == sourceOrDest)
            {
                return(TestAccounts.Secondary.ConnectionString);
            }
            else
            {
                return(TestAccounts.Primary.ConnectionString);
            }
        }
 public static Dictionary <string, DMLibDataInfo> GetDataInfos(SourceOrDest sourceOrDest)
 {
     return(SourceOrDest.Source == sourceOrDest ? sourceDataInfos : destDataInfos);
 }
 public CloudBlobDataAdaptor(TestAccount testAccount, string containerName, string blobType, SourceOrDest sourceOrDest, string delimiter = "/")
     : base(testAccount, containerName, blobType, sourceOrDest, delimiter)
 {
 }
 public static Dictionary<string, DMLibDataInfo> GetDataInfos(SourceOrDest sourceOrDest)
 {
     return SourceOrDest.Source == sourceOrDest ? sourceDataInfos : destDataInfos;
 }
 private static void CleanupData(SourceOrDest sourceOrDest, DMLibDataType dataType)
 {
     if (SourceOrDest.Source == sourceOrDest)
     {
         GetSourceAdaptor(dataType).Cleanup();
     }
     else
     {
         GetDestAdaptor(dataType).Cleanup();
     }
 }
 public LocalDataAdaptor(string basePath, SourceOrDest sourceOrDest, bool useStream = false)
     : base(basePath, sourceOrDest)
 {
     this.useStream = useStream;
 }
예제 #13
0
        private void TestAccessCondition(SourceOrDest sourceOrDest)
        {
            string          eTag            = "\"notmatch\"";
            AccessCondition accessCondition = new AccessCondition()
            {
                IfMatchETag = eTag
            };

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

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

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);

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

            var options = new TestExecutionOptions <DMLibDataInfo>();

            if (sourceOrDest == SourceOrDest.Dest)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;

                if (sourceOrDest == SourceOrDest.Source)
                {
                    transferOptions.SourceAccessCondition = accessCondition;
                }
                else
                {
                    transferOptions.DestinationAccessCondition = accessCondition;
                }

                transferItem.Options = transferOptions;
            };

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

            if (sourceOrDest == SourceOrDest.Dest)
            {
                Test.Assert(DMLibDataHelper.Equals(destDataInfo, result.DataInfo), "Verify no file is transferred.");
            }
            else
            {
                if (DMLibTestContext.DestType != DMLibDataType.Stream)
                {
                    Test.Assert(DMLibDataHelper.Equals(new DMLibDataInfo(string.Empty), result.DataInfo), "Verify no file is transferred.");
                }
                else
                {
                    foreach (var fileNode in result.DataInfo.EnumerateFileNodes())
                    {
                        Test.Assert(fileNode.SizeInByte == 0, "Verify file {0} is empty", fileNode.Name);
                    }
                }
            }

            // Verify TransferException
            if (result.Exceptions.Count != 1)
            {
                Test.Error("There should be exactly one exceptions.");
                return;
            }

            Exception exception = result.Exceptions[0];

#if DOTNET5_4
            VerificationHelper.VerifyTransferException(exception, TransferErrorCode.Unknown);

            // Verify innner StorageException
            VerificationHelper.VerifyStorageException(exception.InnerException, (int)HttpStatusCode.PreconditionFailed,
                                                      "The condition specified using HTTP conditional header(s) is not met.");
#else
            VerificationHelper.VerifyTransferException(exception, TransferErrorCode.Unknown);

            // Verify innner StorageException
            VerificationHelper.VerifyStorageException(exception.InnerException, (int)HttpStatusCode.PreconditionFailed,
                                                      "The condition specified using HTTP conditional header(s) is not met.");
#endif
        }
        private void TestAccessCondition(SourceOrDest sourceOrDest)
        {
            string eTag = "notmatch";
            AccessCondition accessCondition = new AccessCondition()
            {
                IfMatchETag = eTag
            };

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();

            if (sourceOrDest == SourceOrDest.Dest)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;

                if (sourceOrDest == SourceOrDest.Source)
                {
                    transferOptions.SourceAccessCondition = accessCondition;
                }
                else
                {
                    transferOptions.DestinationAccessCondition = accessCondition;
                }

                transferItem.Options = transferOptions;
            };

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

            if (sourceOrDest == SourceOrDest.Dest)
            {
                Test.Assert(DMLibDataHelper.Equals(destDataInfo, result.DataInfo), "Verify no file is transferred.");
            }
            else
            {
                if (DMLibTestContext.DestType != DMLibDataType.Stream)
                {
                    Test.Assert(DMLibDataHelper.Equals(new DMLibDataInfo(string.Empty), result.DataInfo), "Verify no file is transferred.");
                }
                else
                {
                    foreach(var fileNode in result.DataInfo.EnumerateFileNodes())
                    {
                        Test.Assert(fileNode.SizeInByte == 0, "Verify file {0} is empty", fileNode.Name);
                    }
                }
            }
            
            // Verify TransferException
            if (result.Exceptions.Count != 1)
            {
                Test.Error("There should be exactly one exceptions.");
                return;
            }

            Exception exception = result.Exceptions[0];
            VerificationHelper.VerifyTransferException(exception, TransferErrorCode.Unknown);

            // Verify innner StorageException
            VerificationHelper.VerifyStorageException(exception.InnerException, (int)HttpStatusCode.PreconditionFailed,
                "The condition specified using HTTP conditional header(s) is not met.");
        }
        public BlobDataAdaptorBase(TestAccount testAccount, string containerName, string blobType, SourceOrDest sourceOrDest, string delimiter = "/")
        {
            if (BlobTypeConst.Block != blobType && BlobTypeConst.Page != blobType && BlobTypeConst.Append != blobType)
            {
                throw new ArgumentException("blobType");
            }

            this.TestAccount          = testAccount;
            this.BlobHelper           = new CloudBlobHelper(testAccount.Account);
            this.delimiter            = delimiter;
            this.containerName        = containerName;
            this.defaultContainerName = containerName;
            this.TempFolder           = Guid.NewGuid().ToString();
            this.BlobType             = blobType;
            this.SourceOrDest         = sourceOrDest;
        }
 public LocalDataAdaptorBase(string basePath, SourceOrDest sourceOrDest)
 {
     // The folder pointed by basePath will be deleted when cleanup.
     this.BasePath     = basePath;
     this.SourceOrDest = sourceOrDest;
 }