public async Task CreateDeleteFileShare() { //create file share string fileShareName = Recording.GenerateAssetName("testfileshare"); FileShareResource share1 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData())).Value; Assert.AreEqual(share1.Id.Name, fileShareName); //validate if created successfully FileShareData shareData = share1.Data; Assert.IsEmpty(shareData.Metadata); FileShareResource 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(WaitUntil.Completed); //validate if deleted successfully var exception = Assert.ThrowsAsync <RequestFailedException>(async() => { await _fileShareCollection.GetAsync(fileShareName); }); Assert.AreEqual(404, exception.Status); Assert.IsFalse(await _fileShareCollection.ExistsAsync(fileShareName)); }
public async Task Delete() { #region Snippet:Managing_FileShares_DeleteFileShare FileShareCollection fileShareCollection = fileService.GetFileShares(); FileShareResource fileShare = await fileShareCollection.GetAsync("myFileShare"); await fileShare.DeleteAsync(WaitUntil.Completed); #endregion }
public async Task CreateDeleteListFileShareSnapshot() { //update storage account to v2 PatchableStorageAccountData updateParameters = new PatchableStorageAccountData() { Kind = StorageKind.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(WaitUntil.Completed, properties)).Value; //create 2 file share and delete 1 string fileShareName1 = Recording.GenerateAssetName("testfileshare1"); string fileShareName2 = Recording.GenerateAssetName("testfileshare2"); FileShareResource share1 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData())).Value; FileShareResource share2 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName2, new FileShareData())).Value; await share2.DeleteAsync(WaitUntil.Completed); //create 2 share snapshots FileShareResource shareSnapshot1 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData(), expand: "snapshots")).Value; FileShareResource shareSnapshot2 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData(), expand: "snapshots")).Value; //get single share snapshot FileShareResource shareSnapshot = await _fileShareCollection.GetAsync(fileShareName1, "stats", shareSnapshot1.Data.SnapshotOn.Value.UtcDateTime.ToString("o")); Assert.AreEqual(shareSnapshot.Data.SnapshotOn, shareSnapshot1.Data.SnapshotOn); //list share with snapshot List <FileShareResource> fileShares = await _fileShareCollection.GetAllAsync(expand : "snapshots").ToEnumerableAsync(); Assert.AreEqual(3, fileShares.Count); //delete share snapshot await shareSnapshot.DeleteAsync(WaitUntil.Completed); // 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(WaitUntil.Completed, parameter)).Value; //create file share string fileShareName = Recording.GenerateAssetName("testfileshare"); FileShareResource share1 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData())).Value; Assert.AreEqual(share1.Id.Name, fileShareName); //delete this share await share1.DeleteAsync(WaitUntil.Completed); //get the deleted share version string deletedShareVersion = null; List <FileShareResource> 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 PatchableStorageAccountData updateParameters = new PatchableStorageAccountData() { Kind = StorageKind.StorageV2 }; await _storageAccount.UpdateAsync(updateParameters); //create base share string fileShareName = Recording.GenerateAssetName("testfileshare"); FileShareResource share = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData())).Value; //create share snapshots FileShareResource shareSnapshot = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, 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.SnapshotOn.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.SnapshotOn.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(WaitUntil.Completed, 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(WaitUntil.Completed, 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(WaitUntil.Completed, include : "leased-snapshots"); }