public async Task CloudFileDeleteIfExistsAsync() { CloudFileShare share = GetRandomShareReference(); try { await share.CreateAsync(); CloudFile file = share.GetRootDirectoryReference().GetFileReference("file1"); Assert.IsFalse(await file.DeleteIfExistsAsync()); await file.CreateAsync(0); Assert.IsTrue(await file.DeleteIfExistsAsync()); Assert.IsFalse(await file.DeleteIfExistsAsync()); } finally { share.DeleteIfExistsAsync().AsTask().Wait(); } }
public async Task CloudFileDirectoryGetParentAsync() { CloudFileClient client = GenerateCloudFileClient(); string name = GetRandomShareName(); CloudFileShare share = client.GetShareReference(name); try { await share.CreateAsync(); CloudFile file = share.GetRootDirectoryReference().GetFileReference("Dir1/File1"); await file.CreateAsync(0); Assert.AreEqual("Dir1/File1", file.Name); // get the file's parent CloudFileDirectory parent = file.Parent; Assert.AreEqual(parent.Name, "Dir1/"); // get share as parent CloudFileDirectory root = parent.Parent; Assert.AreEqual(root.Name, ""); // make sure the parent of the share dir is null CloudFileDirectory empty = root.Parent; Assert.IsNull(empty); // from share, get directory reference to share root = share.GetRootDirectoryReference().GetDirectoryReference(""); Assert.AreEqual("", root.Name); Assert.AreEqual(share.Uri.AbsoluteUri, root.Uri.AbsoluteUri); List <IListFileItem> list = (await ListFilesAndDirectoriesAsync(root, null, null, null)).ToList(); Assert.AreEqual(1, list.Count); // make sure the parent of the share dir is null empty = root.Parent; Assert.IsNull(empty); await file.DeleteIfExistsAsync(); } finally { share.DeleteIfExistsAsync().AsTask().Wait(); } }