public void GetCopyStateWithSAS()
        {
            string         destShareName = Utility.GenNameString("destshare");
            CloudFileShare destShare     = fileUtil.EnsureFileShareExists(destShareName);

            try
            {
                string fileName = Utility.GenNameString("DestFile");
                StorageFile.CloudFile destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), fileName);

                object destContext;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true));
                }

                string bigBlobUri = Test.Data.Get("BigBlobUri");

                Test.Assert(CommandAgent.StartFileCopy(bigBlobUri, destShareName, fileName, destContext), "Copy to file should succeed.");

                string sasToken = destShare.GetSharedAccessSignature(new SharedAccessFilePolicy()
                {
                    Permissions            = SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);

                Test.Assert(CommandAgent.GetFileCopyState(destShareName, fileName, destContext), "Get copy state with sas token should succeed.");

                string copyId = null;
                if (lang == Language.NodeJS)
                {
                    copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString();
                }

                NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true);
                Test.Assert(CommandAgent.StopFileCopy(destFile, copyId), "Stop file copy should succeed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(destShareName);
            }
        }
        public void StartCopyFromInvalidContext()
        {
            string         destShareName = Utility.GenNameString("destshare");
            CloudFileShare destShare     = fileUtil.EnsureFileShareExists(destShareName);

            string         sourceShareName = Utility.GenNameString("sourceshare");
            CloudFileShare sourceShare     = fileUtil.EnsureFileShareExists(sourceShareName);

            try
            {
                StorageFile.CloudFile sourceFile = fileUtil.CreateFile(sourceShare.GetRootDirectoryReference(), Utility.GenNameString("SourceFile"));

                object destContext;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true));
                }

                string sasToken = sourceShare.GetSharedAccessSignature(new SharedAccessFilePolicy()
                {
                    Permissions            = SharedAccessFilePermissions.Write,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);

                string destFileName = Utility.GenNameString("destfile");
                Test.Assert(!CommandAgent.StartFileCopyFromFile(sourceShareName, sourceFile.Name, destShareName, destFileName, destContext), "Copy to file with invalid sas token credential should fail.");

                ExpectedContainErrorMessage("This request is not authorized to perform this operation using this permission.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(sourceShareName);
                fileUtil.DeleteFileShareIfExists(destShareName);
            }
        }
        private void CopyFromBlob2File(Action <CloudBlobContainer> SetSourceContext)
        {
            string         destShareName = Utility.GenNameString("destshare");
            CloudFileShare destShare     = fileUtil.EnsureFileShareExists(destShareName);

            string             sourceContainerName = Utility.GenNameString("container");
            CloudBlobContainer container           = blobUtil.CreateContainer(sourceContainerName);

            try
            {
                CloudBlob sourceBlob = blobUtil.CreateRandomBlob(container, Utility.GenNameString("BlobName"));

                object destContext;
                if (lang == Language.PowerShell)
                {
                    destContext = PowerShellAgent.GetStorageContext(StorageAccount.ToString(true));
                }
                else
                {
                    destContext = NodeJSAgent.GetStorageContext(StorageAccount.ToString(true));
                }

                SetSourceContext(container);

                string destFileName = Utility.GenNameString("destfile");
                Test.Assert(CommandAgent.StartFileCopyFromBlob(sourceContainerName, sourceBlob.Name, destShareName, destFileName, destContext), "Copy to file with sas token credential should succeed.");

                var destFile = fileUtil.GetFileReference(destShare.GetRootDirectoryReference(), destFileName);

                Test.Assert(CommandAgent.GetFileCopyState(destFile, destContext, true), "Get file copy state should succeed.");

                CloudFileUtil.ValidateCopyResult(sourceBlob, destFile);
            }
            finally
            {
                blobUtil.RemoveContainer(sourceContainerName);
                fileUtil.DeleteFileShareIfExists(destShareName);
            }
        }
        public void CopyFromSASFile()
        {
            CopyFromFile2File((sourceShare) =>
            {
                string sasToken = sourceShare.GetSharedAccessSignature(new SharedAccessFilePolicy()
                {
                    Permissions            = SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                });

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, sasToken);
            },
                              (destShare) =>
            {
                if (lang == Language.PowerShell)
                {
                    return(PowerShellAgent.GetStorageContext(StorageAccount.ToString(true)));
                }
                else
                {
                    return(NodeJSAgent.GetStorageContext(StorageAccount.ToString(true)));
                }
            });
        }