public async Task CreateDeleteFileShare()
        {
            //create file share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share1        = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value;

            Assert.AreEqual(share1.Id.Name, fileShareName);

            //validate if created successfully
            FileShareData shareData = share1.Data;

            Assert.IsEmpty(shareData.Metadata);
            FileShare share2 = await _fileShareCollection.GetAsync(fileShareName);

            AssertFileShareEqual(share1, share2);
            Assert.IsTrue(await _fileShareCollection.ExistsAsync(fileShareName));
            Assert.IsFalse(await _fileShareCollection.ExistsAsync(fileShareName + "1"));

            //delete file share
            await share1.DeleteAsync(true);

            //validate if deleted successfully
            FileShare fileShare3 = await _fileShareCollection.GetIfExistsAsync(fileShareName);

            Assert.IsNull(fileShare3);
            Assert.IsFalse(await _fileShareCollection.ExistsAsync(fileShareName));
        }
예제 #2
0
        public async Task Delete()
        {
            #region Snippet:Managing_FileShares_DeleteFileShare
            FileShareCollection fileShareCollection = fileService.GetFileShares();
            FileShare           fileShare           = await fileShareCollection.GetAsync("myFileShare");

            await fileShare.DeleteAsync(WaitUntil.Completed);

            #endregion
        }
        public async Task Delete()
        {
            #region Snippet:Managing_FileShares_DeleteFileShare
            FileShareContainer fileShareContainer = fileService.GetFileShares();
            FileShare          fileShare          = await fileShareContainer.GetAsync("myFileShare");

            await fileShare.DeleteAsync();

            #endregion
        }
        public async Task CreateDeleteListFileShareSnapshot()
        {
            //update storage account to v2
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                Kind = Kind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            // Enable share soft delete in service properties
            _fileService = await _fileService.GetAsync();

            FileServiceData properties = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(true, properties)).Value;

            //create 2 file share and delete 1
            string    fileShareName1 = Recording.GenerateAssetName("testfileshare1");
            string    fileShareName2 = Recording.GenerateAssetName("testfileshare2");
            FileShare share1         = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData())).Value;
            FileShare share2         = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName2, new FileShareData())).Value;
            await share2.DeleteAsync(true);

            //create 2 share snapshots
            FileShare shareSnapshot1 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value;
            FileShare shareSnapshot2 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value;

            //get single share snapshot
            FileShare shareSnapshot = await _fileShareCollection.GetAsync(fileShareName1, "stats", shareSnapshot1.Data.SnapshotTime.Value.UtcDateTime.ToString("o"));

            Assert.AreEqual(shareSnapshot.Data.SnapshotTime, shareSnapshot1.Data.SnapshotTime);

            //list share with snapshot
            List <FileShare> fileShares = await _fileShareCollection.GetAllAsync(expand : "snapshots").ToEnumerableAsync();

            Assert.AreEqual(3, fileShares.Count);

            //delete share snapshot
            await shareSnapshot.DeleteAsync(true);

            // List share with deleted
            fileShares = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync();

            Assert.AreEqual(2, fileShares.Count);
        }
        public async Task RestoreFileShare()
        {
            //enable soft delete in service property
            FileServiceData parameter = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(true, parameter)).Value;

            //create file share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share1        = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value;

            Assert.AreEqual(share1.Id.Name, fileShareName);

            //delete this share
            await share1.DeleteAsync(true);

            //get the deleted share version
            string           deletedShareVersion = null;
            List <FileShare> fileShares          = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync();

            deletedShareVersion = fileShares[0].Data.Version;

            //restore file share
            //Don't need sleep when playback, or test will be very slow. Need sleep when live and record.
            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(30000);
            }
            DeletedShare deletedShare = new DeletedShare(fileShareName, deletedShareVersion);
            await share1.RestoreAsync(deletedShare);

            //validate
            fileShares = await _fileShareCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(fileShares.Count, 1);
        }
        public async Task FileShareLease()
        {
            //update storage account to v2
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                Kind = Kind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            //create base share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share         = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value;

            //create share snapshots
            FileShare shareSnapshot = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData(), "snapshots")).Value;

            // Acquire lease share
            string             proposedLeaseID1 = "ca761232-ed42-11ce-bacd-00aa0057b223";
            string             proposedLeaseID2 = "dd761232-ed42-11ce-bacd-00aa0057b444";
            LeaseShareResponse leaseResponse;

            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Acquire)
            {
                LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            share = await share.GetAsync();

            Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration);
            Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState);
            Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus);

            //renew lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Renew)
            {
                LeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            // change lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Change)
            {
                LeaseId = proposedLeaseID1, ProposedLeaseId = proposedLeaseID2
            });

            Assert.AreEqual(proposedLeaseID2, leaseResponse.LeaseId);

            //break lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Break)
            {
                BreakPeriod = 20
            });

            Assert.AreEqual("20", leaseResponse.LeaseTimeSeconds);

            //release lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Release)
            {
                LeaseId = proposedLeaseID2
            });

            Assert.IsNull(leaseResponse.LeaseId);

            //lease share snapshot
            leaseResponse = await share.LeaseAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o"),
                                                   parameters : new LeaseShareRequest(LeaseShareAction.Acquire)
            {
                LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            shareSnapshot = await shareSnapshot.GetAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o"));

            Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration);
            Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState);
            Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus);

            bool DeleteFail = false;

            // try delete with include = none
            try
            {
                await share.DeleteAsync(true, include : "none");
            }
            catch (RequestFailedException e) when(e.Status == 409)
            {
                DeleteFail = true;
            }
            Assert.IsTrue(DeleteFail, "Delete should fail with include = none");

            DeleteFail = false;
            // try delete with include = snapshots
            try
            {
                await share.DeleteAsync(true, include : "snapshots");
            }
            catch (RequestFailedException e) when(e.Status == 409)
            {
                DeleteFail = true;
            }
            Assert.IsTrue(DeleteFail, "Delete should fail with include = snapshots");

            //delete with include = leased-snapshots
            await share.DeleteAsync(true, include : "leased-snapshots");
        }