Beispiel #1
0
        public async Task CloudBlobDirectoryGetParentAsync()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                client.DefaultDelimiter = delimiter;
                string             name      = GetRandomContainerName();
                CloudBlobContainer container = client.GetContainerReference(name);
                try
                {
                    await container.CreateAsync();

                    CloudPageBlob blob = container.GetPageBlobReference("Dir1" + delimiter + "Blob1");
                    await blob.CreateAsync(0);

                    Assert.IsTrue(await blob.ExistsAsync());
                    Assert.AreEqual("Dir1" + delimiter + "Blob1", blob.Name);

                    // get the blob's parent
                    CloudBlobDirectory parent = blob.Parent;
                    Assert.AreEqual(parent.Prefix, "Dir1" + delimiter);

                    // get container as parent
                    CloudBlobDirectory root = parent.Parent;
                    Assert.AreEqual(root.Prefix, "");

                    // make sure the parent of the container dir is null
                    CloudBlobDirectory empty = root.Parent;
                    Assert.IsNull(empty);

                    // from container, get directory reference to container
                    root = container.GetDirectoryReference("");
                    Assert.AreEqual("", root.Prefix);
                    Assert.AreEqual(container.Uri.AbsoluteUri, root.Uri.AbsoluteUri);

                    BlobResultSegment segment = await root.ListBlobsSegmentedAsync(null);

                    List <IListBlobItem> list = new List <IListBlobItem>();
                    list.AddRange(segment.Results);
                    while (segment.ContinuationToken != null)
                    {
                        segment = await container.ListBlobsSegmentedAsync(segment.ContinuationToken);

                        list.AddRange(segment.Results);
                    }

                    Assert.AreEqual(1, list.Count);

                    // make sure the parent of the container dir is null
                    empty = root.Parent;
                    Assert.IsNull(empty);

                    await blob.DeleteIfExistsAsync();
                }
                finally
                {
                    container.DeleteIfExistsAsync().AsTask().Wait();
                }
            }
        }
Beispiel #2
0
        public async Task CloudPageBlobDeleteIfExistsAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                CloudPageBlob blob = container.GetPageBlobReference("blob1");
                Assert.IsFalse(await blob.DeleteIfExistsAsync());
                await blob.CreateAsync(0);

                Assert.IsTrue(await blob.DeleteIfExistsAsync());
                Assert.IsFalse(await blob.DeleteIfExistsAsync());
            }
            finally
            {
                container.DeleteIfExistsAsync().AsTask().Wait();
            }
        }