public void GetShareSnapshot_CheckIncludeSnapshot()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string fileName  = CloudFileUtil.GenerateUniqueFileName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();
                fileUtil.CreateFile(share, fileName);
                CloudFileShare shareSnapshot2 = share.Snapshot();

                CommandAgent.GetFileShareByName("");
                var result = CommandAgent.Invoke();

                List <DateTimeOffset> snapshotTimes = new List <DateTimeOffset>();
                snapshotTimes.Add(shareSnapshot1.SnapshotTime.Value);
                snapshotTimes.Add(shareSnapshot2.SnapshotTime.Value);

                result.AssertCloudFileContainersExist(shareName, snapshotTimes);
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
        public void GetShareSnapshot_notExistTime()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();

                CommandAgent.GetFileShareByName(shareName, DateTime.Now.AddDays(-1));
                var result = CommandAgent.Invoke();


                CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ResourceNotFoundFullQualifiedErrorId));
                result.AssertNoResult();
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
        public void GetShareSnapshot_ExistTime()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();


                CommandAgent.GetFileShareByName(shareName, shareSnapshot1.SnapshotTime.Value);
                var result = CommandAgent.Invoke();
                result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, shareName, snapshotTime: shareSnapshot1.SnapshotTime.Value), 1);
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
Example #4
0
        public void DownloadFileFromShareSnapshot_dir()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();
            string fileName  = CloudFileUtil.GenerateUniqueFileName();

            try
            {
                CloudFileShare     share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare     shareSnapshot1 = share.Snapshot();
                CloudFileDirectory dir            = fileUtil.EnsureDirectoryExists(share, dirName);
                CloudFile          file           = fileUtil.CreateFile(dir, fileName);
                CloudFileShare     shareSnapshot2 = share.Snapshot();
                file.Delete();
                dir.Delete();

                //Get File content
                string StorageConnectionString = Test.Data.Get("StorageConnectionString");
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(string.Format(",(New-AzureStorageContext -ConnectionString \"{5}\" | Get-AzureStorageShare -Name {0} -SnapshotTime \"{1}\").GetRootDirectoryReference().GetDirectoryReference(\"{4}\") | Get-AzureStorageFileContent -Path {2} -Destination {3} -Force",
                                                                                           shareName,
                                                                                           shareSnapshot2.SnapshotTime.Value,
                                                                                           fileName,
                                                                                           fileName,
                                                                                           dirName,
                                                                                           StorageConnectionString)),
                            string.Format("Download File {0} from share snapshot {1}, {2} should success.", dirName + "\\" + fileName, shareName, shareSnapshot2.SnapshotTime.Value));

                //validate MD5
                CloudFile file2 = shareSnapshot2.GetRootDirectoryReference().GetDirectoryReference(dirName).GetFileReference(fileName);
                file2.FetchAttributes();
                Test.Assert(file2.Properties.ContentMD5 == FileUtil.GetFileContentMD5(fileName), "Expected MD5: {0}, real MD5: {1}", file2.Properties.ContentMD5, FileUtil.GetFileContentMD5(fileName));
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
        public void RemoveFileShareWithSnapshotTest_NotSetIncludeAllSnapshot()
        {
            string         fileShareName  = CloudFileUtil.GenerateUniqueFileShareName();
            CloudFileShare share          = fileUtil.EnsureFileShareExists(fileShareName);
            CloudFileShare shareSnapshot1 = share.Snapshot();

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName, confirm: true, includeAllSnapshot: false);
                var result = CommandAgent.Invoke();

                CommandAgent.AssertErrors(record => record.AssertError("HostException"));
                Test.Assert(share.Exists(), "The share should not be removed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
        public void RemoveFileShareWithSnapshotTest_NotSetIncludeAllSnapshot_Force()
        {
            string         fileShareName  = CloudFileUtil.GenerateUniqueFileShareName();
            CloudFileShare share          = fileUtil.EnsureFileShareExists(fileShareName);
            CloudFileShare shareSnapshot1 = share.Snapshot();

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName, includeAllSnapshot: false);
                var result = CommandAgent.Invoke();

                CommandAgent.AssertNoError();
                result.AssertNoResult();
                Test.Assert(!share.Exists(), "The share should be removed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }